d3-sankey
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
var version = "0.2.0"; export * from "../index"; export {version}; | ||
var version = "0.2.1"; export * from "../index"; export {version}; |
@@ -7,11 +7,9 @@ (function (global, factory) { | ||
// Stolen from https://github.com/d3/d3-plugins/tree/master/sankey | ||
function sankey() { | ||
var sankey = {}, | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
@@ -67,9 +65,12 @@ sankey.nodeWidth = function(_) { | ||
var x0 = d.source.x + d.source.dx, | ||
x1 = d.target.x, | ||
xi = d3Interpolate.number(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; | ||
return "M" + x0 + "," + y0 + "C" + x2 + "," + y0 + " " + x3 + "," + y1 + " " + x1 + "," + y1; | ||
x1 = d.target.x, | ||
xi = d3Interpolate.number(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; | ||
return "M" + x0 + "," + y0 | ||
+ "C" + x2 + "," + y0 | ||
+ " " + x3 + "," + y1 | ||
+ " " + x1 + "," + y1; | ||
} | ||
@@ -95,3 +96,3 @@ | ||
var source = link.source, | ||
target = link.target; | ||
target = link.target; | ||
if (typeof source === "number") source = link.source = nodes[link.source]; | ||
@@ -120,4 +121,4 @@ if (typeof target === "number") target = link.target = nodes[link.target]; | ||
var remainingNodes = nodes, | ||
nextNodes, | ||
x = 0; | ||
nextNodes, | ||
x = 0; | ||
@@ -147,5 +148,3 @@ while (remainingNodes.length) { | ||
if (!node.targetLinks.length) { | ||
node.x = d3Arrays.min(node.sourceLinks, function(d) { | ||
return d.target.x; | ||
}) - 1; | ||
node.x = d3Arrays.min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
} | ||
@@ -171,10 +170,6 @@ }); | ||
var nodesByBreadth = d3Arrays.nest() | ||
.key(function(d) { | ||
return d.x; | ||
}) | ||
.sortKeys(d3Arrays.ascending) | ||
.entries(nodes) | ||
.map(function(d) { | ||
return d.values; | ||
}); | ||
.key(function(d) { return d.x; }) | ||
.sortKeys(d3Arrays.ascending) | ||
.entries(nodes) | ||
.map(function(d) { return d.values; }); | ||
@@ -241,6 +236,6 @@ // | ||
var node, | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
@@ -283,4 +278,3 @@ // Push any overlapping nodes down. | ||
nodes.forEach(function(node) { | ||
var sy = 0, | ||
ty = 0; | ||
var sy = 0, ty = 0; | ||
node.sourceLinks.forEach(function(link) { | ||
@@ -316,3 +310,3 @@ link.sy = sy; | ||
var version = "0.2.0"; | ||
var version = "0.2.1"; | ||
@@ -319,0 +313,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-arrays"),require("d3-interpolate")):"function"==typeof define&&define.amd?define("d3-sankey",["exports","d3-arrays","d3-interpolate"],t):t(n.d3_sankey={},n.d3_arrays,n.d3_interpolate)}(this,function(n,t,r){"use strict";function e(){function n(){l.forEach(function(n){n.sourceLinks=[],n.targetLinks=[]}),k.forEach(function(n){var t=n.source,r=n.target;"number"==typeof t&&(t=n.source=l[n.source]),"number"==typeof r&&(r=n.target=l[n.target]),t.sourceLinks.push(n),r.targetLinks.push(n)})}function e(){l.forEach(function(n){n.value=Math.max(t.sum(n.sourceLinks,s),t.sum(n.targetLinks,s))})}function u(){for(var n,t=l,r=0;t.length;)n=[],t.forEach(function(t){t.x=r,t.dx=g,t.sourceLinks.forEach(function(t){n.indexOf(t.target)<0&&n.push(t.target)})}),t=n,++r;o(r),c((d[0]-g)/(r-1))}function o(n){l.forEach(function(t){t.sourceLinks.length||(t.x=n-1)})}function c(n){l.forEach(function(t){t.x*=n})}function i(n){function r(){var n=t.min(i,function(n){return(d[1]-(n.length-1)*h)/t.sum(n,s)});i.forEach(function(t){t.forEach(function(t,r){t.y=r,t.dy=t.value*n})}),k.forEach(function(t){t.dy=t.value*n})}function e(n){function r(n){return a(n.source)*n.value}i.forEach(function(e,u){e.forEach(function(e){if(e.targetLinks.length){var u=t.sum(e.targetLinks,r)/t.sum(e.targetLinks,s);e.y+=(u-a(e))*n}})})}function u(n){function r(n){return a(n.target)*n.value}i.slice().reverse().forEach(function(e){e.forEach(function(e){if(e.sourceLinks.length){var u=t.sum(e.sourceLinks,r)/t.sum(e.sourceLinks,s);e.y+=(u-a(e))*n}})})}function o(){i.forEach(function(n){var t,r,e,u=0,o=n.length;for(n.sort(c),e=0;o>e;++e)t=n[e],r=u-t.y,r>0&&(t.y+=r),u=t.y+t.dy+h;if(r=u-h-d[1],r>0)for(u=t.y-=r,e=o-2;e>=0;--e)t=n[e],r=t.y+t.dy+h-u,r>0&&(t.y-=r),u=t.y})}function c(n,t){return n.y-t.y}var i=t.nest().key(function(n){return n.x}).sortKeys(t.ascending).entries(l).map(function(n){return n.values});r(),o();for(var f=1;n>0;--n)u(f*=.99),o(),e(f),o()}function f(){function n(n,t){return n.source.y-t.source.y}function t(n,t){return n.target.y-t.target.y}l.forEach(function(r){r.sourceLinks.sort(t),r.targetLinks.sort(n)}),l.forEach(function(n){var t=0,r=0;n.sourceLinks.forEach(function(n){n.sy=t,t+=n.dy}),n.targetLinks.forEach(function(n){n.ty=r,r+=n.dy})})}function a(n){return n.y+n.dy/2}function s(n){return n.value}var y={},g=24,h=8,d=[1,1],l=[],k=[];return y.nodeWidth=function(n){return arguments.length?(g=+n,y):g},y.nodePadding=function(n){return arguments.length?(h=+n,y):h},y.nodes=function(n){return arguments.length?(l=n,y):l},y.links=function(n){return arguments.length?(k=n,y):k},y.size=function(n){return arguments.length?(d=n,y):d},y.layout=function(t){return n(),e(),u(),i(t),f(),y},y.relayout=function(){return f(),y},y.link=function(){function n(n){var e=n.source.x+n.source.dx,u=n.target.x,o=r.number(e,u),c=o(t),i=o(1-t),f=n.source.y+n.sy+n.dy/2,a=n.target.y+n.ty+n.dy/2;return"M"+e+","+f+"C"+c+","+f+" "+i+","+a+" "+u+","+a}var t=.5;return n.curvature=function(r){return arguments.length?(t=+r,n):t},n},y}var u="0.2.0";n.version=u,n.sankey=e}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-arrays"),require("d3-interpolate")):"function"==typeof define&&define.amd?define("d3-sankey",["exports","d3-arrays","d3-interpolate"],t):t(n.d3_sankey={},n.d3_arrays,n.d3_interpolate)}(this,function(n,t,r){"use strict";function e(){function n(){l.forEach(function(n){n.sourceLinks=[],n.targetLinks=[]}),k.forEach(function(n){var t=n.source,r=n.target;"number"==typeof t&&(t=n.source=l[n.source]),"number"==typeof r&&(r=n.target=l[n.target]),t.sourceLinks.push(n),r.targetLinks.push(n)})}function e(){l.forEach(function(n){n.value=Math.max(t.sum(n.sourceLinks,s),t.sum(n.targetLinks,s))})}function u(){for(var n,t=l,r=0;t.length;)n=[],t.forEach(function(t){t.x=r,t.dx=g,t.sourceLinks.forEach(function(t){n.indexOf(t.target)<0&&n.push(t.target)})}),t=n,++r;o(r),c((d[0]-g)/(r-1))}function o(n){l.forEach(function(t){t.sourceLinks.length||(t.x=n-1)})}function c(n){l.forEach(function(t){t.x*=n})}function i(n){function r(){var n=t.min(i,function(n){return(d[1]-(n.length-1)*h)/t.sum(n,s)});i.forEach(function(t){t.forEach(function(t,r){t.y=r,t.dy=t.value*n})}),k.forEach(function(t){t.dy=t.value*n})}function e(n){function r(n){return a(n.source)*n.value}i.forEach(function(e,u){e.forEach(function(e){if(e.targetLinks.length){var u=t.sum(e.targetLinks,r)/t.sum(e.targetLinks,s);e.y+=(u-a(e))*n}})})}function u(n){function r(n){return a(n.target)*n.value}i.slice().reverse().forEach(function(e){e.forEach(function(e){if(e.sourceLinks.length){var u=t.sum(e.sourceLinks,r)/t.sum(e.sourceLinks,s);e.y+=(u-a(e))*n}})})}function o(){i.forEach(function(n){var t,r,e,u=0,o=n.length;for(n.sort(c),e=0;o>e;++e)t=n[e],r=u-t.y,r>0&&(t.y+=r),u=t.y+t.dy+h;if(r=u-h-d[1],r>0)for(u=t.y-=r,e=o-2;e>=0;--e)t=n[e],r=t.y+t.dy+h-u,r>0&&(t.y-=r),u=t.y})}function c(n,t){return n.y-t.y}var i=t.nest().key(function(n){return n.x}).sortKeys(t.ascending).entries(l).map(function(n){return n.values});r(),o();for(var f=1;n>0;--n)u(f*=.99),o(),e(f),o()}function f(){function n(n,t){return n.source.y-t.source.y}function t(n,t){return n.target.y-t.target.y}l.forEach(function(r){r.sourceLinks.sort(t),r.targetLinks.sort(n)}),l.forEach(function(n){var t=0,r=0;n.sourceLinks.forEach(function(n){n.sy=t,t+=n.dy}),n.targetLinks.forEach(function(n){n.ty=r,r+=n.dy})})}function a(n){return n.y+n.dy/2}function s(n){return n.value}var y={},g=24,h=8,d=[1,1],l=[],k=[];return y.nodeWidth=function(n){return arguments.length?(g=+n,y):g},y.nodePadding=function(n){return arguments.length?(h=+n,y):h},y.nodes=function(n){return arguments.length?(l=n,y):l},y.links=function(n){return arguments.length?(k=n,y):k},y.size=function(n){return arguments.length?(d=n,y):d},y.layout=function(t){return n(),e(),u(),i(t),f(),y},y.relayout=function(){return f(),y},y.link=function(){function n(n){var e=n.source.x+n.source.dx,u=n.target.x,o=r.number(e,u),c=o(t),i=o(1-t),f=n.source.y+n.sy+n.dy/2,a=n.target.y+n.ty+n.dy/2;return"M"+e+","+f+"C"+c+","+f+" "+i+","+a+" "+u+","+a}var t=.5;return n.curvature=function(r){return arguments.length?(t=+r,n):t},n},y}var u="0.2.1";n.version=u,n.sankey=e}); |
{ | ||
"name": "d3-sankey", | ||
"version": "0.2.0", | ||
"description": "D3 4.0 implementation of the Sankey plugin", | ||
"version": "0.2.1", | ||
"description": "Visualize flow between nodes in a directed acyclic network.", | ||
"keywords": [ | ||
@@ -22,12 +22,12 @@ "d3", | ||
}, | ||
"dependencies": { | ||
"d3-arrays": "~0.4.0", | ||
"d3-interpolate": "~0.2.0" | ||
}, | ||
"devDependencies": { | ||
"faucet": "^0.0.1", | ||
"faucet": "0.0", | ||
"rollup": "^0.21.1", | ||
"tape": "^4.2.2", | ||
"uglify-js": "^2.6.1" | ||
}, | ||
"dependencies": { | ||
"d3-arrays": "^0.4.0", | ||
"d3-interpolate": "^0.2.0" | ||
"tape": "4", | ||
"uglify-js": "2" | ||
} | ||
} |
@@ -12,3 +12,3 @@ # d3-sankey | ||
The dependencies are listed in the [package.json](https://gist.github.com/xaranke/9ada4c74a87b57ae7308#file-package-json) file, so all you need to do to recreate the example is [clone](http://blockbuilder.org/xaranke/9ada4c74a87b57ae7308) or download the block, run `npm install` and then [smush](https://github.com/xaranke/d3smush) your JS together with `d3smush`. | ||
Clone or download the block, then run `npm install` and `npm run build` to create `d3.min.js`. | ||
@@ -15,0 +15,0 @@ ## API Reference |
@@ -1,22 +0,11 @@ | ||
import { | ||
sum, | ||
nest, | ||
ascending, | ||
min | ||
} | ||
from 'd3-arrays'; | ||
import {ascending, min, nest, sum} from "d3-arrays"; | ||
import {number} from "d3-interpolate"; | ||
import { | ||
number | ||
} from 'd3-interpolate'; | ||
// Stolen from https://github.com/d3/d3-plugins/tree/master/sankey | ||
export default function() { | ||
var sankey = {}, | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
@@ -72,9 +61,12 @@ sankey.nodeWidth = function(_) { | ||
var x0 = d.source.x + d.source.dx, | ||
x1 = d.target.x, | ||
xi = number(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; | ||
return "M" + x0 + "," + y0 + "C" + x2 + "," + y0 + " " + x3 + "," + y1 + " " + x1 + "," + y1; | ||
x1 = d.target.x, | ||
xi = number(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; | ||
return "M" + x0 + "," + y0 | ||
+ "C" + x2 + "," + y0 | ||
+ " " + x3 + "," + y1 | ||
+ " " + x1 + "," + y1; | ||
} | ||
@@ -100,3 +92,3 @@ | ||
var source = link.source, | ||
target = link.target; | ||
target = link.target; | ||
if (typeof source === "number") source = link.source = nodes[link.source]; | ||
@@ -125,4 +117,4 @@ if (typeof target === "number") target = link.target = nodes[link.target]; | ||
var remainingNodes = nodes, | ||
nextNodes, | ||
x = 0; | ||
nextNodes, | ||
x = 0; | ||
@@ -152,5 +144,3 @@ while (remainingNodes.length) { | ||
if (!node.targetLinks.length) { | ||
node.x = min(node.sourceLinks, function(d) { | ||
return d.target.x; | ||
}) - 1; | ||
node.x = min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
} | ||
@@ -176,10 +166,6 @@ }); | ||
var nodesByBreadth = nest() | ||
.key(function(d) { | ||
return d.x; | ||
}) | ||
.sortKeys(ascending) | ||
.entries(nodes) | ||
.map(function(d) { | ||
return d.values; | ||
}); | ||
.key(function(d) { return d.x; }) | ||
.sortKeys(ascending) | ||
.entries(nodes) | ||
.map(function(d) { return d.values; }); | ||
@@ -246,6 +232,6 @@ // | ||
var node, | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
@@ -288,4 +274,3 @@ // Push any overlapping nodes down. | ||
nodes.forEach(function(node) { | ||
var sy = 0, | ||
ty = 0; | ||
var sy = 0, ty = 0; | ||
node.sourceLinks.forEach(function(link) { | ||
@@ -292,0 +277,0 @@ link.sy = sy; |
Sorry, the diff of this file is not supported yet
24668
521
Updatedd3-arrays@~0.4.0
Updatedd3-interpolate@~0.2.0