Getting Started
Install TopoKit and render your first graph in under five minutes.
Installation
# npm
npm install @topokit/core @topokit/layouts @topokit/renderer-canvas
# yarn
yarn add @topokit/core @topokit/layouts @topokit/renderer-canvas
# pnpm
pnpm add @topokit/core @topokit/layouts @topokit/renderer-canvas For React projects, also install:
npm install @topokit/react IIFE Bundle (No Bundler)
<script src="https://cdn.topokit.io/topokit.js"></script> Quick Start
import { create } from '@topokit/renderer-canvas';
const app = create(document.getElementById('graph'), {
nodes: [
{ id: 'alice', data: { name: 'Alice' }, style: { fill: '#3B82F6', label: 'Alice' } },
{ id: 'bob', data: { name: 'Bob' }, style: { fill: '#8B5CF6', label: 'Bob' } },
{ id: 'charlie', data: { name: 'Charlie' }, style: { fill: '#10B981', label: 'Charlie' } },
],
edges: [
{ id: 'e1', source: 'alice', target: 'bob', data: {} },
{ id: 'e2', source: 'bob', target: 'charlie', data: {} },
{ id: 'e3', source: 'charlie', target: 'alice', data: {} },
],
layout: 'force',
theme: 'dark',
}); TopoKit renders the nodes, connects them, runs force layout, and enables pan/zoom/drag automatically.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
nodes | Node[] | [] | Initial node array |
edges | Edge[] | [] | Initial edge array |
layout | string | 'force' | Layout algorithm name |
theme | string | 'dark' | Built-in theme name |
directed | boolean | true | Show edge direction arrows |
interactive | boolean | true | Enable pan, zoom, drag |
layoutRunner | function | undefined | Custom layout runner (e.g., Web Worker) |
autoResize | boolean | true | Resize canvas on container resize |
React Quick Start
import { GraphCanvas, useGraph } from '@topokit/react';
function App() {
const { graph, renderer } = useGraph({
nodes: [
{ id: 'a', data: { name: 'Alice' }, style: { label: 'Alice' } },
{ id: 'b', data: { name: 'Bob' }, style: { label: 'Bob' } },
],
edges: [
{ id: 'e1', source: 'a', target: 'b', data: {} },
],
layout: 'force',
theme: 'dark',
});
return (
<GraphCanvas
graph={graph}
renderer={renderer}
style={{ width: '100%', height: '600px' }}
/>
);
}
export default App; useGraph returns a reactive graph instance and renderer ref. GraphCanvas handles canvas lifecycle and cleanup.
Next Steps
- Core Concepts -- graph data model, events, and themes
- Layouts -- all 7 layout algorithms
- Filtering & Highlighting -- show, hide, or dim nodes
- Components -- legends, badges, minimap
- Embedding (iframe) -- drop a topo into your site, BYO license to suppress the watermark
- API Reference -- full method reference