@simplex-viz/canvas API Reference
Framework-agnostic Canvas 2D renderer with viewport frustum culling, automatic LOD simplification, HiDPI scaling, 1:4 zoom/drill-down, timeline playback, and native PNG export.
- @simplex-viz/canvas v1.0.0
- High-Capacity HTML5 Canvas 2D Renderer (2,000–10,000+ Items)
Entry Points
Environment: Browser HTML5 Canvas 2D (Framework-agnostic, zero @simplex-viz/svg dependency)
High-capacity Canvas 2D controller & adapter, stateless snapshot painter, frustum culling, automatic LOD simplification, and native PNG export.
Primary Exports
import { … } from '@simplex-viz/canvas'
Root entrypointcreateSimplexCanvas<TItem, TContentVisual, TClusterVisual, TTagMeta, TClusterMeta>(
container: HTMLElement | string,
itemsOrOptions: readonly TItem[] | SimplexCanvasControllerOptions<...>,
): SimplexCanvasController<...>Zero-boilerplate factory mounting an interactive high-capacity Canvas 2D simplex atlas into an HTMLElement or CSS selector.
new SimplexCanvasController<
TItem, TContentVisual, TClusterVisual, TTagMeta, TClusterMeta
>(container: HTMLElement | string, options: SimplexCanvasControllerOptions<...>)Manages ResizeObserver (with 0x0 auto-recovery & deferInitialLayout), relayoutOnFontLoad, rAF spring loop with onFpsUpdate, frustum-culled Canvas 2D rendering, hierarchical 1:4 zoom with built-in breadcrumb HUD, timeline playback bar & subscribeTimeline(), Shift+Click/Shift+Drag marquee multi-selection, WCAG 2.1 AA keyboard navigation & focus target APIs, custom DOM/HTML tooltips (SimplexDomTooltipRenderer), getLegendModel()/setOnLegendChange(), getViewState()/restoreViewState(), full atomic setOptions()/batch(), highlightedIds, onClustersChange, and native exportPng().
new CanvasRendererAdapter(options: CanvasRendererAdapterOptions)Low-level SimplexRendererAdapter implementing HiDPI DPR scaling, world-space viewport culling, automatic LOD simplification (lodThresholdPx), dual-layer crossfades, and pluggable CanvasNodeRenderer / CanvasTriangleRenderer / CanvasEdgeRenderer hooks.
renderSimplexSnapshotToCanvas<TItem>(
canvas: HTMLCanvasElement,
snapshot: SimplexLayoutSnapshot<TItem>,
options?: RenderSimplexSnapshotToCanvasOptions,
): CanvasRenderStatsStateless one-shot renderer painting a pre-solved SimplexLayoutSnapshot (from solveSimplexSnapshot() or @simplex-viz/core/worker) directly onto a <canvas> element.
createCanvasPresetVisualResolver<TItem, TTagMeta, TClusterMeta>(
preset: CanvasVisualPreset,
options?: CanvasPresetResolverOptions<TItem, TTagMeta, TClusterMeta>,
): VisualResolver<...>Creates built-in 'geometric', 'glyphs', or 'badges' visual resolvers with analytical Canvas 2D convex hull measurement.
Overview
@simplex-viz/canvas renders the entire simplex atlas onto a single HiDPI <canvas> with zero per-node DOM overhead, world-space viewport frustum culling, and automatic Level-of-Detail (LOD) shape simplification for corpora of 2,000–10,000+ items at 60 FPS. It depends exclusively on @simplex-viz/core (including pure preset/OKLab/timeline helpers and @simplex-viz/core/dom container, tooltip, breadcrumb & timeline HUD overlays, accessibility, and gesture primitives) with zero dependency on @simplex-viz/svg, while mirroring SimplexSvgController’s full interactive API (timeline: true shorthand, setTimelineOptions, subscribeTimeline, showZoomBreadcrumbs, setZoomUiOptions, setOptions, batch, deferInitialLayout, relayoutOnFontLoad, onClustersChange, onFpsUpdate, SimplexDomTooltipRenderer tooltips, getKeyboardFocusTarget, getInteractiveTargets, restoreViewState) and curated @simplex-viz/core root re-exports.
Interactive Canvas Controller
import {
createSimplexCanvas,
createCollisionDrivenLayoutStrategy,
createSubspaceZoomStrategy,
} from '@simplex-viz/canvas';
const controller = createSimplexCanvas('#atlas', {
items: largeCorpus,
preset: 'badges',
theme: 'dark',
lodThresholdPx: 3.5,
layoutStrategy: createCollisionDrivenLayoutStrategy(),
zoomStrategy: createSubspaceZoomStrategy(),
tooltip: true,
});
// Inspect render culling & LOD stats for profiling:
console.log(controller.getRenderStats());
// Native zero-serialization PNG export:
const pngBlob = await controller.exportPng({ scale: 2 });
Pairing with @simplex-viz/core/worker
import { createSimplexWorkerClient } from '@simplex-viz/core/worker';
import { renderSimplexSnapshotToCanvas } from '@simplex-viz/canvas';
const worker = createSimplexWorkerClient(
() => new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),
);
const { snapshot } = await worker.solve(largeCorpus, {
width: 1200,
height: 760,
layoutStrategy: { kind: 'collision-driven' },
});
renderSimplexSnapshotToCanvas(canvasEl, snapshot, { theme: 'dark' });
See this exact pipeline running live on 1,000–3,500 stars in the Hertzsprung-Russell Stellar Spectral Atlas example.