plotpx 0.1.7

Pixel-focused plotting engine that renders magnitude grids, heatmaps, and spectra to RGBA buffers
Documentation
using Test

push!(LOAD_PATH, normpath(joinpath(@__DIR__, "..")))
using PlotPx

const PNG_SIGNATURE = UInt8[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]

@testset "PlotPx" begin
    PlotPx.load_plotpx()

    data = [Float32(x + y) for y in 0:3, x in 0:5]
    bytes = PlotPx.write_png_bytes(data)
    @test bytes[begin:begin+7] == PNG_SIGNATURE

    mktemp() do path, io
        close(io)
        PlotPx.write_png_file(path, data; saturation=10.0)
        saved = read(path)
        @test saved[begin:begin+7] == PNG_SIGNATURE
        @test length(saved) == length(read(IOBuffer(bytes)))
    end

    colors = UInt8[0, 0, 0, 255, 255, 255, 255, 255]
    bytes2 = PlotPx.write_png_bytes(data; colors=colors, saturation=5.0)
    @test bytes2[begin:begin+7] == PNG_SIGNATURE

    @test_throws ErrorException PlotPx.write_png_bytes(:magnitude, data[1:end-1]; width=6, height=4)

    mapped = reshape(Float32[0.0, 0.5, 0.8, 0.2], 2, 2)
    bytes_mapped = PlotPx.write_png_bytes(:magnitude_mapped, mapped; image_width=6, image_height=4)
    @test bytes_mapped[begin:begin+7] == PNG_SIGNATURE

    heat_points = [(1, 1), (5, 3, 0.75f0)]
    bytes_heat = PlotPx.write_png_bytes(:heatmap, heat_points; width=8, height=6)
    @test bytes_heat[begin:begin+7] == PNG_SIGNATURE

    spectrum_data = Float32[0.1, 0.5, 0.9, 0.3, 0.7]
    bytes_spec = PlotPx.write_png_bytes(:spectrum, spectrum_data;
        width=32,
        height=16,
        style=:gradient,
        show_peaks=true,
        peak_decay=0.1f0,
        bar_width_factor=0.9f0,
        background=(0x05, 0x0a, 0x0f, 0xff),
    )
    @test bytes_spec[begin:begin+7] == PNG_SIGNATURE

    mktemp() do path, io
        close(io)
        PlotPx.write_png_file(path, :heatmap, heat_points; width=8, height=6)
        saved = read(path)
        @test saved[begin:begin+7] == PNG_SIGNATURE
    end
end