Expand description
Layered (Sugiyama-style) layout of a directed graph of boxes — nodes in layers (stages) along one axis, ordered across it to keep crossings low.
The steps: cycles broken by a DFS in input order; ranks by longest path (a pinned layer wins; sources pulled up to just before their nearest successor); a dummy vertex per layer a long edge passes; barycenter sweeps plus adjacent transposition, the fewest crossings kept (counted per layer pair with a Fenwick tree); a weighted least-squares (isotonic) placement along each layer; ports spread along a box’s side; optional swimlanes as bands. A graph whose every node is pinned in both axes is drawn on a grid where it is placed, with straight edges.
Node sizes come from the caller (the box contents are the drawing’s
business); the result is in px with the origin at the top-left margin.
Moved here from anofox-visualization’s ::DIAGRAM (sipemu/ggplot-rs#497,
DataZooDE/anofox-visualization#1153).
Structs§
- Banded
Params - Spacing of
banded. - Graph
Edge - A directed edge;
label_wis the width (px) of its label, if it has one: left to right, the gap between two layers is at least as wide as the labels that cross it. - Graph
Layout - The laid-out graph.
- Graph
Node - A node: its box size, its swimlane, and optional pins (a layer, and a position across it; both pinned on every node → the grid layout).
- Layered
Params - Spacing and options; the defaults are anofox-visualization’s diagram.
- Placed
Node - A placed node: centre, size, layer, and rank in reading order (layer by layer, then along it).
Enums§
- Direction
- Which way the layers run.
Functions§
- banded
- Lay out a graph in horizontal bands (a factor graph’s layers: control,
parameters, states, observations, …), left to right. A column is a step
along an edge within a band; an edge into another band keeps the
column, so a branch drops straight down (or up) into its band — the
state chain stays one straight row with each observation below its
state. A leaf hanging off one node of its band (an observed variable
under its factor) sits right below it; nodes dropping in from other
bands side by side fan out over the band’s free columns. Nodes that
still share a band and a column stack in tracks, a node staying on the
track of the node before it in its band. A source is
pulled right to just before its first successor in its band (a
constant next to its factor). Edges are straight; a cycle’s closing
edge is drawn as is and marked
back. - layered
- Lay out
nodesandedgesin layers (see the module docs).