Skip to content

API Reference

Complete reference of all public classes, methods, and configuration options.

What's New

Surfaces added since the initial reference. See linked sections below for full details.

New CreateConfig options

OptionTypeDefaultNotes
edgeBundlingboolean | 'fdeb' | 'merge' | objectfalseEdge bundling. true auto-pivots fdeb→merge at ≥150 edges. See Edge Bundling.
autoFitOnChangebooleantrueRe-fit viewport on batch:end / focus:edge-filter / focus:pin / focus:release. Suppressed when the viewport is user-dirty (manual pan / zoom / pinch).
hideOrphansbooleanfalseHide non-combo nodes with zero visible incident edges. See Filtering.
autoCollapseCombosForcebooleanfalseBypass the “user already collapsed something” guard so force layouts always honor autoCollapseCombosThreshold.
comboEdgeAggregationbooleantrueSynthesize cross-boundary edges between visible collapse-roots. Set false to drop them.
legend.groupEdgesBystring | callbackauto-detectOpts into the edge-type filter section of the Legend. Auto-detect probes type → category → role → kind → class.
minimap.mode'dots' | 'heatmap' | 'both''dots'Heatmap modes suppress edges. See Minimap modes.
layoutOptions.comboStrengthnumber0.15combo-force layout: centroid spring.
layoutOptions.comboRepelStrengthnumber0.5combo-force layout: inter-combo repulsion.
layoutOptions.comboMinMembersnumber2combo-force layout: combos below this size skip both extra passes.

New public methods

MethodWhereNotes
renderer.requestAutoFit()CanvasRendererDebounced auto-fit. Honors the viewport user-dirty flag.
renderer.getSynthesizedComboEdges()CanvasRendererReturns the current synthetic __combo_edge_* edges (empty when no combos collapsed).
legend.toggleCategory(key)LegendToggle visibility of all nodes in node group key.
legend.toggleEdgeCategory(key)LegendFade/restore all edges in edge group key. Emits focus:edge-filter.
createAutoFitOnChangeApplier(graph, renderer)top-level exportReturns an object with a destroy() method. Wires the autoFitOnChange behavior.
computeLegendBodyMaxHeight(args)top-level exportPure helper for legend ↔ minimap clearance. Returns number | null.
computeHeatmapDensity(nodes, bounds, gridSize)top-level exportGrid-aggregated density for minimap heatmap mode.
sampleHeatmapColor(palette, t)top-level exportInterpolated color from a cold-to-hot palette at t in [0, 1].

New public events

EventPayloadFired When
focus:pinnodeId, hopsA node is pinned via pinned-focus / clickable legend.
focus:releaseundefinedPinned focus is released.
focus:edge-filterhiddenTypes: string[]Edge-type filter changes. Payload is the current full hidden-set, not a diff.

New globals / build metadata

  • window.GraphKit.VERSION — injected at build time as <semver>+<sha>[-dirty] (e.g. 0.9.0+384b375). Useful for in-browser debugging and bug reports. In Node / unbundled test contexts the symbol falls back to '0.0.0-dev'.
  • VERSION from @graphkit/core — same string, importable for non-IIFE consumers.

create(container, config)

TypeScript
import { create } from '@topokit/renderer-canvas';

const app = create(container: HTMLElement, config: CreateConfig);

CreateConfig

