Interface Layering<NodeDatum, LinkDatum>

An operator for layering a graph.

Layering operators take a graph and a Separation function sep, and must assign every node in the graph a y-coordinate that respects sep along edges in the graph. In general the coordinates should try to respect the same order as returned by Graph#topological but it's not required. This should also return the total "height" of the layout, such that all nodes coordinates + sep(node, undefined) is less than height.

Example

The built-in layering operators should cover the majority of use cases, but you may need to implement your own for custom layouts.

We illistrate implementing a custom layering operator where the nodes are already assigned their y-coordinate in their data. Note that this doesn't respect sep and an appropriate layering should, so this won't work as is.

function exampleLayering<N extends { y: number }, L>(dag: Graph<N, L>, sep: Separation<N, L>): number {
// determine span of ys
let min = Infinity;
let max = -Infinity;
for (const node of dag) {
const y = node.y = node.data.y;
min = Math.min(min, y - sep(undefined, node));
max = Math.max(max, y + sep(node, undefined));
}
// assign ys
for (const node of dag) {
node.y = -= min;
}
return max - min;
}

Type Parameters

  • in NodeDatum = never

  • in LinkDatum = never

Hierarchy

  • layer a graph

    After calling this, every node should have a y coordinate that satisfies sep.

    Type Parameters

    • N

    • L

    Parameters

    • graph: Graph<N, L>

      the graph to layer

    • sep: Separation<N, L>

      the minimum separation between nodes

    Returns number

    height - the height after layering

Generated using TypeDoc