1.1.0 • Published 10h ago
@ouestware/graphology-layout-elk
Licence
—
Version
1.1.0
Deps
2
Size
44 kB
Vulns
0
Weekly
0
OuestWare's Graphology Experiments - Layout ELK
A graphology connector to the elkjs layout engine.
It translates a graphology graph into ELK's graph format, runs an ELK algorithm (layered by default), and returns a
LayoutMapping of each node to its position and box size.
Usage
import Graph from "graphology";
import { elkLayout } from "@ouestware/graphology-layout-elk";
import { applyLayout } from "@ouestware/graphology-layout-utils";
const graph = new Graph();
// ...populate the graph...
const layout = await elkLayout(graph, {
// ELK options, forwarded as-is:
layoutOptions: { "elk.algorithm": "layered", "elk.direction": "RIGHT" },
// How to read each node's box size from the graph:
attributes: {
width: "width", // read from the "width" node attribute
height: (node, attributes) => attributes.size * 2, // or extract it
},
});
// Write x / y back as node attributes, and the box size as "w" / "h":
applyLayout(graph, layout, { width: "w", height: "h" });Notes
elkLayoutis asynchronous (it returns aPromise).- ELK positions boxes by their top-left corner: By default, the returned coordinates are node centers.
Set
center: falseto keep ELK's top-left corners. - The bundled elkjs engine runs on the main thread.