d3-sankey
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,307 +1,307 @@ | ||
// https://github.com/d3/d3-sankey Version 0.3.0. Copyright 2016 Mike Bostock. | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-arrays'), require('d3-interpolate')) : | ||
typeof define === 'function' && define.amd ? define('d3-sankey', ['exports', 'd3-arrays', 'd3-interpolate'], factory) : | ||
factory((global.d3_sankey = {}),global.d3_arrays,global.d3_interpolate); | ||
}(this, function (exports,d3Arrays,d3Interpolate) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-collection'), require('d3-interpolate')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-interpolate'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Array,d3Collection,d3Interpolate) { 'use strict'; | ||
function sankey() { | ||
var sankey = {}, | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
function sankey() { | ||
var sankey = {}, | ||
nodeWidth = 24, | ||
nodePadding = 8, | ||
size = [1, 1], | ||
nodes = [], | ||
links = []; | ||
sankey.nodeWidth = function(_) { | ||
if (!arguments.length) return nodeWidth; | ||
nodeWidth = +_; | ||
return sankey; | ||
}; | ||
sankey.nodeWidth = function(_) { | ||
if (!arguments.length) return nodeWidth; | ||
nodeWidth = +_; | ||
return sankey; | ||
}; | ||
sankey.nodePadding = function(_) { | ||
if (!arguments.length) return nodePadding; | ||
nodePadding = +_; | ||
return sankey; | ||
}; | ||
sankey.nodePadding = function(_) { | ||
if (!arguments.length) return nodePadding; | ||
nodePadding = +_; | ||
return sankey; | ||
}; | ||
sankey.nodes = function(_) { | ||
if (!arguments.length) return nodes; | ||
nodes = _; | ||
return sankey; | ||
}; | ||
sankey.nodes = function(_) { | ||
if (!arguments.length) return nodes; | ||
nodes = _; | ||
return sankey; | ||
}; | ||
sankey.links = function(_) { | ||
if (!arguments.length) return links; | ||
links = _; | ||
return sankey; | ||
}; | ||
sankey.links = function(_) { | ||
if (!arguments.length) return links; | ||
links = _; | ||
return sankey; | ||
}; | ||
sankey.size = function(_) { | ||
if (!arguments.length) return size; | ||
size = _; | ||
return sankey; | ||
}; | ||
sankey.size = function(_) { | ||
if (!arguments.length) return size; | ||
size = _; | ||
return sankey; | ||
}; | ||
sankey.layout = function(iterations) { | ||
computeNodeLinks(); | ||
computeNodeValues(); | ||
computeNodeBreadths(); | ||
computeNodeDepths(iterations); | ||
computeLinkDepths(); | ||
return sankey; | ||
}; | ||
sankey.layout = function(iterations) { | ||
computeNodeLinks(); | ||
computeNodeValues(); | ||
computeNodeBreadths(); | ||
computeNodeDepths(iterations); | ||
computeLinkDepths(); | ||
return sankey; | ||
}; | ||
sankey.relayout = function() { | ||
computeLinkDepths(); | ||
return sankey; | ||
}; | ||
sankey.relayout = function() { | ||
computeLinkDepths(); | ||
return sankey; | ||
}; | ||
sankey.link = function() { | ||
var curvature = .5; | ||
sankey.link = function() { | ||
var curvature = .5; | ||
function link(d) { | ||
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; | ||
} | ||
function link(d) { | ||
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; | ||
} | ||
link.curvature = function(_) { | ||
if (!arguments.length) return curvature; | ||
curvature = +_; | ||
return link; | ||
}; | ||
link.curvature = function(_) { | ||
if (!arguments.length) return curvature; | ||
curvature = +_; | ||
return link; | ||
}; | ||
// Populate the sourceLinks and targetLinks for each node. | ||
// Also, if the source and target are not objects, assume they are indices. | ||
function computeNodeLinks() { | ||
nodes.forEach(function(node) { | ||
node.sourceLinks = []; | ||
node.targetLinks = []; | ||
}); | ||
links.forEach(function(link) { | ||
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]; | ||
source.sourceLinks.push(link); | ||
target.targetLinks.push(link); | ||
}); | ||
} | ||
return link; | ||
}; | ||
// Compute the value (size) of each node by summing the associated links. | ||
function computeNodeValues() { | ||
nodes.forEach(function(node) { | ||
node.value = Math.max( | ||
d3Arrays.sum(node.sourceLinks, value), | ||
d3Arrays.sum(node.targetLinks, value) | ||
); | ||
// Populate the sourceLinks and targetLinks for each node. | ||
// Also, if the source and target are not objects, assume they are indices. | ||
function computeNodeLinks() { | ||
nodes.forEach(function(node) { | ||
node.sourceLinks = []; | ||
node.targetLinks = []; | ||
}); | ||
links.forEach(function(link) { | ||
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]; | ||
source.sourceLinks.push(link); | ||
target.targetLinks.push(link); | ||
}); | ||
} | ||
// Compute the value (size) of each node by summing the associated links. | ||
function computeNodeValues() { | ||
nodes.forEach(function(node) { | ||
node.value = Math.max( | ||
d3Array.sum(node.sourceLinks, value), | ||
d3Array.sum(node.targetLinks, value) | ||
); | ||
}); | ||
} | ||
// Iteratively assign the breadth (x-position) for each node. | ||
// Nodes are assigned the maximum breadth of incoming neighbors plus one; | ||
// nodes with no incoming links are assigned breadth zero, while | ||
// nodes with no outgoing links are assigned the maximum breadth. | ||
function computeNodeBreadths() { | ||
var remainingNodes = nodes, | ||
nextNodes, | ||
x = 0; | ||
while (remainingNodes.length) { | ||
nextNodes = []; | ||
remainingNodes.forEach(function(node) { | ||
node.x = x; | ||
node.dx = nodeWidth; | ||
node.sourceLinks.forEach(function(link) { | ||
if (nextNodes.indexOf(link.target) < 0) { | ||
nextNodes.push(link.target); | ||
} | ||
}); | ||
}); | ||
remainingNodes = nextNodes; | ||
++x; | ||
} | ||
// Iteratively assign the breadth (x-position) for each node. | ||
// Nodes are assigned the maximum breadth of incoming neighbors plus one; | ||
// nodes with no incoming links are assigned breadth zero, while | ||
// nodes with no outgoing links are assigned the maximum breadth. | ||
function computeNodeBreadths() { | ||
var remainingNodes = nodes, | ||
nextNodes, | ||
x = 0; | ||
// | ||
moveSinksRight(x); | ||
scaleNodeBreadths((size[0] - nodeWidth) / (x - 1)); | ||
} | ||
while (remainingNodes.length) { | ||
nextNodes = []; | ||
remainingNodes.forEach(function(node) { | ||
node.x = x; | ||
node.dx = nodeWidth; | ||
node.sourceLinks.forEach(function(link) { | ||
if (nextNodes.indexOf(link.target) < 0) { | ||
nextNodes.push(link.target); | ||
} | ||
}); | ||
}); | ||
remainingNodes = nextNodes; | ||
++x; | ||
// function moveSourcesRight() { | ||
// nodes.forEach(function(node) { | ||
// if (!node.targetLinks.length) { | ||
// node.x = min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
// } | ||
// }); | ||
// } | ||
function moveSinksRight(x) { | ||
nodes.forEach(function(node) { | ||
if (!node.sourceLinks.length) { | ||
node.x = x - 1; | ||
} | ||
}); | ||
} | ||
// | ||
moveSinksRight(x); | ||
scaleNodeBreadths((size[0] - nodeWidth) / (x - 1)); | ||
function scaleNodeBreadths(kx) { | ||
nodes.forEach(function(node) { | ||
node.x *= kx; | ||
}); | ||
} | ||
function computeNodeDepths(iterations) { | ||
var nodesByBreadth = d3Collection.nest() | ||
.key(function(d) { return d.x; }) | ||
.sortKeys(d3Array.ascending) | ||
.entries(nodes) | ||
.map(function(d) { return d.values; }); | ||
// | ||
initializeNodeDepth(); | ||
resolveCollisions(); | ||
for (var alpha = 1; iterations > 0; --iterations) { | ||
relaxRightToLeft(alpha *= .99); | ||
resolveCollisions(); | ||
relaxLeftToRight(alpha); | ||
resolveCollisions(); | ||
} | ||
function moveSourcesRight() { | ||
nodes.forEach(function(node) { | ||
if (!node.targetLinks.length) { | ||
node.x = d3Arrays.min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
} | ||
function initializeNodeDepth() { | ||
var ky = d3Array.min(nodesByBreadth, function(nodes) { | ||
return (size[1] - (nodes.length - 1) * nodePadding) / d3Array.sum(nodes, value); | ||
}); | ||
} | ||
function moveSinksRight(x) { | ||
nodes.forEach(function(node) { | ||
if (!node.sourceLinks.length) { | ||
node.x = x - 1; | ||
} | ||
nodesByBreadth.forEach(function(nodes) { | ||
nodes.forEach(function(node, i) { | ||
node.y = i; | ||
node.dy = node.value * ky; | ||
}); | ||
}); | ||
} | ||
function scaleNodeBreadths(kx) { | ||
nodes.forEach(function(node) { | ||
node.x *= kx; | ||
links.forEach(function(link) { | ||
link.dy = link.value * ky; | ||
}); | ||
} | ||
function computeNodeDepths(iterations) { | ||
var nodesByBreadth = d3Arrays.nest() | ||
.key(function(d) { return d.x; }) | ||
.sortKeys(d3Arrays.ascending) | ||
.entries(nodes) | ||
.map(function(d) { return d.values; }); | ||
// | ||
initializeNodeDepth(); | ||
resolveCollisions(); | ||
for (var alpha = 1; iterations > 0; --iterations) { | ||
relaxRightToLeft(alpha *= .99); | ||
resolveCollisions(); | ||
relaxLeftToRight(alpha); | ||
resolveCollisions(); | ||
} | ||
function initializeNodeDepth() { | ||
var ky = d3Arrays.min(nodesByBreadth, function(nodes) { | ||
return (size[1] - (nodes.length - 1) * nodePadding) / d3Arrays.sum(nodes, value); | ||
function relaxLeftToRight(alpha) { | ||
nodesByBreadth.forEach(function(nodes) { | ||
nodes.forEach(function(node) { | ||
if (node.targetLinks.length) { | ||
var y = d3Array.sum(node.targetLinks, weightedSource) / d3Array.sum(node.targetLinks, value); | ||
node.y += (y - center(node)) * alpha; | ||
} | ||
}); | ||
}); | ||
nodesByBreadth.forEach(function(nodes) { | ||
nodes.forEach(function(node, i) { | ||
node.y = i; | ||
node.dy = node.value * ky; | ||
}); | ||
}); | ||
links.forEach(function(link) { | ||
link.dy = link.value * ky; | ||
}); | ||
function weightedSource(link) { | ||
return center(link.source) * link.value; | ||
} | ||
} | ||
function relaxLeftToRight(alpha) { | ||
nodesByBreadth.forEach(function(nodes, breadth) { | ||
nodes.forEach(function(node) { | ||
if (node.targetLinks.length) { | ||
var y = d3Arrays.sum(node.targetLinks, weightedSource) / d3Arrays.sum(node.targetLinks, value); | ||
node.y += (y - center(node)) * alpha; | ||
} | ||
}); | ||
function relaxRightToLeft(alpha) { | ||
nodesByBreadth.slice().reverse().forEach(function(nodes) { | ||
nodes.forEach(function(node) { | ||
if (node.sourceLinks.length) { | ||
var y = d3Array.sum(node.sourceLinks, weightedTarget) / d3Array.sum(node.sourceLinks, value); | ||
node.y += (y - center(node)) * alpha; | ||
} | ||
}); | ||
}); | ||
function weightedSource(link) { | ||
return center(link.source) * link.value; | ||
} | ||
function weightedTarget(link) { | ||
return center(link.target) * link.value; | ||
} | ||
} | ||
function relaxRightToLeft(alpha) { | ||
nodesByBreadth.slice().reverse().forEach(function(nodes) { | ||
nodes.forEach(function(node) { | ||
if (node.sourceLinks.length) { | ||
var y = d3Arrays.sum(node.sourceLinks, weightedTarget) / d3Arrays.sum(node.sourceLinks, value); | ||
node.y += (y - center(node)) * alpha; | ||
} | ||
}); | ||
}); | ||
function resolveCollisions() { | ||
nodesByBreadth.forEach(function(nodes) { | ||
var node, | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
function weightedTarget(link) { | ||
return center(link.target) * link.value; | ||
// Push any overlapping nodes down. | ||
nodes.sort(ascendingDepth); | ||
for (i = 0; i < n; ++i) { | ||
node = nodes[i]; | ||
dy = y0 - node.y; | ||
if (dy > 0) node.y += dy; | ||
y0 = node.y + node.dy + nodePadding; | ||
} | ||
} | ||
function resolveCollisions() { | ||
nodesByBreadth.forEach(function(nodes) { | ||
var node, | ||
dy, | ||
y0 = 0, | ||
n = nodes.length, | ||
i; | ||
// If the bottommost node goes outside the bounds, push it back up. | ||
dy = y0 - nodePadding - size[1]; | ||
if (dy > 0) { | ||
y0 = node.y -= dy; | ||
// Push any overlapping nodes down. | ||
nodes.sort(ascendingDepth); | ||
for (i = 0; i < n; ++i) { | ||
// Push any overlapping nodes back up. | ||
for (i = n - 2; i >= 0; --i) { | ||
node = nodes[i]; | ||
dy = y0 - node.y; | ||
if (dy > 0) node.y += dy; | ||
y0 = node.y + node.dy + nodePadding; | ||
dy = node.y + node.dy + nodePadding - y0; | ||
if (dy > 0) node.y -= dy; | ||
y0 = node.y; | ||
} | ||
} | ||
}); | ||
} | ||
// If the bottommost node goes outside the bounds, push it back up. | ||
dy = y0 - nodePadding - size[1]; | ||
if (dy > 0) { | ||
y0 = node.y -= dy; | ||
// Push any overlapping nodes back up. | ||
for (i = n - 2; i >= 0; --i) { | ||
node = nodes[i]; | ||
dy = node.y + node.dy + nodePadding - y0; | ||
if (dy > 0) node.y -= dy; | ||
y0 = node.y; | ||
} | ||
} | ||
}); | ||
} | ||
function ascendingDepth(a, b) { | ||
return a.y - b.y; | ||
} | ||
function ascendingDepth(a, b) { | ||
return a.y - b.y; | ||
} | ||
} | ||
function computeLinkDepths() { | ||
nodes.forEach(function(node) { | ||
node.sourceLinks.sort(ascendingTargetDepth); | ||
node.targetLinks.sort(ascendingSourceDepth); | ||
function computeLinkDepths() { | ||
nodes.forEach(function(node) { | ||
node.sourceLinks.sort(ascendingTargetDepth); | ||
node.targetLinks.sort(ascendingSourceDepth); | ||
}); | ||
nodes.forEach(function(node) { | ||
var sy = 0, ty = 0; | ||
node.sourceLinks.forEach(function(link) { | ||
link.sy = sy; | ||
sy += link.dy; | ||
}); | ||
nodes.forEach(function(node) { | ||
var sy = 0, ty = 0; | ||
node.sourceLinks.forEach(function(link) { | ||
link.sy = sy; | ||
sy += link.dy; | ||
}); | ||
node.targetLinks.forEach(function(link) { | ||
link.ty = ty; | ||
ty += link.dy; | ||
}); | ||
node.targetLinks.forEach(function(link) { | ||
link.ty = ty; | ||
ty += link.dy; | ||
}); | ||
}); | ||
function ascendingSourceDepth(a, b) { | ||
return a.source.y - b.source.y; | ||
} | ||
function ascendingTargetDepth(a, b) { | ||
return a.target.y - b.target.y; | ||
} | ||
function ascendingSourceDepth(a, b) { | ||
return a.source.y - b.source.y; | ||
} | ||
function center(node) { | ||
return node.y + node.dy / 2; | ||
function ascendingTargetDepth(a, b) { | ||
return a.target.y - b.target.y; | ||
} | ||
} | ||
function value(link) { | ||
return link.value; | ||
} | ||
function center(node) { | ||
return node.y + node.dy / 2; | ||
} | ||
return sankey; | ||
}; | ||
function value(link) { | ||
return link.value; | ||
} | ||
var version = "0.2.1"; | ||
return sankey; | ||
} | ||
exports.version = version; | ||
exports.sankey = sankey; | ||
exports.sankey = sankey; | ||
})); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,2 @@ | ||
!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}); | ||
// https://github.com/d3/d3-sankey Version 0.3.0. Copyright 2016 Mike Bostock. | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-array"),require("d3-collection"),require("d3-interpolate")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-collection","d3-interpolate"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3)}(this,function(n,t,r,e){"use strict";function u(){function n(){k.forEach(function(n){n.sourceLinks=[],n.targetLinks=[]}),v.forEach(function(n){var t=n.source,r=n.target;"number"==typeof t&&(t=n.source=k[n.source]),"number"==typeof r&&(r=n.target=k[n.target]),t.sourceLinks.push(n),r.targetLinks.push(n)})}function u(){k.forEach(function(n){n.value=Math.max(t.sum(n.sourceLinks,y),t.sum(n.targetLinks,y))})}function o(){for(var n,t=k,r=0;t.length;)n=[],t.forEach(function(t){t.x=r,t.dx=h,t.sourceLinks.forEach(function(t){n.indexOf(t.target)<0&&n.push(t.target)})}),t=n,++r;c(r),i((g[0]-h)/(r-1))}function c(n){k.forEach(function(t){t.sourceLinks.length||(t.x=n-1)})}function i(n){k.forEach(function(t){t.x*=n})}function f(n){function e(){var n=t.min(f,function(n){return(g[1]-(n.length-1)*l)/t.sum(n,y)});f.forEach(function(t){t.forEach(function(t,r){t.y=r,t.dy=t.value*n})}),v.forEach(function(t){t.dy=t.value*n})}function u(n){function r(n){return s(n.source)*n.value}f.forEach(function(e){e.forEach(function(e){if(e.targetLinks.length){var u=t.sum(e.targetLinks,r)/t.sum(e.targetLinks,y);e.y+=(u-s(e))*n}})})}function o(n){function r(n){return s(n.target)*n.value}f.slice().reverse().forEach(function(e){e.forEach(function(e){if(e.sourceLinks.length){var u=t.sum(e.sourceLinks,r)/t.sum(e.sourceLinks,y);e.y+=(u-s(e))*n}})})}function c(){f.forEach(function(n){var t,r,e,u=0,o=n.length;for(n.sort(i),e=0;e<o;++e)t=n[e],r=u-t.y,r>0&&(t.y+=r),u=t.y+t.dy+l;if(r=u-l-g[1],r>0)for(u=t.y-=r,e=o-2;e>=0;--e)t=n[e],r=t.y+t.dy+l-u,r>0&&(t.y-=r),u=t.y})}function i(n,t){return n.y-t.y}var f=r.nest().key(function(n){return n.x}).sortKeys(t.ascending).entries(k).map(function(n){return n.values});e(),c();for(var a=1;n>0;--n)o(a*=.99),c(),u(a),c()}function a(){function n(n,t){return n.source.y-t.source.y}function t(n,t){return n.target.y-t.target.y}k.forEach(function(r){r.sourceLinks.sort(t),r.targetLinks.sort(n)}),k.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 s(n){return n.y+n.dy/2}function y(n){return n.value}var d={},h=24,l=8,g=[1,1],k=[],v=[];return d.nodeWidth=function(n){return arguments.length?(h=+n,d):h},d.nodePadding=function(n){return arguments.length?(l=+n,d):l},d.nodes=function(n){return arguments.length?(k=n,d):k},d.links=function(n){return arguments.length?(v=n,d):v},d.size=function(n){return arguments.length?(g=n,d):g},d.layout=function(t){return n(),u(),o(),f(t),a(),d},d.relayout=function(){return a(),d},d.link=function(){function n(n){var r=n.source.x+n.source.dx,u=n.target.x,o=e.number(r,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"+r+","+f+"C"+c+","+f+" "+i+","+a+" "+u+","+a}var t=.5;return n.curvature=function(r){return arguments.length?(t=+r,n):t},n},d}n.sankey=u,Object.defineProperty(n,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-sankey", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Visualize flow between nodes in a directed acyclic network.", | ||
@@ -9,2 +9,6 @@ "keywords": [ | ||
], | ||
"author": { | ||
"name": "Mike Bostock", | ||
"url": "http://bost.ocks.org/mike" | ||
}, | ||
"license": "BSD-3-Clause", | ||
@@ -19,16 +23,20 @@ "main": "build/d3-sankey.js", | ||
"scripts": { | ||
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -g d3-arrays:d3_arrays,d3-interpolate:d3_interpolate -u d3-sankey -n d3_sankey -o build/d3-sankey.js -- build/bundle.js", | ||
"test": "faucet `find test -name '*-test.js'`", | ||
"prepublish": "npm run test && uglifyjs build/d3-sankey.js -c -m -o build/d3-sankey.min.js && rm -f build/d3-sankey.zip && zip -j build/d3-sankey.zip -- LICENSE README.md build/d3-sankey.js build/d3-sankey.min.js" | ||
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -g d3-array:d3,d3-collection:d3,d3-interpolate:d3 -f umd -n d3 -o build/d3-sankey.js -- index.js", | ||
"test": "tape 'test/**/*-test.js' && eslint index.js src", | ||
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-sankey.js -c -m -o build/d3-sankey.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-sankey.js ../d3.github.com/d3-sankey.v0.3.js && cp build/d3-sankey.min.js ../d3.github.com/d3-sankey.v0.3.min.js && cd ../d3.github.com && git add d3-sankey.v0.3.js d3-sankey.v0.3.min.js && git commit -m \"d3-sankey ${VERSION}\" && git push && cd - && zip -j build/d3-sankey.zip -- LICENSE README.md build/d3-sankey.js build/d3-sankey.min.js" | ||
}, | ||
"dependencies": { | ||
"d3-arrays": "~0.4.0", | ||
"d3-interpolate": "~0.2.0" | ||
"d3-array": "^1.0.1", | ||
"d3-collection": "^1.0.1", | ||
"d3-interpolate": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"faucet": "0.0", | ||
"rollup": "^0.21.1", | ||
"tape": "4", | ||
"uglify-js": "2" | ||
"eslint": "^3.4.0", | ||
"json2module": "0.0.3", | ||
"package-preamble": "0.0.2", | ||
"rollup": "^0.34.13", | ||
"tape": "^4.6.0", | ||
"uglify-js": "^2.7.3" | ||
} | ||
} |
@@ -1,2 +0,3 @@ | ||
import {ascending, min, nest, sum} from "d3-arrays"; | ||
import {ascending, min, sum} from "d3-array"; | ||
import {nest} from "d3-collection"; | ||
import {number} from "d3-interpolate"; | ||
@@ -138,9 +139,9 @@ | ||
function moveSourcesRight() { | ||
nodes.forEach(function(node) { | ||
if (!node.targetLinks.length) { | ||
node.x = min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
} | ||
}); | ||
} | ||
// function moveSourcesRight() { | ||
// nodes.forEach(function(node) { | ||
// if (!node.targetLinks.length) { | ||
// node.x = min(node.sourceLinks, function(d) { return d.target.x; }) - 1; | ||
// } | ||
// }); | ||
// } | ||
@@ -196,3 +197,3 @@ function moveSinksRight(x) { | ||
function relaxLeftToRight(alpha) { | ||
nodesByBreadth.forEach(function(nodes, breadth) { | ||
nodesByBreadth.forEach(function(nodes) { | ||
nodes.forEach(function(node) { | ||
@@ -299,2 +300,2 @@ if (node.targetLinks.length) { | ||
return sankey; | ||
}; | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
24939
523
1
3
6
+ Addedd3-array@^1.0.1
+ Addedd3-collection@^1.0.1
+ Addedd3-array@1.2.4(transitive)
+ Addedd3-collection@1.0.7(transitive)
+ Addedd3-color@1.4.1(transitive)
+ Addedd3-interpolate@1.4.0(transitive)
- Removedd3-arrays@~0.4.0
- Removedd3-arrays@0.4.1(transitive)
- Removedd3-color@0.3.4(transitive)
- Removedd3-interpolate@0.2.1(transitive)
Updatedd3-interpolate@^1.1.1