Dagre is a pure JavaScript library for automatically laying out directed graphs. It implements a layered graph drawing algorithm based on the Sugiyama framework, positioning nodes in horizontal layers and routing edges to produce clear, readable visualizations with no native dependencies.
The library handles edge routing as polylines with control points to avoid overlapping nodes, reduces edge crossings through heuristic node ordering within layers, and assigns final coordinates using a slack-based approach that respects minimum separation constraints. Graph structure and layout options are exchanged as plain JSON objects, making dagre straightforward to integrate into JavaScript applications. It is designed for generating structured layouts of dependency graphs, flowcharts, state machines, and other hierarchical structures.
Dagre also provides facilities for inspecting the order of graph elements during layout, aiding in debugging and verification of visual correctness.