Web Worker Layout
Move layout computation off the main thread to keep the UI responsive during large graph layouts.
Setup
1. Create the Worker Script
import { WorkerLayoutRunner } from '@topokit/layouts/worker';
const runner = new WorkerLayoutRunner();
runner.listen(); 2. Use in Your App
import { create } from '@topokit/renderer-canvas';
import { WorkerLayoutRunner } from '@topokit/layouts/worker';
const worker = new Worker(
new URL('./layout-worker.js', import.meta.url),
{ type: 'module' }
);
const layoutRunner = new WorkerLayoutRunner(worker);
const app = create(container, {
nodes: largeDataset.nodes,
edges: largeDataset.edges,
layout: 'force',
theme: 'dark',
layoutRunner: layoutRunner.toLayoutRunner(),
}); Most modern bundlers (Vite, Webpack 5, Rollup) support the new URL(..., import.meta.url) pattern automatically.
LayoutRunnerFn Signature
type LayoutRunnerFn = (
algorithm: string,
nodes: Node[],
edges: Edge[],
options?: Record<string, any>
) => Promise<{ positions: Map<string, { x: number; y: number }> }>; You can implement your own layout runner (e.g., server-side) as long as it matches this interface.
Performance Tips
- Level-of-Detail: Renderer automatically simplifies nodes at low zoom. No config needed.
- Spatial Indexing: Quadtree for O(log n) hit-testing and viewport culling.
- Batch Updates: Always use
graph.batch()for bulk changes. - Reduce Edges: Filter, cluster, or bundle to reduce edge count.
| Node Count | Performance | Strategy |
|---|---|---|
| < 500 | Smooth anywhere | No optimization needed |
| 500 -- 2,000 | Smooth on modern devices | Consider Web Worker |
| 2,000 -- 10,000 | Needs optimization | Worker + expand + clustering |
| > 10,000 | Advanced | All above + filtering + server-side layout |
White Label
Enterprise license holders can remove all TopoKit branding.
const app = create(container, {
nodes: [...],
edges: [...],
license: 'your-enterprise-license-key',
whiteLabel: true,
}); Licensing
| Feature | Trial | Pro | Enterprise |
|---|---|---|---|
| Duration | 30 days | 1 year | 1 year |
| Node limit | 50 | Unlimited | Unlimited |
| Watermark | Yes | No | No |
| All features | Yes | Yes | Yes |
| White label | No | No | Yes |
| SSO | No | No | Yes |
| Support | Community | Priority + SLA | |
| Perpetual fallback | No | Yes | Yes |
const app = create(container, {
nodes: [...],
edges: [...],
license: 'GK-PRO-XXXX-XXXX-XXXX',
}); Without a license key, TopoKit runs in Trial mode (30 days, 50 nodes, watermark). See pricing for details.
Next Steps
- Layout Algorithms -- choose the right layout
- Clustering -- simplify large graphs
- API Reference -- complete method listing