The GroupTherapy Stack

WasmMakie.jl is host-agnostic. It compiles cleanly on top of WasmTarget.jl and integrates directly with Therapy.jl, Snapshot.jl, or any custom web page.

With WasmTarget.jl

WasmTarget.jl Docs ↗

WasmMakie compiles plotting functions directly to standalone WasmGC binaries through WasmTarget.jl. All 72 Canvas2D operations lower to native "canvas2d" host imports and standard wasm:js-string builtins.

  • Standalone WasmGC + JS glue: compile_figure(fn, argtypes) emits the .wasm binary, and WasmMakie.js_glue() provides canvas2d_imports(canvas) plus the double-buffered OffscreenCanvas canvas2d_frame_presenter.
  • Compact passive array.new_data LUTs: WasmTarget emits constant arrays via passive data segments (array.new_data), keeping all 25 colormap LUTs and bundled font metrics compact inside the compiled module.
  • Compute and plot in one binary: pure-Julia LinearAlgebra, Random, Statistics, and StatsBase code compiles into the exact same WasmGC module as your figure, so numerical updates never cross a JS serialization boundary.
JuliaCompile standalone .wasm + JS glue
using LinearAlgebra
using Random
using WasmMakie

function draw_pca_projection(seed_i::Int64)
    rng = MersenneTwister(Int(seed_i))
    n = Int64(80)
    X = Matrix{Float64}(undef, n, 2)
    i = Int64(1)
    while i <= n
        z1 = randn(rng)
        z2 = 0.35 * randn(rng)
        X[i, 1] = z1
        X[i, 2] = 0.75 * z1 + z2
        i = i + Int64(1)
    end

    # Compute SVD in pure Julia inside the exact same WasmGC module
    F = svd(X)
    u1 = F.Vt[1, 1]
    u2 = F.Vt[1, 2]

    xs = Vector{Float64}(undef, n)
    ys = Vector{Float64}(undef, n)
    k = Int64(1)
    while k <= n
        xs[k] = X[k, 1]
        ys[k] = X[k, 2]
        k = k + Int64(1)
    end

    fig = Figure(size = (640.0, 400.0))
    ax = Axis(fig[1, 1]; title = "Pure-Julia SVD + WasmMakie", xlabel = "x1", ylabel = "x2")
    scatter!(ax, xs, ys; color = (Cycled(1), 0.75), markersize = 7.0, label = "samples")
    lines!(
        ax,
        [-3.0 * u1, 3.0 * u1],
        [-3.0 * u2, 3.0 * u2];
        color = Cycled(2),
        linewidth = 2.5,
        label = "PC1",
    )
    axislegend(ax; position = :lt)
    render!(fig, WasmCtx())
    return nothing
end

wasm_bytes = compile_figure(draw_pca_projection, (Int64,))
write("pca_plot.wasm", wasm_bytes)
write("wasmmakie_glue.js", js_glue())
JavaScriptStream, instantiate, and redraw with zero flicker
const canvas = document.getElementById("plot");
const presenter = canvas2d_frame_presenter(canvas);

const { instance } = await WebAssembly.instantiateStreaming(
  fetch("pca_plot.wasm"),
  {
    canvas2d: canvas2d_imports(presenter.offscreen),
    Math: { pow: Math.pow },
  },
  { builtins: ["js-string"] }
);

function redraw(seed) {
  instance.exports.draw_pca_projection(BigInt(seed));
  presenter.present();
}

redraw(42);

With Therapy.jl

Therapy.jl Docs ↗

Loading Therapy and WasmMakie together activates the built-in WasmMakieTherapyExt package extension automatically — registering WasmMakie as Therapy's Canvas2D provider with zero boilerplate and letting you drop any WasmMakie.Figure directly into VNode trees (responsive HiDPI with automatic font deduplication). For interactive client-side plots, write reactive @island components driven by create_signal and create_effect — Therapy emits each island as a streaming external .wasm asset and supports lazy viewport hydration via hydrate = :visible.

using Therapy
import WasmMakie as WM
using WasmMakie: band!, lines!

# Zero-config setup: loading Therapy + WasmMakie automatically registers
# WasmMakie as Therapy's Canvas2D provider (via WasmMakieTherapyExt).
# Tip: use `import WasmMakie as WM` so `Figure`, `Label`, and `Legend`
# never collide with Therapy's HTML elements of the same name.

