Skip to content

canvas

The Canvas2D backend. CanvasBackend renders render layers to a 2D canvas context (honouring per-layer clipping and world/screen size modes), and CanvasContext is a passthrough core!PathContext that draws directly to a CanvasRenderingContext2D.

import { CanvasBackend } from "@mapequation/d3gl/canvas";
const backend = new CanvasBackend(canvasEl, width, height);
backend.setLayers(layers); // RenderLayer[] built from a Scene's buffers
backend.render();
ClassDescription
CanvasBackendA renderer for a Scene, implemented per target (WebGL / Canvas / SVG).
CanvasContextImmediate-mode backend: forwards PathContext calls straight to a real CanvasRenderingContext2D. This is the publication/fallback path and behaves exactly like drawing with d3 to a canvas today. fill()/stroke() take a style so callers don’t poke 2D-context properties directly.