@simplex-viz/svg API Reference
Portable SVG renderer, offscreen getBBox() hull measurement, root pointer hit-testing, client-side SVG/PNG export, zero-DOM SSR string rendering (@simplex-viz/svg/ssr), 1:4 subdivision previews, and breadcrumbs.
- @simplex-viz/svg v1.0.0
- Framework-Agnostic SVG Scene Graph, Export & Zero-DOM SSR
Entry Points
Environment: Browser DOM (Vanilla TS, Vue, Angular, Svelte, Solid)
Interactive SVG controller, offscreen getBBox() hull measurement, pluggable Svg*View system, client-side SVG/PNG export, and core strategy re-exports.
Environment: Node.js, Edge, Astro / Next.js SSR builds
Exclusive zero-DOM subpath (not re-exported from root) providing SVG string rendering & deterministic font-metric measurers for server bundles.
Primary Exports
import { … } from '@simplex-viz/svg'
Root entrypointcreateSimplexSvg(
container: HTMLElement | string,
itemsOrOptions: readonly TItem[] | SimplexSvgOptions<...>,
maybeOptions?: Partial<SimplexSvgOptions<...>>,
): SimplexSvgController<...>Zero-boilerplate factory mounting a complete interactive SVG simplex atlas into an HTMLElement or CSS selector.
new SimplexSvgController<
TItem, TContentVisual, TClusterVisual, TTagMeta, TClusterMeta
>(options: SimplexSvgOptions<...>)Manages ResizeObserver (with 0x0 auto-recovery & deferInitialLayout), rAF loop, live prefers-reduced-motion subscription (reducedMotion), Shift+Click & Shift+Drag marquee multi-selection (selectedIds, shiftClickSelects, marqueeSelection, onSelectionChange), structured getLegendModel()/onLegendChange synced with zoom/filter/focus/timeline, custom DOM/HTML tooltip renderers (SimplexDomTooltipRenderer) with viewport edge-flipping, deep-link getViewState()/restoreViewState(), zero-relayout itemFilter, linked-view setHighlightedIds()/focusItem()/zoomToItem(), client-side exportSvg()/exportPng(), re-entrant batch()/setOptions(), WCAG 2.1 AA keyboard navigation & aria-live announcements, mobile touchScrollLockPx/clickTolerancePx, timeline HUD, and breadcrumbs—powered by shared @simplex-viz/core/dom primitives.
new SvgRendererAdapter(options: SvgRendererAdapterOptions)Low-level SimplexRendererAdapter reconciling SVG layers, view-level hoverScale/dimmedOpacity hooks, semantic ARIA metadata (ariaIdPrefix), zoom-adaptive double-halo focus rings, dual-layer crossfades, and internal 1:4 drillable edges.
new GeometricShapeSvgView(options?: GeometricShapeSvgViewOptions)Renders and morphs circles, diamonds, stars, and arbitrary regular N-gons (sides >= 3) with exact convex SAT hulls plus lightweight shapeOptions (hoverScale, hoverRingColor, dimmedOpacity, strokeColor, strokeWidth).
new MultiSectorGlyphSvgView()Renders multi-arc donut glyphs proportional to an item's barycentric cluster weights.
new OklabTintTriangleSvgView(options?: OklabTintTriangleOptions)Default triangle face view with subtle OKLab fills, hover/focus perimeter strokes, and dimmed neighbor context.
new BadgeClusterSvgView(options?: BadgeClusterSvgViewOptions)WCAG-AA saturated OKLab cluster view rendering full-round capsules (configurable via showCode, maxTitleChars, formatTitle) and chamfered hexagonal plaques for intermediate sub-clusters.
new DashedMeshEdgeSvgView(options?: DashedMeshEdgeOptions)Default dashed 60-degree mesh edge view, automatically reused for internal 1:4 drillable triangle subdivision lines.
import { … } from '@simplex-viz/svg/ssr'
Exclusive subpathrenderSimplexSvgString<TItem, TTagMeta, TClusterMeta>(
itemsOrSnapshot: readonly TItem[] | SimplexLayoutSnapshot<TItem, TTagMeta, TClusterMeta>,
options?: RenderSimplexSvgStringOptions<TItem, TTagMeta, TClusterMeta>,
): stringZero-DOM SSR SVG string renderer supporting deterministic font metrics (estimateSsrTextWidth, createSsrPresetHullMeasurers, pluggable measureText), all presets, themes, filters, highlights, and custom SVG string hooks.
Mounting in Vanilla TypeScript, Vue, Svelte, or Angular
createSimplexSvg accepts either a CSS selector ('#atlas') or an HTMLElement reference and returns a SimplexSvgController whose .destroy() method cleans up all DOM listeners and ResizeObserver instances:
import {
createSimplexSvg,
createSubspaceZoomStrategy,
GradientTriangleSvgView,
ClusterTintedEdgeSvgView,
} from '@simplex-viz/svg';
const controller = createSimplexSvg('#atlas', {
items,
preset: 'glyphs',
theme: 'dark',
triangleView: new GradientTriangleSvgView({ baseOpacity: 0.16 }),
edgeView: new ClusterTintedEdgeSvgView({ strokeWidth: 1.35 }),
zoomStrategy: createSubspaceZoomStrategy(),
showZoomBreadcrumbs: true,
itemFilter: (item) => item.tags.includes('geometry'),
itemFilterMode: 'dim',
ariaLabel: 'Interactive knowledge simplex atlas',
keyboardNavigation: true,
tooltip: {
render(target, container) {
if (target.kind !== 'content') return false;
const title = document.createElement('strong');
title.textContent = target.item.label;
container.replaceChildren(title);
},
},
onLegendChange: (legend) => {
console.log('Legend entries:', legend.entries.length, 'visible:', legend.visibleItems);
},
});
// Coalesce multi-property runtime updates into a single recomputation:
controller.setOptions({
theme: 'light',
itemFilterMode: 'hide',
highlightedIds: ['item-1', 'item-4'],
});
// Programmatic linked-view navigation, legend snapshot, multi-selection, deep-linking & export:
const legend = controller.getLegendModel();
controller.zoomToItem('item-1', { zoom: 2.2, maxDrillSteps: 4 });
controller.setSelectedIds(['item-1', 'item-4']);
const snapshot = controller.getViewState();
controller.restoreViewState(snapshot);
const svgMarkup = controller.exportSvg({ padding: 24, title: 'Knowledge Atlas' });
const pngBlob = await controller.exportPng({ scale: 2, padding: 24 });
// Clean up on unmount:
// controller.destroy();
Headless Zero-DOM SSR (@simplex-viz/svg/ssr)
Import renderSimplexSvgString from @simplex-viz/svg/ssr in Node.js, Edge runtimes, Astro/Next.js builds, or headless PNG pipelines (such as @resvg/resvg-js) without bundling browser controller code or running Puppeteer:
import { renderSimplexSvgString } from '@simplex-viz/svg/ssr';
const svg = renderSimplexSvgString(items, {
width: 1200,
height: 720,
preset: 'badges',
theme: 'dark',
padding: 24,
});
Custom SvgNodeView Contract
Implement SvgNodeView<TVisual, TRenderState> when building high-throughput custom SVG glyphs that update imperatively at 60 fps without virtual-DOM overhead:
import type { SvgNodeView, ContentNodeRenderState } from '@simplex-viz/svg';
export const pillNodeView: SvgNodeView<
{ label: string; colorHex: string },
ContentNodeRenderState<{ label: string; colorHex: string }, MyItem>
> = {
createElement(doc) {
const g = doc.createElementNS('http://www.w3.org/2000/svg', 'g');
const rect = doc.createElementNS('http://www.w3.org/2000/svg', 'rect');
const text = doc.createElementNS('http://www.w3.org/2000/svg', 'text');
g.append(rect, text);
return g;
},
updateElement(g, visual, state) {
const [rect, text] = g.children as unknown as [SVGRectElement, SVGTextElement];
rect.setAttribute('x', '-42');
rect.setAttribute('y', '-12');
rect.setAttribute('width', '84');
rect.setAttribute('height', '24');
rect.setAttribute('rx', '6');
rect.setAttribute('fill', visual.colorHex);
rect.setAttribute('opacity', state.interaction.isDimmed ? '0.28' : '1');
text.textContent = visual.label;
},
};