From f83f214305f5f77d6ad3b0f0cbef298d41b48fee Mon Sep 17 00:00:00 2001 From: Mattia Gheda Date: Tue, 22 Jan 2013 18:36:52 -0500 Subject: [PATCH 1/2] Sankey Plugin: Improved drawing of links As seen in http://bl.ocks.org/d/4599519/ using a thick line to draw links between blocks can lead to artifacts this patch uses a set of 4 lines to draw the connection between blocks, see http://bl.ocks.org/d/4599792/ --- sankey/sankey.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sankey/sankey.js b/sankey/sankey.js index c3bc59f..c359db1 100644 --- a/sankey/sankey.js +++ b/sankey/sankey.js @@ -59,12 +59,20 @@ d3.sankey = function() { xi = d3.interpolateNumber(x0, x1), x2 = xi(curvature), x3 = xi(1 - curvature), - y0 = d.source.y + d.sy + d.dy / 2, - y1 = d.target.y + d.ty + d.dy / 2; + y0 = d.source.y + d.sy, + y1 = d.target.y + d.ty, + y2 = y1 + d.dy, + y3 = y0 + d.dy; + return "M" + x0 + "," + y0 + "C" + x2 + "," + y0 + " " + x3 + "," + y1 - + " " + x1 + "," + y1; + + " " + x1 + "," + y1 + + " L" + x1 + "," + y2 + + "C" + x3+ "," + y2 + + " " + x2 + "," + y3 + + " " + x0 + "," + y3 + + "Z"; } link.curvature = function(_) { From c94e5149fc5463c8690fc64f25cfacd542737457 Mon Sep 17 00:00:00 2001 From: Caleb Morse Date: Mon, 4 Feb 2013 17:14:52 -0700 Subject: [PATCH 2/2] Update sankey/sankey.js --- sankey/sankey.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sankey/sankey.js b/sankey/sankey.js index c359db1..a67815e 100644 --- a/sankey/sankey.js +++ b/sankey/sankey.js @@ -59,6 +59,8 @@ d3.sankey = function() { xi = d3.interpolateNumber(x0, x1), x2 = xi(curvature), x3 = xi(1 - curvature), + x4 = x3 + ((d.dy < 15) ? ((d.source.y < d.target.y) ? -1 * d.dy : d.dy) : 0), + x5 = x2 + ((d.dy < 15) ? ((d.source.y < d.target.y) ? -1 * d.dy : d.dy) : 0), y0 = d.source.y + d.sy, y1 = d.target.y + d.ty, y2 = y1 + d.dy, @@ -68,9 +70,9 @@ d3.sankey = function() { + "C" + x2 + "," + y0 + " " + x3 + "," + y1 + " " + x1 + "," + y1 - + " L" + x1 + "," + y2 - + "C" + x3+ "," + y2 - + " " + x2 + "," + y3 + + "v" + d.dy + + "C" + x4 + "," + y2 + + " " + x5 + "," + y3 + " " + x0 + "," + y3 + "Z"; }