From 4574a236bc33ec6e0c4ba819f5dd73cbbf464877 Mon Sep 17 00:00:00 2001 From: Robert Monfera Date: Wed, 1 Mar 2017 10:33:01 +0100 Subject: [PATCH] stable sorting links for better parallel edge handling --- src/sankey.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sankey.js b/src/sankey.js index b47e724..11a6c30 100644 --- a/src/sankey.js +++ b/src/sankey.js @@ -87,11 +87,12 @@ export default function() { node.sourceLinks = []; node.targetLinks = []; }); - links.forEach(function(link) { + links.forEach(function(link, i) { var source = link.source, target = link.target; if (typeof source === "number") source = link.source = nodes[link.source]; if (typeof target === "number") target = link.target = nodes[link.target]; + link.originalIndex = i; source.sourceLinks.push(link); target.targetLinks.push(link); }); @@ -278,11 +279,11 @@ export default function() { }); function ascendingSourceDepth(a, b) { - return a.source.y - b.source.y; + return (a.source.y - b.source.y) || (a.originalIndex - b.originalIndex); } function ascendingTargetDepth(a, b) { - return a.target.y - b.target.y; + return (a.target.y - b.target.y) || (a.originalIndex - b.originalIndex); } }