Skip to content

Generators, parsers & geometry

This page collects the supporting APIs: generators, parsers, geometry, transformations, layers, schema watchers, export and backend activation.

nodus.generate.* builds graphs procedurally. Each is deterministic and seeded, and returns a Promise. Option semantics are described generically (counts, branching factors, probabilities); the exact keys vary by generator.

  • balancedTree(opts?) — a balanced tree.
  • barabasiAlbert(opts?) — a scale-free (preferential-attachment) graph.
  • erdosRenyi(opts?) — a random graph with a per-edge probability.
  • flower(opts?) — a flower graph.
  • grid(opts?) — a regular grid.
  • path(opts?) — a path graph.
  • random(opts?) — a random graph.
  • randomTree(opts?) — a random tree.

Each generator returns a { nodes, edges } graph — pass it to setGraph to load it.

const g = await nodus.generate.barabasiAlbert({ nodes: 40, m0: 2, m: 1 });
await nodus.setGraph(g);
await nodus.layouts.force({ duration: 0 });
await nodus.view.locateGraph();

See the Generating Graphs guide for worked examples.

import { parse } from '@kortexya/nodus';

The parse namespace turns graph file formats into the RawGraph JSON shape ({ nodes, edges }) you pass to setGraph. One supported format is MTX (Matrix Market) sparse matrices.

import { parse } from '@kortexya/nodus';
const mtxText = await (await fetch('/data/graph.mtx')).text();
const rawGraph = parse.mtx(mtxText); // -> { nodes, edges }
await nodus.setGraph(rawGraph);

See Parsing Data for more.

There are two geometry surfaces:

  • The static geometry namespace — pure geometry utilities, importable on their own.
  • nodus.geo — geometry helpers bound to the instance.
import { geometry } from '@kortexya/nodus';

The utilities cover these categories:

  • Distances — distances between points and shapes.
  • Intersections — intersection tests and points between shapes.
  • Polygons — polygon operations.
  • Circles — circle operations.
  • Bézier curves — Bézier curve math.
import { geometry } from '@kortexya/nodus';
// distances, intersections, polygons, circles and Bézier helpers

nodus.transformations applies graph transformations — for example grouping duplicate edges, or building meta-edges/bundling. The Transformation class is exported for advanced use.

import { Transformation } from '@kortexya/nodus';

Try it live — group nodes and collapse them into a single meta-node:

Grouping & collapse Open in new tab ↗

nodus.layers manages multiple render layers — for example a background layer drawn behind the graph. Use it when you need to compose additional content with the graph render.

nodus.schema provides reactive property watchers. Two watcher classes are exported:

import { NonObjectPropertyWatcher, ObjectPropertyWatcher } from '@kortexya/nodus';

Use NonObjectPropertyWatcher for primitive properties and ObjectPropertyWatcher for object-valued properties when you need to react to changes.

nodus.export exports the graph or an image. SVG is the vector export path. For a raster snapshot, use nodus.view.getImageData().

// Raster snapshot of the current render:
const image = nodus.view.getImageData();

These functions move compute work to the compiled Rust backend, which offloads force layout, shortest-path (Bellman-Ford / Johnson / Dijkstra), hierarchical layout (Sugiyama), stress minimization, geometry kernels and spatial indexing.

  • enableWasmBackend() — turn on the compiled compute backend.
  • useWasm(subsystem) — activate a subsystem, where subsystem is 'layout' | 'geometry' | 'all'.
  • configureBackends(...) — finer-grained backend configuration.

The types Subsystem and Backend are also exported.

import { enableWasmBackend, useWasm } from '@kortexya/nodus';
enableWasmBackend();
useWasm('all');

See WASM backend for the architecture behind this.