d3-sankey icon indicating copy to clipboard operation
d3-sankey copied to clipboard

nodeAlign not aligning the nodes properly

Open jacksonngoo opened this issue 3 years ago • 1 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

jacksonngoo avatar Dec 24 '21 02:12 jacksonngoo

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 }.

jeremy-sylvis avatar Jan 06 '23 02:01 jeremy-sylvis