PropertyTypeDescription
nodesNode[]Initial node array
edgesEdge[]Initial edge array
graphGraphPre-built graph (overrides nodes/edges)
layoutstringLayout algorithm name
layoutOptionsobjectOptions passed to layout algorithm
layoutRunnerLayoutRunnerFnCustom layout runner (e.g., Web Worker)
themestring | ThemeConfigTheme name or custom object
directedbooleanEnable directed edges
interactivebooleanEnable pan, zoom, drag
autoResizebooleanAuto-resize on container resize
licensestringLicense key
whiteLabelbooleanRemove branding (Enterprise)
minimapMinimapConfigMinimap configuration
toolbarToolbarConfigToolbar configuration
searchSearchConfigSearch bar configuration
tooltipTooltipConfigTooltip configuration
contextMenuContextMenuConfigContext menu configuration
infoPanelInfoPanelConfigInfo panel configuration
legendLegendConfigLegend configuration
edgeBundlingboolean | 'fdeb' | 'merge' | EdgeBundlingOptionsEdge bundling (see What's New).
autoFitOnChangebooleanRe-fit viewport on graph / focus changes (default true).
hideOrphansbooleanHide non-combo nodes with no visible incident edges (default false).
autoCollapseCombosForcebooleanForce layouts always honor autoCollapseCombosThreshold (default false).
comboEdgeAggregationbooleanSynthesize cross-boundary combo edges (default true).

App Instance

Property / MethodTypeDescription
app.graphGraphUnderlying graph instance
app.rendererCanvasRendererCanvas renderer instance
app.setLayout(name, options?)voidSwitch layout algorithm
app.setTheme(name | config)voidSwitch theme
app.bundleEdges(options?)voidEnable edge bundling at runtime
app.unbundleEdges()voidDisable edge bundling
app.legendLegendLegend component instance (when enabled). Exposes toggleCategory / toggleEdgeCategory.
app.setMinimap(config)voidUpdate minimap
app.setToolbar(config)voidUpdate toolbar
app.setSearch(config)voidUpdate search
app.setTooltip(config)voidUpdate tooltip
app.setLegend(config)voidUpdate legend
app.destroy()voidClean up all resources

Graph Class

TypeScript
import { Graph } from '@topokit/core';
const graph = new Graph(options?);

Node Operations

MethodReturnsDescription
addNode(node)voidAdd a node
removeNode(id)voidRemove node and its edges
updateNode(id, changes)voidMerge changes into node
getNode(id)Node | undefinedGet node by ID
getNodes()Node[]Get all nodes
getNodeCount()numberTotal node count
hasNode(id)booleanCheck existence
getNeighbors(id)Node[]Get neighboring nodes
getDegree(id)numberConnection count

Edge Operations

MethodReturnsDescription
addEdge(edge)voidAdd an edge
removeEdge(id)voidRemove an edge
updateEdge(id, changes)voidMerge changes into edge
getEdge(id)Edge | undefinedGet edge by ID
getEdges()Edge[]Get all edges
getEdgeCount()numberTotal edge count
getEdgesBetween(a, b)Edge[]Edges between two nodes
getNodeEdges(nodeId)Edge[]All edges of a node

Filter & Highlight

MethodReturnsDescription
filter(predicate)voidHide non-matching nodes
resetFilter()voidShow all hidden nodes
highlightByPredicate(fn, opts?)voidDim non-matching nodes
highlightNodes(ids)voidHighlight by ID array
resetHighlight()voidReset all highlighting

Progressive Expand

MethodReturnsDescription
initExpand(options)voidEnter expand mode with seeds
expand(nodeId)voidReveal neighbors
collapse(nodeId)voidHide neighbors
expandAll()voidReveal all
collapseAll()voidCollapse to seeds
resetExpand()voidExit expand mode

Clustering

MethodReturnsDescription
cluster(options)voidGroup nodes by field or function
uncluster()voidRestore ungrouped graph

Batch & Events

MethodReturnsDescription
batch(fn)voidAtomic multi-change operation
on(event, handler)() => voidSubscribe (returns unsub fn)
off(event, handler)voidUnsubscribe

Static Methods

MethodReturnsDescription
Graph.fromData(data, mapping)GraphCreate graph from JSON with mapping config

CanvasRenderer

Accessed via app.renderer.

MethodReturnsDescription
render()voidForce re-render
fitToScreen(padding?)voidZoom to fit graph
zoomTo(level)voidSet zoom (1.0 = 100%)
panTo(x, y)voidPan viewport to coordinates
centerOnNode(nodeId)voidCenter on a node
getZoom()numberCurrent zoom level
getViewport()RectCurrent viewport bounds
toImage(format?, quality?)Promise<Blob>Export canvas as image
resize(w, h)voidManual canvas resize
requestAutoFit()voidDebounced re-fit. Honors viewport user-dirty flag.
getSynthesizedComboEdges()GraphEdge[]Current synthetic __combo_edge_* edges; empty when no combos collapsed.
destroy()voidClean up renderer

React Hooks & Components

useGraph(config)

TypeScript
import { useGraph } from '@topokit/react';

const { graph, renderer } = useGraph({
  nodes: [...],
  edges: [...],
  layout: 'force',
  theme: 'dark',
});
ReturnTypeDescription
graphGraphStable graph instance
rendererRefObject<CanvasRenderer>Renderer ref (available after mount)

useRenderer()

TypeScript
import { useRenderer } from '@topokit/react';

function Controls() {
  const renderer = useRenderer();
  return <button onClick={() => renderer.fitToScreen()}>Fit</button>;
}

GraphCanvas

TypeScript
import { GraphCanvas } from '@topokit/react';

<GraphCanvas
  graph={graph}
  renderer={renderer}
  style={{ width: '100%', height: '600px' }}
  onNodeClick={(node) => console.log(node)}
  onEdgeClick={(edge) => console.log(edge)}
/>
PropTypeDescription
graphGraphGraph from useGraph
rendererRefObjectRenderer ref from useGraph
styleCSSPropertiesContainer styles
classNamestringCSS class
onNodeClick(node) => voidNode click handler
onNodeDoubleClick(node) => voidDouble-click handler
onEdgeClick(edge) => voidEdge click handler
onCanvasClick() => voidCanvas click handler
onSelectionChange(selection) => voidSelection change handler

Core Types

TypeScript
interface Node {
  id: string;
  data: Record<string, any>;
  position?: { x: number; y: number };
  style?: Partial<NodeStyle>;
}

interface Edge {
  id: string;
  source: string;
  target: string;
  data: Record<string, any>;
  style?: Partial<EdgeStyle>;
}

interface NodeStyle {
  shape: 'circle' | 'rect' | 'diamond' | 'hexagon' | 'triangle';
  fill: string;
  stroke: string;
  radius: number;
  label: string;
  fontSize: number;
  fontColor: string;
  opacity: number;
  icon: string;
  badges: NodeBadge[];
}

interface EdgeStyle {
  type: 'line' | 'curve' | 'step';
  stroke: string;
  width: number;
  arrow: boolean;
  dashed: boolean;
  animated: boolean;
  label: string;
  opacity: number;
}

interface NodeBadge {
  text: string;
  color: string;
  background: string;
  position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
  shape: 'circle' | 'rect';
  icon?: 'dot' | 'alert' | 'check' | 'star';
}