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.
functionexampleLayering<Nextends { y: number }, L>(dag: Graph<N, L>, sep: Separation<N, L>): number { // determine span of ys letmin = Infinity; letmax = -Infinity; for (constnodeofdag) { consty = node.y = node.data.y; min = Math.min(min, y - sep(undefined, node)); max = Math.max(max, y + sep(node, undefined)); } // assign ys for (constnodeofdag) { node.y = -= min; } returnmax - min; }
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 respectssep
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.