From 5f02b21ef041d2e575b9f0714fe12203c78f50ca Mon Sep 17 00:00:00 2001 From: George Madrid Date: Fri, 30 Aug 2013 11:01:51 -0400 Subject: [PATCH] foo --- sankey/sankey.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sankey/sankey.js b/sankey/sankey.js index c3bc59f..528e3dc 100644 --- a/sankey/sankey.js +++ b/sankey/sankey.js @@ -257,22 +257,31 @@ d3.sankey = function() { function computeLinkDepths() { nodes.forEach(function(node) { node.sourceLinks.sort(ascendingTargetDepth); - node.targetLinks.sort(ascendingSourceDepth); }); nodes.forEach(function(node) { - var sy = 0, ty = 0; + var sy = 0; node.sourceLinks.forEach(function(link) { link.sy = sy; sy += link.dy; }); + }); + nodes.forEach(function(node) { + node.targetLinks.sort(descendingLinkSlope); + }); + nodes.forEach(function(node) { + var ty = 0; node.targetLinks.forEach(function(link) { link.ty = ty; ty += link.dy; }); }); - function ascendingSourceDepth(a, b) { - return a.source.y - b.source.y; + function descendingLinkSlope(a, b) { + function slope(l) { + return (l.target.y - (l.source.y + l.sy)) / + (l.target.x - l.source.x); + } + return slope(b) - slope(a); } function ascendingTargetDepth(a, b) {