Skip to content

Commit

Permalink
Merge pull request d3#1 from plotly/stable-sorting-links
Browse files Browse the repository at this point in the history
Stable sorting links for better parallel edge handling
  • Loading branch information
monfera authored Apr 12, 2017
2 parents c343f2b + 4574a23 commit 0048f2a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 0048f2a

Please sign in to comment.