d3-dag
    Preparing search index...

    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.

    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 (View Summary)