d3-dag
Version:
Layout algorithms for visualizing directed acylic graphs.
14 lines (11 loc) • 398 B
JavaScript
// Assign a value for the layer of each node that is a topological ordering
export default function() {
// TODO Add option to optimally assign layer to minimize number of dummy
// nodes, similar to simplex. This might be combinatoric.
function layeringTopological(dag) {
let layer = 0;
dag.eachBefore((n) => (n.layer = layer++));
return dag;
}
return layeringTopological;
}