in packages-ext/recoil-devtools/src/utils/sankey/SankeyGraphLayout.js [136:169]
function flowLayoutNodeDepths<N, L>(
graph: Graph<N, L>,
layoutOptions: FlowLayoutOptions,
): [number, number] {
const visibleNodes = graph.nodes.filter(node => node.visible);
// Compute the depth of each node
let remainingNodes = visibleNodes;
let depth = 0;
while (remainingNodes.length) {
const nextNodes = [];
for (const node of remainingNodes) {
node.depth = depth;
for (const targetLink of node.targetLinks.filter(l => !l.backedge)) {
if (!targetLink.fadeTarget && targetLink.target != null) {
nextNodes.push(targetLink.target);
}
}
}
remainingNodes = nextNodes;
depth++;
}
const maxDepth = depth - 1;
// Right align nodes with no targets if requested
if (layoutOptions.nodeAlignment === 'both') {
for (const node of visibleNodes) {
if (!node.targetLinks.length) {
node.depth = maxDepth;
}
}
}
return [0, maxDepth];
}