Interface Coord<NodeDatum, LinkDatum>

an operator that assigns coordinates to layered SugiNodes

This function must assign each node an x coordinate, and return the width of the layout. The x coordinates should satisfy the SugiSeparation, and all be between zero and the returned width.

Example

In order to illustrate what it might look like, below we demonstrate a coordinate operator that assigns an x attached to the nodes themselves. If the node is a dummy node (e.g. a point on an edge between two nodes), then instead we average the coordinate. Note that this isn't compliant since it might not respect sep, and is therefore only an illustration.

customCoord<N extends { x: number }, L>(layers: SugiNode<N, L>[][], sep: SugiSeparation<N, L>): number {
// determine span of xs
let min = Infinity;
let max = -Infinity;
for (const layer of layers) {
for (const node of layer) {
const { data } = node;
const x = node.x = data.role === "node" ? data.node.data.x : (data.link.source.data.x + data.link.target.data.x) / 2;
min = Math.min(min, x - sep(undefined, node));
max = Math.max(max, x + sep(node, undefined));
}
}
// assign xs
for (const node of dag) {
node.x = -= min;
}
return max - min;
}

Type Parameters

  • in NodeDatum = never

  • in LinkDatum = never

Hierarchy

  • assign coordinates to a layered graph

    Type Parameters

    • N

    • L

    Parameters

    • layers: SugiNode<N, L>[][]

      a layered graph of sugiyama nodes

    • sep: SugiSeparation<N, L>

      how much horizontal separation should exist between nodes

    Returns number

    width - the total width of the layout

Generated using TypeDoc