Skip to content

Commit 0048f2a

Browse files
authored
Merge pull request #1 from plotly/stable-sorting-links
Stable sorting links for better parallel edge handling
2 parents c343f2b + 4574a23 commit 0048f2a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/sankey.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ export default function() {
8787
node.sourceLinks = [];
8888
node.targetLinks = [];
8989
});
90-
links.forEach(function(link) {
90+
links.forEach(function(link, i) {
9191
var source = link.source,
9292
target = link.target;
9393
if (typeof source === "number") source = link.source = nodes[link.source];
9494
if (typeof target === "number") target = link.target = nodes[link.target];
95+
link.originalIndex = i;
9596
source.sourceLinks.push(link);
9697
target.targetLinks.push(link);
9798
});
@@ -278,11 +279,11 @@ export default function() {
278279
});
279280

280281
function ascendingSourceDepth(a, b) {
281-
return a.source.y - b.source.y;
282+
return (a.source.y - b.source.y) || (a.originalIndex - b.originalIndex);
282283
}
283284

284285
function ascendingTargetDepth(a, b) {
285-
return a.target.y - b.target.y;
286+
return (a.target.y - b.target.y) || (a.originalIndex - b.originalIndex);
286287
}
287288
}
288289

0 commit comments

Comments
 (0)