dagre-dgl-rs
A faithful Rust port of dagre-js — a directed graph layout library that produces layered, hierarchical graph drawings.
What it does
dagre-dgl-rs takes a directed graph with node sizes and edge constraints, runs a multi-stage layout pipeline, and outputs x/y coordinates for each node and a list of waypoints for each edge. It does not render anything — it is a pure layout engine.
Layout pipeline
The stages mirror dagre-js exactly:
- Acyclic — reverse edges to make the graph a DAG
- Rank — assign each node to a horizontal layer (network simplex)
- Nesting — handle compound/nested graphs
- Normalize — insert dummy nodes on long edges
- Order — minimise edge crossings within each layer
- Position — assign x/y coordinates (Brandes-Köpf)
- Edge routing — compute waypoints through dummy nodes
Usage
use ;
let mut g = with_options;
g.set_graph;
g.set_node;
g.set_node;
g.set_edge;
layout;
let a = g.node;
println!;
Graph options
Graph::with_options(multigraph, directed, compound):
| Parameter | Description |
|---|---|
multigraph |
Allow multiple edges between the same pair of nodes |
directed |
Treat edges as directed (required for layout) |
compound |
Enable parent/child node relationships |
GraphLabel fields
| Field | Default | Description |
|---|---|---|
rankdir |
"TB" |
Layout direction: TB, BT, LR, RL |
nodesep |
50 |
Minimum gap between nodes in the same rank |
edgesep |
10 |
Minimum gap between edge splines |
ranksep |
50 |
Minimum gap between ranks |
marginx |
0 |
Graph margin (x) |
marginy |
0 |
Graph margin (y) |
Output
After layout(), each node has x and y set to its centre coordinates, and each edge label has points: Vec<Point> containing the waypoints.
Running tests
The test suite is ported from dagre-js/test/ and covers the rank, network simplex, and layout algorithms.
Run all tests:
Run with output visible (useful for debugging):
Run a specific test by name:
Run tests matching a pattern:
Dependencies
License
MIT © 2026 Rochanglien Infimate