d3-sankey
d3-sankey copied to clipboard
nodeAlign not aligning the nodes properly
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.
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 }.