in packages-ext/recoil-devtools/src/utils/sankey/SankeyGraphLayout.js [283:312]
function collisionDetection() {
for (const depth of depths) {
sortAsc(depth, n => n.position);
// Push overlapping nodes down
let position = 0;
for (const node of depth) {
const delta = position - node.position;
if (delta > 0) {
node.position += delta;
}
position = node.position + node.value + depth.padding;
}
// If they extend past the edge, then push some nodes back
const lastNode = depth[depth.length - 1];
if (lastNode.position + lastNode.value > maxPosition) {
position = maxPosition;
for (const node of [...depth].reverse()) {
const delta = node.position + node.value - position;
if (delta > 0) {
node.position -= delta;
} else {
break;
}
position = node.position - depth.padding;
}
}
}
}