From e70b7724ecd2c6b8a70e0920f8a482c1244c9754 Mon Sep 17 00:00:00 2001 From: James Addison Date: Mon, 14 Sep 2020 10:45:36 +0100 Subject: [PATCH] Bounds checking: check both lower and upper bounds during node collision resolution --- src/sankey.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sankey.js b/src/sankey.js index 56ad642..a2a3574 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -299,7 +299,7 @@ export default function Sankey() { // Push any overlapping nodes down. function resolveCollisionsTopToBottom(nodes, y, i, alpha) { - for (; i < nodes.length; ++i) { + for (; i >= 0 && i < nodes.length; ++i) { const node = nodes[i]; const dy = (y - node.y0) * alpha; if (dy > 1e-6) node.y0 += dy, node.y1 += dy; @@ -309,7 +309,7 @@ export default function Sankey() { // Push any overlapping nodes up. function resolveCollisionsBottomToTop(nodes, y, i, alpha) { - for (; i >= 0; --i) { + for (; i >= 0 && i < nodes.length; --i) { const node = nodes[i]; const dy = (node.y1 - y) * alpha; if (dy > 1e-6) node.y0 -= dy, node.y1 -= dy;