# 1. Static / SSR routes — drop any WasmMakie Figure directly into VNodes:
function StaticChartCard()
    fig = WM.Figure(size = (640, 360))
    ax = WM.Axis(fig[1, 1]; title = "Direct SSR Figure", xlabel = "x", ylabel = "y")
    xs = collect(range(0.0, 2pi; length = 120))
    lines!(ax, xs, sin.(xs); linewidth = 2.2)
    return Div(:class => "rounded-xl border p-4", fig)
end

# 2. Interactive client-side @island — compiles pure Julia to WasmGC:
@island hydrate = :visible function DampedWavePlot()
    freq, set_freq = create_signal(Int64(3))

    create_effect(
        () -> begin
            f = Float64(freq())
            fig = WM.Figure(size = (640.0, 340.0))
            ax = WM.Axis(
                fig[1, 1];
                title = "Reactive Therapy Island",
                xlabel = "t",
                ylabel = "y",
            )

            n = Int64(120)
            ts = Float64[]
            ys = Float64[]
            lo = Float64[]
            hi = Float64[]
            i = Int64(0)
            while i < n
                t = Float64(i) / Float64(n - Int64(1)) * 6.0
                y = exp(-0.25 * t) * sin(f * t)
                push!(ts, t)
                push!(ys, y)
                push!(lo, y - 0.16)
                push!(hi, y + 0.16)
                i = i + Int64(1)
            end

            band!(ax, ts, lo, hi; color = (WM.Cycled(1), 0.22))
            lines!(ax, ts, ys; color = WM.Cycled(1), linewidth = 2.2)
            WM.render!(fig, WM.WasmCtx())
        end,
    )

    return Div(
        Canvas(:width => 640, :height => 340, :style => "display:block;width:100%;height:auto;"),
        Button(:on_click => () -> set_freq(max(Int64(1), freq() - Int64(1))), "-"),
        Span(freq),
        Button(:on_click => () -> set_freq(min(Int64(8), freq() + Int64(1))), "+"),
    )
end
Hydration strategies: Use @island hydrate = :eager for above-the-fold hero figures so they draw immediately on page load, and @island hydrate = :visible for below-the-fold charts so browsers defer fetching and instantiating their .wasm until scrolled into view.

During live Pluto development, WasmMakiePlutoExt activates automatically when AbstractPlutoDingetjes (including via PlutoUI) is loaded: it transfers the bundled Makie font atlas once via published_to_js and reuses the existing <canvas> in place across @bind updates for crisp, flicker-free interactive editing. On export, Snapshot.jl compiles those same reactive Pluto.jl cells into standalone HTML and client-side WasmGC bundles that run with no Julia server.

Because WasmMakie owns the detached OffscreenCanvas presenter (canvas2d_frame_presenter), rapid slider drags coalesce onto requestAnimationFrame and swap only complete frames onto the visible canvas, eliminating flicker during continuous updates.

# Inside a Pluto.jl notebook cell:
using WasmMakie

begin
    f = Float64(freq_slider)
    fig = Figure(size = (640.0, 380.0))
    ax = Axis(fig[1, 1]; title = "Notebook Parameter Sweep", xlabel = "x", ylabel = "y")
    xs = collect(range(0.0, 2pi; length = 140))
    lines!(ax, xs, sin.(f .* xs); color = Cycled(1), linewidth = 2.2)
    fig
end

Embedding Contract

Every host framework and standalone page talks to WasmMakie through the same small public contract:

FunctionPurpose
html_snippet(fig; fonts = true, hidpi = false)Self-contained HTML fragment with canvas, bundled fonts, recorded Canvas2D stream, and JS replayer.
save(path, fig; fonts = true, hidpi = false)Write a figure directly to .html, .json (recorded command stream), or .png.
compile_figure(fn, argtypes; optimize = true)Compile a WasmMakie plotting function to WasmGC bytes against the "canvas2d" host module.
wasm_html_snippet(bytes, export; width, height)Wrap a compiled WasmGC module in a one-call standalone HTML fragment.
import_specs()Return the 72-op "canvas2d" import metadata table used by host compilers such as Therapy.jl.
js_glue()Generate the canonical JS host module (canvas2d_imports, canvas2d_frame_presenter, canvas2d_load_fonts).
font_faces_json()Bundled Makie font payloads for crisp, reproducible Canvas2D text metrics across browsers.

CanvasMakie (Server-Side Twin)

The same repository also includes CanvasMakie, a full Makie backend over the shared Canvas2D draw layer (CanvasMakie.activate!(), colorbuffer, backend_show) for server-side PNG rendering and Makie 2D reference testing. See CanvasMakie/CONFORMANCE.md for the backend conformance matrix.