sankeyCenter function
Centers the node based on its incoming/outgoing relationships
- If the node has incoming links (i.e. it is a target), its column is set to
its
depth
. - Otherwise, if it has outgoing links, its column is set to one less than the minimum depth of its target nodes
- If neither is available, the node is placed in column 0
This function mimics d3‑sankey's "center" alignment
Implementation
int sankeyCenter(SankeyNode node, int n) {
if (node.targetLinks.isNotEmpty) return node.depth;
if (node.sourceLinks.isNotEmpty)
return (node.sourceLinks
.map((link) => (link.target as SankeyNode).depth)
.reduce(min)) -
1;
return 0;
}