d3 / d3-sankey

Visualize flow between nodes in a directed acyclic network.

Home Page:https://observablehq.com/collection/@d3/d3-sankey

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nodeAlign not aligning the nodes properly

jacksonngoo opened this issue · comments

I am trying to fix the nodes' position in my sankey diagram by using a field called position.

Then I will call the nodeAlign with custom function where it return the position.

sankey.nodeAlign(
        (node) => {
            return node.position;
        }
    );

However the diagram does not render the expected result.

Please refer to the below diagram.

image

I've run into similar issues.

As of 0.12.3, this is due how computeNodeDepths calculates depths for nodes and how computeNodeLayers depends on assumptions made in those depth calculations.

In computeNodeDepths, node depth calculations are done by traversing links. In your expected example, D is a calculated depth of 0, E of 1, F of 2 much like { A, B, C }. It doesn't have any facility for providing an override or alternate.

In computeNodeLayers, the calculation of the max number of columns is done using the max depth calculated in computeNodeDepths and is further constrained to transparently through a min of that max column count and your alignment result, resulting in an upper bound of its computed columns regardless of what you say - the exact behavior you see with Result { E, F }.