Socket
Socket
Sign inDemoInstall

d3-hierarchy

Package Overview
Dependencies
0
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.9 to 2.0.0-rc.1

src/hierarchy/find.js

126

dist/d3-hierarchy.js

@@ -1,2 +0,2 @@

// https://d3js.org/d3-hierarchy/ v1.1.9 Copyright 2019 Mike Bostock
// https://d3js.org/d3-hierarchy/ v2.0.0-rc.1 Copyright 2019 Mike Bostock
(function (global, factory) {

@@ -106,22 +106,18 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

function node_each(callback) {
var node = this, current, next = [node], children, i, n;
do {
current = next.reverse(), next = [];
while (node = current.pop()) {
callback(node), children = node.children;
if (children) for (i = 0, n = children.length; i < n; ++i) {
next.push(children[i]);
}
}
} while (next.length);
function node_each(callback, that) {
let index = -1;
for (const node of this) {
callback.call(that, node, ++index, this);
}
return this;
}
function node_eachBefore(callback) {
var node = this, nodes = [node], children, i;
function node_eachBefore(callback, that) {
var node = this, nodes = [node], children, i, index = -1;
while (node = nodes.pop()) {
callback(node), children = node.children;
if (children) for (i = children.length - 1; i >= 0; --i) {
nodes.push(children[i]);
callback.call(that, node, ++index, this);
if (children = node.children) {
for (i = children.length - 1; i >= 0; --i) {
nodes.push(children[i]);
}
}

@@ -132,12 +128,14 @@ }

function node_eachAfter(callback) {
var node = this, nodes = [node], next = [], children, i, n;
function node_eachAfter(callback, that) {
var node = this, nodes = [node], next = [], children, i, n, index = -1;
while (node = nodes.pop()) {
next.push(node), children = node.children;
if (children) for (i = 0, n = children.length; i < n; ++i) {
nodes.push(children[i]);
next.push(node);
if (children = node.children) {
for (i = 0, n = children.length; i < n; ++i) {
nodes.push(children[i]);
}
}
}
while (node = next.pop()) {
callback(node);
callback.call(that, node, ++index, this);
}

@@ -147,2 +145,11 @@ return this;

function node_find(callback, that) {
let index = -1;
for (const node of this) {
if (callback.call(that, node, ++index, this)) {
return node;
}
}
}
function node_sum(value) {

@@ -206,7 +213,3 @@ return this.eachAfter(function(node) {

function node_descendants() {
var nodes = [];
this.each(function(node) {
nodes.push(node);
});
return nodes;
return Array.from(this);
}

@@ -234,2 +237,17 @@

function* node_iterator() {
var node = this, current, next = [node], children, i, n;
do {
current = next.reverse(), next = [];
while (node = current.pop()) {
yield node;
if (children = node.children) {
for (i = 0, n = children.length; i < n; ++i) {
next.push(children[i]);
}
}
}
} while (next.length);
}
function hierarchy(data, children) {

@@ -249,6 +267,6 @@ var root = new Node(data),

if (valued) node.value = +node.data.value;
if ((childs = children(node.data)) && (n = childs.length)) {
node.children = new Array(n);
if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
node.children = childs;
for (i = n - 1; i >= 0; --i) {
nodes.push(child = node.children[i] = new Node(childs[i]));
nodes.push(child = childs[i] = new Node(childs[i]));
child.parent = node;

@@ -294,2 +312,3 @@ child.depth = node.depth + 1;

eachBefore: node_eachBefore,
find: node_find,
sum: node_sum,

@@ -302,6 +321,11 @@ sort: node_sort,

links: node_links,
copy: node_copy
copy: node_copy,
[Symbol.iterator]: node_iterator
};
var slice = Array.prototype.slice;
function array(x) {
return typeof x === "object" && "length" in x
? x // Array, TypedArray, NodeList, array-like
: Array.from(x); // Map, Set, iterable, string, or anything else
}

@@ -324,3 +348,3 @@ function shuffle(array) {

function enclose(circles) {
var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
var i = 0, n = (circles = shuffle(Array.from(circles))).length, B = [], p, e;

@@ -486,3 +510,3 @@ while (i < n) {

function packEnclose(circles) {
if (!(n = circles.length)) return 0;
if (!(n = (circles = array(circles)).length)) return 0;

@@ -724,4 +748,3 @@ var a, b, c, n, aa, ca, i, j, k, sj, sk;

var keyPrefix = "$", // Protect against keys like “__proto__”.
preroot = {depth: -1},
var preroot = {depth: -1},
ambiguous = {};

@@ -742,28 +765,28 @@

function stratify(data) {
var d,
var nodes = Array.from(data),
n = nodes.length,
d,
i,
n = data.length,
root,
parent,
node,
nodes = new Array(n),
nodeId,
nodeKey,
nodeByKey = {};
nodeByKey = new Map;
for (i = 0; i < n; ++i) {
d = data[i], node = nodes[i] = new Node(d);
d = nodes[i], node = nodes[i] = new Node(d);
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
nodeKey = keyPrefix + (node.id = nodeId);
nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
nodeKey = node.id = nodeId;
nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
}
if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
node.parent = nodeId;
}
}
for (i = 0; i < n; ++i) {
node = nodes[i], nodeId = parentId(data[i], i, data);
if (nodeId == null || !(nodeId += "")) {
if (root) throw new Error("multiple roots");
root = node;
} else {
parent = nodeByKey[keyPrefix + nodeId];
node = nodes[i];
if (nodeId = node.parent) {
parent = nodeByKey.get(nodeId);
if (!parent) throw new Error("missing: " + nodeId);

@@ -774,2 +797,5 @@ if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);

node.parent = parent;
} else {
if (root) throw new Error("multiple roots");
root = node;
}

@@ -776,0 +802,0 @@ }

@@ -1,2 +0,2 @@

// https://d3js.org/d3-hierarchy/ v1.1.9 Copyright 2019 Mike Bostock
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n=n||self).d3=n.d3||{})}(this,function(n){"use strict";function r(n,r){return n.parent===r.parent?1:2}function e(n,r){return n+r.x}function t(n,r){return Math.max(n,r.y)}function u(n){var r=0,e=n.children,t=e&&e.length;if(t)for(;--t>=0;)r+=e[t].value;else r=1;n.value=r}function i(n,r){var e,t,u,i,a,h=new c(n),l=+n.value&&(h.value=n.value),p=[h];for(null==r&&(r=o);e=p.pop();)if(l&&(e.value=+e.data.value),(u=r(e.data))&&(a=u.length))for(e.children=new Array(a),i=a-1;i>=0;--i)p.push(t=e.children[i]=new c(u[i])),t.parent=e,t.depth=e.depth+1;return h.eachBefore(f)}function o(n){return n.children}function a(n){n.data=n.data.data}function f(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function c(n){this.data=n,this.depth=this.height=0,this.parent=null}c.prototype=i.prototype={constructor:c,count:function(){return this.eachAfter(u)},each:function(n){var r,e,t,u,i=this,o=[i];do{for(r=o.reverse(),o=[];i=r.pop();)if(n(i),e=i.children)for(t=0,u=e.length;t<u;++t)o.push(e[t])}while(o.length);return this},eachAfter:function(n){for(var r,e,t,u=this,i=[u],o=[];u=i.pop();)if(o.push(u),r=u.children)for(e=0,t=r.length;e<t;++e)i.push(r[e]);for(;u=o.pop();)n(u);return this},eachBefore:function(n){for(var r,e,t=this,u=[t];t=u.pop();)if(n(t),r=t.children)for(e=r.length-1;e>=0;--e)u.push(r[e]);return this},sum:function(n){return this.eachAfter(function(r){for(var e=+n(r.data)||0,t=r.children,u=t&&t.length;--u>=0;)e+=t[u].value;r.value=e})},sort:function(n){return this.eachBefore(function(r){r.children&&r.children.sort(n)})},path:function(n){for(var r=this,e=function(n,r){if(n===r)return n;var e=n.ancestors(),t=r.ancestors(),u=null;for(n=e.pop(),r=t.pop();n===r;)u=n,n=e.pop(),r=t.pop();return u}(r,n),t=[r];r!==e;)r=r.parent,t.push(r);for(var u=t.length;n!==e;)t.splice(u,0,n),n=n.parent;return t},ancestors:function(){for(var n=this,r=[n];n=n.parent;)r.push(n);return r},descendants:function(){var n=[];return this.each(function(r){n.push(r)}),n},leaves:function(){var n=[];return this.eachBefore(function(r){r.children||n.push(r)}),n},links:function(){var n=this,r=[];return n.each(function(e){e!==n&&r.push({source:e.parent,target:e})}),r},copy:function(){return i(this).eachBefore(a)}};var h=Array.prototype.slice;function l(n){for(var r,e,t=0,u=(n=function(n){for(var r,e,t=n.length;t;)e=Math.random()*t--|0,r=n[t],n[t]=n[e],n[e]=r;return n}(h.call(n))).length,i=[];t<u;)r=n[t],e&&s(e,r)?++t:(e=x(i=p(i,r)),t=0);return e}function p(n,r){var e,t;if(v(r,n))return[r];for(e=0;e<n.length;++e)if(d(r,n[e])&&v(y(n[e],r),n))return[n[e],r];for(e=0;e<n.length-1;++e)for(t=e+1;t<n.length;++t)if(d(y(n[e],n[t]),r)&&d(y(n[e],r),n[t])&&d(y(n[t],r),n[e])&&v(g(n[e],n[t],r),n))return[n[e],n[t],r];throw new Error}function d(n,r){var e=n.r-r.r,t=r.x-n.x,u=r.y-n.y;return e<0||e*e<t*t+u*u}function s(n,r){var e=n.r-r.r+1e-6,t=r.x-n.x,u=r.y-n.y;return e>0&&e*e>t*t+u*u}function v(n,r){for(var e=0;e<r.length;++e)if(!s(n,r[e]))return!1;return!0}function x(n){switch(n.length){case 1:return{x:(r=n[0]).x,y:r.y,r:r.r};case 2:return y(n[0],n[1]);case 3:return g(n[0],n[1],n[2])}var r}function y(n,r){var e=n.x,t=n.y,u=n.r,i=r.x,o=r.y,a=r.r,f=i-e,c=o-t,h=a-u,l=Math.sqrt(f*f+c*c);return{x:(e+i+f/l*h)/2,y:(t+o+c/l*h)/2,r:(l+u+a)/2}}function g(n,r,e){var t=n.x,u=n.y,i=n.r,o=r.x,a=r.y,f=r.r,c=e.x,h=e.y,l=e.r,p=t-o,d=t-c,s=u-a,v=u-h,x=f-i,y=l-i,g=t*t+u*u-i*i,m=g-o*o-a*a+f*f,w=g-c*c-h*h+l*l,_=d*s-p*v,z=(s*w-v*m)/(2*_)-t,B=(v*x-s*y)/_,M=(d*m-p*w)/(2*_)-u,A=(p*y-d*x)/_,q=B*B+A*A-1,E=2*(i+z*B+M*A),b=z*z+M*M-i*i,S=-(q?(E+Math.sqrt(E*E-4*q*b))/(2*q):b/E);return{x:t+z+B*S,y:u+M+A*S,r:S}}function m(n,r,e){var t,u,i,o,a=n.x-r.x,f=n.y-r.y,c=a*a+f*f;c?(u=r.r+e.r,u*=u,o=n.r+e.r,u>(o*=o)?(t=(c+o-u)/(2*c),i=Math.sqrt(Math.max(0,o/c-t*t)),e.x=n.x-t*a-i*f,e.y=n.y-t*f+i*a):(t=(c+u-o)/(2*c),i=Math.sqrt(Math.max(0,u/c-t*t)),e.x=r.x+t*a-i*f,e.y=r.y+t*f+i*a)):(e.x=r.x+e.r,e.y=r.y)}function w(n,r){var e=n.r+r.r-1e-6,t=r.x-n.x,u=r.y-n.y;return e>0&&e*e>t*t+u*u}function _(n){var r=n._,e=n.next._,t=r.r+e.r,u=(r.x*e.r+e.x*r.r)/t,i=(r.y*e.r+e.y*r.r)/t;return u*u+i*i}function z(n){this._=n,this.next=null,this.previous=null}function B(n){if(!(u=n.length))return 0;var r,e,t,u,i,o,a,f,c,h,p;if((r=n[0]).x=0,r.y=0,!(u>1))return r.r;if(e=n[1],r.x=-e.r,e.x=r.r,e.y=0,!(u>2))return r.r+e.r;m(e,r,t=n[2]),r=new z(r),e=new z(e),t=new z(t),r.next=t.previous=e,e.next=r.previous=t,t.next=e.previous=r;n:for(a=3;a<u;++a){m(r._,e._,t=n[a]),t=new z(t),f=e.next,c=r.previous,h=e._.r,p=r._.r;do{if(h<=p){if(w(f._,t._)){e=f,r.next=e,e.previous=r,--a;continue n}h+=f._.r,f=f.next}else{if(w(c._,t._)){(r=c).next=e,e.previous=r,--a;continue n}p+=c._.r,c=c.previous}}while(f!==c.next);for(t.previous=r,t.next=e,r.next=e.previous=e=t,i=_(r);(t=t.next)!==e;)(o=_(t))<i&&(r=t,i=o);e=r.next}for(r=[e._],t=e;(t=t.next)!==e;)r.push(t._);for(t=l(r),a=0;a<u;++a)(r=n[a]).x-=t.x,r.y-=t.y;return t.r}function M(n){return null==n?null:A(n)}function A(n){if("function"!=typeof n)throw new Error;return n}function q(){return 0}function E(n){return function(){return n}}function b(n){return Math.sqrt(n.value)}function S(n){return function(r){r.children||(r.r=Math.max(0,+n(r)||0))}}function k(n,r){return function(e){if(t=e.children){var t,u,i,o=t.length,a=n(e)*r||0;if(a)for(u=0;u<o;++u)t[u].r+=a;if(i=B(t),a)for(u=0;u<o;++u)t[u].r-=a;e.r=i+a}}}function I(n){return function(r){var e=r.parent;r.r*=n,e&&(r.x=e.x+n*r.x,r.y=e.y+n*r.y)}}function O(n){n.x0=Math.round(n.x0),n.y0=Math.round(n.y0),n.x1=Math.round(n.x1),n.y1=Math.round(n.y1)}function j(n,r,e,t,u){for(var i,o=n.children,a=-1,f=o.length,c=n.value&&(t-r)/n.value;++a<f;)(i=o[a]).y0=e,i.y1=u,i.x0=r,i.x1=r+=i.value*c}var R="$",T={depth:-1},D={};function L(n){return n.id}function P(n){return n.parentId}function $(n,r){return n.parent===r.parent?1:2}function C(n){var r=n.children;return r?r[0]:n.t}function F(n){var r=n.children;return r?r[r.length-1]:n.t}function G(n,r,e){var t=e/(r.i-n.i);r.c-=t,r.s+=e,n.c+=t,r.z+=e,r.m+=e}function H(n,r,e){return n.a.parent===r.parent?n.a:e}function J(n,r){this._=n,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=r}function K(n,r,e,t,u){for(var i,o=n.children,a=-1,f=o.length,c=n.value&&(u-e)/n.value;++a<f;)(i=o[a]).x0=r,i.x1=t,i.y0=e,i.y1=e+=i.value*c}J.prototype=Object.create(c.prototype);var N=(1+Math.sqrt(5))/2;function Q(n,r,e,t,u,i){for(var o,a,f,c,h,l,p,d,s,v,x,y=[],g=r.children,m=0,w=0,_=g.length,z=r.value;m<_;){f=u-e,c=i-t;do{h=g[w++].value}while(!h&&w<_);for(l=p=h,x=h*h*(v=Math.max(c/f,f/c)/(z*n)),s=Math.max(p/x,x/l);w<_;++w){if(h+=a=g[w].value,a<l&&(l=a),a>p&&(p=a),x=h*h*v,(d=Math.max(p/x,x/l))>s){h-=a;break}s=d}y.push(o={value:h,dice:f<c,children:g.slice(m,w)}),o.dice?j(o,e,t,u,z?t+=c*h/z:i):K(o,e,t,z?e+=f*h/z:u,i),z-=h,m=w}return y}var U=function n(r){function e(n,e,t,u,i){Q(r,n,e,t,u,i)}return e.ratio=function(r){return n((r=+r)>1?r:1)},e}(N);var V=function n(r){function e(n,e,t,u,i){if((o=n._squarify)&&o.ratio===r)for(var o,a,f,c,h,l=-1,p=o.length,d=n.value;++l<p;){for(f=(a=o[l]).children,c=a.value=0,h=f.length;c<h;++c)a.value+=f[c].value;a.dice?j(a,e,t,u,t+=(i-t)*a.value/d):K(a,e,t,e+=(u-e)*a.value/d,i),d-=a.value}else n._squarify=o=Q(r,n,e,t,u,i),o.ratio=r}return e.ratio=function(r){return n((r=+r)>1?r:1)},e}(N);n.cluster=function(){var n=r,u=1,i=1,o=!1;function a(r){var a,f=0;r.eachAfter(function(r){var u=r.children;u?(r.x=function(n){return n.reduce(e,0)/n.length}(u),r.y=function(n){return 1+n.reduce(t,0)}(u)):(r.x=a?f+=n(r,a):0,r.y=0,a=r)});var c=function(n){for(var r;r=n.children;)n=r[0];return n}(r),h=function(n){for(var r;r=n.children;)n=r[r.length-1];return n}(r),l=c.x-n(c,h)/2,p=h.x+n(h,c)/2;return r.eachAfter(o?function(n){n.x=(n.x-r.x)*u,n.y=(r.y-n.y)*i}:function(n){n.x=(n.x-l)/(p-l)*u,n.y=(1-(r.y?n.y/r.y:1))*i})}return a.separation=function(r){return arguments.length?(n=r,a):n},a.size=function(n){return arguments.length?(o=!1,u=+n[0],i=+n[1],a):o?null:[u,i]},a.nodeSize=function(n){return arguments.length?(o=!0,u=+n[0],i=+n[1],a):o?[u,i]:null},a},n.hierarchy=i,n.pack=function(){var n=null,r=1,e=1,t=q;function u(u){return u.x=r/2,u.y=e/2,n?u.eachBefore(S(n)).eachAfter(k(t,.5)).eachBefore(I(1)):u.eachBefore(S(b)).eachAfter(k(q,1)).eachAfter(k(t,u.r/Math.min(r,e))).eachBefore(I(Math.min(r,e)/(2*u.r))),u}return u.radius=function(r){return arguments.length?(n=M(r),u):n},u.size=function(n){return arguments.length?(r=+n[0],e=+n[1],u):[r,e]},u.padding=function(n){return arguments.length?(t="function"==typeof n?n:E(+n),u):t},u},n.packEnclose=l,n.packSiblings=function(n){return B(n),n},n.partition=function(){var n=1,r=1,e=0,t=!1;function u(u){var i=u.height+1;return u.x0=u.y0=e,u.x1=n,u.y1=r/i,u.eachBefore(function(n,r){return function(t){t.children&&j(t,t.x0,n*(t.depth+1)/r,t.x1,n*(t.depth+2)/r);var u=t.x0,i=t.y0,o=t.x1-e,a=t.y1-e;o<u&&(u=o=(u+o)/2),a<i&&(i=a=(i+a)/2),t.x0=u,t.y0=i,t.x1=o,t.y1=a}}(r,i)),t&&u.eachBefore(O),u}return u.round=function(n){return arguments.length?(t=!!n,u):t},u.size=function(e){return arguments.length?(n=+e[0],r=+e[1],u):[n,r]},u.padding=function(n){return arguments.length?(e=+n,u):e},u},n.stratify=function(){var n=L,r=P;function e(e){var t,u,i,o,a,h,l,p=e.length,d=new Array(p),s={};for(u=0;u<p;++u)t=e[u],a=d[u]=new c(t),null!=(h=n(t,u,e))&&(h+="")&&(s[l=R+(a.id=h)]=l in s?D:a);for(u=0;u<p;++u)if(a=d[u],null!=(h=r(e[u],u,e))&&(h+="")){if(!(o=s[R+h]))throw new Error("missing: "+h);if(o===D)throw new Error("ambiguous: "+h);o.children?o.children.push(a):o.children=[a],a.parent=o}else{if(i)throw new Error("multiple roots");i=a}if(!i)throw new Error("no root");if(i.parent=T,i.eachBefore(function(n){n.depth=n.parent.depth+1,--p}).eachBefore(f),i.parent=null,p>0)throw new Error("cycle");return i}return e.id=function(r){return arguments.length?(n=A(r),e):n},e.parentId=function(n){return arguments.length?(r=A(n),e):r},e},n.tree=function(){var n=$,r=1,e=1,t=null;function u(u){var f=function(n){for(var r,e,t,u,i,o=new J(n,0),a=[o];r=a.pop();)if(t=r._.children)for(r.children=new Array(i=t.length),u=i-1;u>=0;--u)a.push(e=r.children[u]=new J(t[u],u)),e.parent=r;return(o.parent=new J(null,0)).children=[o],o}(u);if(f.eachAfter(i),f.parent.m=-f.z,f.eachBefore(o),t)u.eachBefore(a);else{var c=u,h=u,l=u;u.eachBefore(function(n){n.x<c.x&&(c=n),n.x>h.x&&(h=n),n.depth>l.depth&&(l=n)});var p=c===h?1:n(c,h)/2,d=p-c.x,s=r/(h.x+p+d),v=e/(l.depth||1);u.eachBefore(function(n){n.x=(n.x+d)*s,n.y=n.depth*v})}return u}function i(r){var e=r.children,t=r.parent.children,u=r.i?t[r.i-1]:null;if(e){!function(n){for(var r,e=0,t=0,u=n.children,i=u.length;--i>=0;)(r=u[i]).z+=e,r.m+=e,e+=r.s+(t+=r.c)}(r);var i=(e[0].z+e[e.length-1].z)/2;u?(r.z=u.z+n(r._,u._),r.m=r.z-i):r.z=i}else u&&(r.z=u.z+n(r._,u._));r.parent.A=function(r,e,t){if(e){for(var u,i=r,o=r,a=e,f=i.parent.children[0],c=i.m,h=o.m,l=a.m,p=f.m;a=F(a),i=C(i),a&&i;)f=C(f),(o=F(o)).a=r,(u=a.z+l-i.z-c+n(a._,i._))>0&&(G(H(a,r,t),r,u),c+=u,h+=u),l+=a.m,c+=i.m,p+=f.m,h+=o.m;a&&!F(o)&&(o.t=a,o.m+=l-h),i&&!C(f)&&(f.t=i,f.m+=c-p,t=r)}return t}(r,u,r.parent.A||t[0])}function o(n){n._.x=n.z+n.parent.m,n.m+=n.parent.m}function a(n){n.x*=r,n.y=n.depth*e}return u.separation=function(r){return arguments.length?(n=r,u):n},u.size=function(n){return arguments.length?(t=!1,r=+n[0],e=+n[1],u):t?null:[r,e]},u.nodeSize=function(n){return arguments.length?(t=!0,r=+n[0],e=+n[1],u):t?[r,e]:null},u},n.treemap=function(){var n=U,r=!1,e=1,t=1,u=[0],i=q,o=q,a=q,f=q,c=q;function h(n){return n.x0=n.y0=0,n.x1=e,n.y1=t,n.eachBefore(l),u=[0],r&&n.eachBefore(O),n}function l(r){var e=u[r.depth],t=r.x0+e,h=r.y0+e,l=r.x1-e,p=r.y1-e;l<t&&(t=l=(t+l)/2),p<h&&(h=p=(h+p)/2),r.x0=t,r.y0=h,r.x1=l,r.y1=p,r.children&&(e=u[r.depth+1]=i(r)/2,t+=c(r)-e,h+=o(r)-e,(l-=a(r)-e)<t&&(t=l=(t+l)/2),(p-=f(r)-e)<h&&(h=p=(h+p)/2),n(r,t,h,l,p))}return h.round=function(n){return arguments.length?(r=!!n,h):r},h.size=function(n){return arguments.length?(e=+n[0],t=+n[1],h):[e,t]},h.tile=function(r){return arguments.length?(n=A(r),h):n},h.padding=function(n){return arguments.length?h.paddingInner(n).paddingOuter(n):h.paddingInner()},h.paddingInner=function(n){return arguments.length?(i="function"==typeof n?n:E(+n),h):i},h.paddingOuter=function(n){return arguments.length?h.paddingTop(n).paddingRight(n).paddingBottom(n).paddingLeft(n):h.paddingTop()},h.paddingTop=function(n){return arguments.length?(o="function"==typeof n?n:E(+n),h):o},h.paddingRight=function(n){return arguments.length?(a="function"==typeof n?n:E(+n),h):a},h.paddingBottom=function(n){return arguments.length?(f="function"==typeof n?n:E(+n),h):f},h.paddingLeft=function(n){return arguments.length?(c="function"==typeof n?n:E(+n),h):c},h},n.treemapBinary=function(n,r,e,t,u){var i,o,a=n.children,f=a.length,c=new Array(f+1);for(c[0]=o=i=0;i<f;++i)c[i+1]=o+=a[i].value;!function n(r,e,t,u,i,o,f){if(r>=e-1){var h=a[r];return h.x0=u,h.y0=i,h.x1=o,void(h.y1=f)}for(var l=c[r],p=t/2+l,d=r+1,s=e-1;d<s;){var v=d+s>>>1;c[v]<p?d=v+1:s=v}p-c[d-1]<c[d]-p&&r+1<d&&--d;var x=c[d]-l,y=t-x;if(o-u>f-i){var g=(u*y+o*x)/t;n(r,d,x,u,i,g,f),n(d,e,y,g,i,o,f)}else{var m=(i*y+f*x)/t;n(r,d,x,u,i,o,m),n(d,e,y,u,m,o,f)}}(0,f,n.value,r,e,t,u)},n.treemapDice=j,n.treemapResquarify=V,n.treemapSlice=K,n.treemapSliceDice=function(n,r,e,t,u){(1&n.depth?K:j)(n,r,e,t,u)},n.treemapSquarify=U,Object.defineProperty(n,"__esModule",{value:!0})});
// https://d3js.org/d3-hierarchy/ v2.0.0-rc.1 Copyright 2019 Mike Bostock
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n=n||self).d3=n.d3||{})}(this,function(n){"use strict";function r(n,r){return n.parent===r.parent?1:2}function t(n,r){return n+r.x}function e(n,r){return Math.max(n,r.y)}function i(n){var r=0,t=n.children,e=t&&t.length;if(e)for(;--e>=0;)r+=t[e].value;else r=1;n.value=r}function u(n,r){var t,e,i,u,f,h=new c(n),l=+n.value&&(h.value=n.value),p=[h];for(null==r&&(r=o);t=p.pop();)if(l&&(t.value=+t.data.value),(i=r(t.data))&&(f=(i=Array.from(i)).length))for(t.children=i,u=f-1;u>=0;--u)p.push(e=i[u]=new c(i[u])),e.parent=t,e.depth=t.depth+1;return h.eachBefore(a)}function o(n){return n.children}function f(n){n.data=n.data.data}function a(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function c(n){this.data=n,this.depth=this.height=0,this.parent=null}function h(n){for(var r,t,e=0,i=(n=function(n){for(var r,t,e=n.length;e;)t=Math.random()*e--|0,r=n[e],n[e]=n[t],n[t]=r;return n}(Array.from(n))).length,u=[];e<i;)r=n[e],t&&d(t,r)?++e:(t=v(u=l(u,r)),e=0);return t}function l(n,r){var t,e;if(s(r,n))return[r];for(t=0;t<n.length;++t)if(p(r,n[t])&&s(x(n[t],r),n))return[n[t],r];for(t=0;t<n.length-1;++t)for(e=t+1;e<n.length;++e)if(p(x(n[t],n[e]),r)&&p(x(n[t],r),n[e])&&p(x(n[e],r),n[t])&&s(y(n[t],n[e],r),n))return[n[t],n[e],r];throw new Error}function p(n,r){var t=n.r-r.r,e=r.x-n.x,i=r.y-n.y;return t<0||t*t<e*e+i*i}function d(n,r){var t=n.r-r.r+1e-6,e=r.x-n.x,i=r.y-n.y;return t>0&&t*t>e*e+i*i}function s(n,r){for(var t=0;t<r.length;++t)if(!d(n,r[t]))return!1;return!0}function v(n){switch(n.length){case 1:return{x:(r=n[0]).x,y:r.y,r:r.r};case 2:return x(n[0],n[1]);case 3:return y(n[0],n[1],n[2])}var r}function x(n,r){var t=n.x,e=n.y,i=n.r,u=r.x,o=r.y,f=r.r,a=u-t,c=o-e,h=f-i,l=Math.sqrt(a*a+c*c);return{x:(t+u+a/l*h)/2,y:(e+o+c/l*h)/2,r:(l+i+f)/2}}function y(n,r,t){var e=n.x,i=n.y,u=n.r,o=r.x,f=r.y,a=r.r,c=t.x,h=t.y,l=t.r,p=e-o,d=e-c,s=i-f,v=i-h,x=a-u,y=l-u,g=e*e+i*i-u*u,m=g-o*o-f*f+a*a,w=g-c*c-h*h+l*l,_=d*s-p*v,z=(s*w-v*m)/(2*_)-e,B=(v*x-s*y)/_,M=(d*m-p*w)/(2*_)-i,A=(p*y-d*x)/_,q=B*B+A*A-1,b=2*(u+z*B+M*A),E=z*z+M*M-u*u,S=-(q?(b+Math.sqrt(b*b-4*q*E))/(2*q):E/b);return{x:e+z+B*S,y:i+M+A*S,r:S}}function g(n,r,t){var e,i,u,o,f=n.x-r.x,a=n.y-r.y,c=f*f+a*a;c?(i=r.r+t.r,i*=i,o=n.r+t.r,i>(o*=o)?(e=(c+o-i)/(2*c),u=Math.sqrt(Math.max(0,o/c-e*e)),t.x=n.x-e*f-u*a,t.y=n.y-e*a+u*f):(e=(c+i-o)/(2*c),u=Math.sqrt(Math.max(0,i/c-e*e)),t.x=r.x+e*f-u*a,t.y=r.y+e*a+u*f)):(t.x=r.x+t.r,t.y=r.y)}function m(n,r){var t=n.r+r.r-1e-6,e=r.x-n.x,i=r.y-n.y;return t>0&&t*t>e*e+i*i}function w(n){var r=n._,t=n.next._,e=r.r+t.r,i=(r.x*t.r+t.x*r.r)/e,u=(r.y*t.r+t.y*r.r)/e;return i*i+u*u}function _(n){this._=n,this.next=null,this.previous=null}function z(n){if(!(u=(r=n,n="object"==typeof r&&"length"in r?r:Array.from(r)).length))return 0;var r,t,e,i,u,o,f,a,c,l,p,d;if((t=n[0]).x=0,t.y=0,!(u>1))return t.r;if(e=n[1],t.x=-e.r,e.x=t.r,e.y=0,!(u>2))return t.r+e.r;g(e,t,i=n[2]),t=new _(t),e=new _(e),i=new _(i),t.next=i.previous=e,e.next=t.previous=i,i.next=e.previous=t;n:for(a=3;a<u;++a){g(t._,e._,i=n[a]),i=new _(i),c=e.next,l=t.previous,p=e._.r,d=t._.r;do{if(p<=d){if(m(c._,i._)){e=c,t.next=e,e.previous=t,--a;continue n}p+=c._.r,c=c.next}else{if(m(l._,i._)){(t=l).next=e,e.previous=t,--a;continue n}d+=l._.r,l=l.previous}}while(c!==l.next);for(i.previous=t,i.next=e,t.next=e.previous=e=i,o=w(t);(i=i.next)!==e;)(f=w(i))<o&&(t=i,o=f);e=t.next}for(t=[e._],i=e;(i=i.next)!==e;)t.push(i._);for(i=h(t),a=0;a<u;++a)(t=n[a]).x-=i.x,t.y-=i.y;return i.r}function B(n){return null==n?null:M(n)}function M(n){if("function"!=typeof n)throw new Error;return n}function A(){return 0}function q(n){return function(){return n}}function b(n){return Math.sqrt(n.value)}function E(n){return function(r){r.children||(r.r=Math.max(0,+n(r)||0))}}function S(n,r){return function(t){if(e=t.children){var e,i,u,o=e.length,f=n(t)*r||0;if(f)for(i=0;i<o;++i)e[i].r+=f;if(u=z(e),f)for(i=0;i<o;++i)e[i].r-=f;t.r=u+f}}}function k(n){return function(r){var t=r.parent;r.r*=n,t&&(r.x=t.x+n*r.x,r.y=t.y+n*r.y)}}function I(n){n.x0=Math.round(n.x0),n.y0=Math.round(n.y0),n.x1=Math.round(n.x1),n.y1=Math.round(n.y1)}function j(n,r,t,e,i){for(var u,o=n.children,f=-1,a=o.length,c=n.value&&(e-r)/n.value;++f<a;)(u=o[f]).y0=t,u.y1=i,u.x0=r,u.x1=r+=u.value*c}c.prototype=u.prototype={constructor:c,count:function(){return this.eachAfter(i)},each:function(n,r){let t=-1;for(const e of this)n.call(r,e,++t,this);return this},eachAfter:function(n,r){for(var t,e,i,u=this,o=[u],f=[],a=-1;u=o.pop();)if(f.push(u),t=u.children)for(e=0,i=t.length;e<i;++e)o.push(t[e]);for(;u=f.pop();)n.call(r,u,++a,this);return this},eachBefore:function(n,r){for(var t,e,i=this,u=[i],o=-1;i=u.pop();)if(n.call(r,i,++o,this),t=i.children)for(e=t.length-1;e>=0;--e)u.push(t[e]);return this},find:function(n,r){let t=-1;for(const e of this)if(n.call(r,e,++t,this))return e},sum:function(n){return this.eachAfter(function(r){for(var t=+n(r.data)||0,e=r.children,i=e&&e.length;--i>=0;)t+=e[i].value;r.value=t})},sort:function(n){return this.eachBefore(function(r){r.children&&r.children.sort(n)})},path:function(n){for(var r=this,t=function(n,r){if(n===r)return n;var t=n.ancestors(),e=r.ancestors(),i=null;for(n=t.pop(),r=e.pop();n===r;)i=n,n=t.pop(),r=e.pop();return i}(r,n),e=[r];r!==t;)r=r.parent,e.push(r);for(var i=e.length;n!==t;)e.splice(i,0,n),n=n.parent;return e},ancestors:function(){for(var n=this,r=[n];n=n.parent;)r.push(n);return r},descendants:function(){return Array.from(this)},leaves:function(){var n=[];return this.eachBefore(function(r){r.children||n.push(r)}),n},links:function(){var n=this,r=[];return n.each(function(t){t!==n&&r.push({source:t.parent,target:t})}),r},copy:function(){return u(this).eachBefore(f)},[Symbol.iterator]:function*(){var n,r,t,e,i=this,u=[i];do{for(n=u.reverse(),u=[];i=n.pop();)if(yield i,r=i.children)for(t=0,e=r.length;t<e;++t)u.push(r[t])}while(u.length)}};var O={depth:-1},R={};function T(n){return n.id}function D(n){return n.parentId}function L(n,r){return n.parent===r.parent?1:2}function P(n){var r=n.children;return r?r[0]:n.t}function C(n){var r=n.children;return r?r[r.length-1]:n.t}function F(n,r,t){var e=t/(r.i-n.i);r.c-=e,r.s+=t,n.c+=e,r.z+=t,r.m+=t}function G(n,r,t){return n.a.parent===r.parent?n.a:t}function H(n,r){this._=n,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=r}function J(n,r,t,e,i){for(var u,o=n.children,f=-1,a=o.length,c=n.value&&(i-t)/n.value;++f<a;)(u=o[f]).x0=r,u.x1=e,u.y0=t,u.y1=t+=u.value*c}H.prototype=Object.create(c.prototype);var K=(1+Math.sqrt(5))/2;function N(n,r,t,e,i,u){for(var o,f,a,c,h,l,p,d,s,v,x,y=[],g=r.children,m=0,w=0,_=g.length,z=r.value;m<_;){a=i-t,c=u-e;do{h=g[w++].value}while(!h&&w<_);for(l=p=h,x=h*h*(v=Math.max(c/a,a/c)/(z*n)),s=Math.max(p/x,x/l);w<_;++w){if(h+=f=g[w].value,f<l&&(l=f),f>p&&(p=f),x=h*h*v,(d=Math.max(p/x,x/l))>s){h-=f;break}s=d}y.push(o={value:h,dice:a<c,children:g.slice(m,w)}),o.dice?j(o,t,e,i,z?e+=c*h/z:u):J(o,t,e,z?t+=a*h/z:i,u),z-=h,m=w}return y}var Q=function n(r){function t(n,t,e,i,u){N(r,n,t,e,i,u)}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(K);var U=function n(r){function t(n,t,e,i,u){if((o=n._squarify)&&o.ratio===r)for(var o,f,a,c,h,l=-1,p=o.length,d=n.value;++l<p;){for(a=(f=o[l]).children,c=f.value=0,h=a.length;c<h;++c)f.value+=a[c].value;f.dice?j(f,t,e,i,e+=(u-e)*f.value/d):J(f,t,e,t+=(i-t)*f.value/d,u),d-=f.value}else n._squarify=o=N(r,n,t,e,i,u),o.ratio=r}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(K);n.cluster=function(){var n=r,i=1,u=1,o=!1;function f(r){var f,a=0;r.eachAfter(function(r){var i=r.children;i?(r.x=function(n){return n.reduce(t,0)/n.length}(i),r.y=function(n){return 1+n.reduce(e,0)}(i)):(r.x=f?a+=n(r,f):0,r.y=0,f=r)});var c=function(n){for(var r;r=n.children;)n=r[0];return n}(r),h=function(n){for(var r;r=n.children;)n=r[r.length-1];return n}(r),l=c.x-n(c,h)/2,p=h.x+n(h,c)/2;return r.eachAfter(o?function(n){n.x=(n.x-r.x)*i,n.y=(r.y-n.y)*u}:function(n){n.x=(n.x-l)/(p-l)*i,n.y=(1-(r.y?n.y/r.y:1))*u})}return f.separation=function(r){return arguments.length?(n=r,f):n},f.size=function(n){return arguments.length?(o=!1,i=+n[0],u=+n[1],f):o?null:[i,u]},f.nodeSize=function(n){return arguments.length?(o=!0,i=+n[0],u=+n[1],f):o?[i,u]:null},f},n.hierarchy=u,n.pack=function(){var n=null,r=1,t=1,e=A;function i(i){return i.x=r/2,i.y=t/2,n?i.eachBefore(E(n)).eachAfter(S(e,.5)).eachBefore(k(1)):i.eachBefore(E(b)).eachAfter(S(A,1)).eachAfter(S(e,i.r/Math.min(r,t))).eachBefore(k(Math.min(r,t)/(2*i.r))),i}return i.radius=function(r){return arguments.length?(n=B(r),i):n},i.size=function(n){return arguments.length?(r=+n[0],t=+n[1],i):[r,t]},i.padding=function(n){return arguments.length?(e="function"==typeof n?n:q(+n),i):e},i},n.packEnclose=h,n.packSiblings=function(n){return z(n),n},n.partition=function(){var n=1,r=1,t=0,e=!1;function i(i){var u=i.height+1;return i.x0=i.y0=t,i.x1=n,i.y1=r/u,i.eachBefore(function(n,r){return function(e){e.children&&j(e,e.x0,n*(e.depth+1)/r,e.x1,n*(e.depth+2)/r);var i=e.x0,u=e.y0,o=e.x1-t,f=e.y1-t;o<i&&(i=o=(i+o)/2),f<u&&(u=f=(u+f)/2),e.x0=i,e.y0=u,e.x1=o,e.y1=f}}(r,u)),e&&i.eachBefore(I),i}return i.round=function(n){return arguments.length?(e=!!n,i):e},i.size=function(t){return arguments.length?(n=+t[0],r=+t[1],i):[n,r]},i.padding=function(n){return arguments.length?(t=+n,i):t},i},n.stratify=function(){var n=T,r=D;function t(t){var e,i,u,o,f,h,l,p=Array.from(t),d=p.length,s=new Map;for(i=0;i<d;++i)e=p[i],f=p[i]=new c(e),null!=(h=n(e,i,t))&&(h+="")&&(l=f.id=h,s.set(l,s.has(l)?R:f)),null!=(h=r(e,i,t))&&(h+="")&&(f.parent=h);for(i=0;i<d;++i)if(h=(f=p[i]).parent){if(!(o=s.get(h)))throw new Error("missing: "+h);if(o===R)throw new Error("ambiguous: "+h);o.children?o.children.push(f):o.children=[f],f.parent=o}else{if(u)throw new Error("multiple roots");u=f}if(!u)throw new Error("no root");if(u.parent=O,u.eachBefore(function(n){n.depth=n.parent.depth+1,--d}).eachBefore(a),u.parent=null,d>0)throw new Error("cycle");return u}return t.id=function(r){return arguments.length?(n=M(r),t):n},t.parentId=function(n){return arguments.length?(r=M(n),t):r},t},n.tree=function(){var n=L,r=1,t=1,e=null;function i(i){var a=function(n){for(var r,t,e,i,u,o=new H(n,0),f=[o];r=f.pop();)if(e=r._.children)for(r.children=new Array(u=e.length),i=u-1;i>=0;--i)f.push(t=r.children[i]=new H(e[i],i)),t.parent=r;return(o.parent=new H(null,0)).children=[o],o}(i);if(a.eachAfter(u),a.parent.m=-a.z,a.eachBefore(o),e)i.eachBefore(f);else{var c=i,h=i,l=i;i.eachBefore(function(n){n.x<c.x&&(c=n),n.x>h.x&&(h=n),n.depth>l.depth&&(l=n)});var p=c===h?1:n(c,h)/2,d=p-c.x,s=r/(h.x+p+d),v=t/(l.depth||1);i.eachBefore(function(n){n.x=(n.x+d)*s,n.y=n.depth*v})}return i}function u(r){var t=r.children,e=r.parent.children,i=r.i?e[r.i-1]:null;if(t){!function(n){for(var r,t=0,e=0,i=n.children,u=i.length;--u>=0;)(r=i[u]).z+=t,r.m+=t,t+=r.s+(e+=r.c)}(r);var u=(t[0].z+t[t.length-1].z)/2;i?(r.z=i.z+n(r._,i._),r.m=r.z-u):r.z=u}else i&&(r.z=i.z+n(r._,i._));r.parent.A=function(r,t,e){if(t){for(var i,u=r,o=r,f=t,a=u.parent.children[0],c=u.m,h=o.m,l=f.m,p=a.m;f=C(f),u=P(u),f&&u;)a=P(a),(o=C(o)).a=r,(i=f.z+l-u.z-c+n(f._,u._))>0&&(F(G(f,r,e),r,i),c+=i,h+=i),l+=f.m,c+=u.m,p+=a.m,h+=o.m;f&&!C(o)&&(o.t=f,o.m+=l-h),u&&!P(a)&&(a.t=u,a.m+=c-p,e=r)}return e}(r,i,r.parent.A||e[0])}function o(n){n._.x=n.z+n.parent.m,n.m+=n.parent.m}function f(n){n.x*=r,n.y=n.depth*t}return i.separation=function(r){return arguments.length?(n=r,i):n},i.size=function(n){return arguments.length?(e=!1,r=+n[0],t=+n[1],i):e?null:[r,t]},i.nodeSize=function(n){return arguments.length?(e=!0,r=+n[0],t=+n[1],i):e?[r,t]:null},i},n.treemap=function(){var n=Q,r=!1,t=1,e=1,i=[0],u=A,o=A,f=A,a=A,c=A;function h(n){return n.x0=n.y0=0,n.x1=t,n.y1=e,n.eachBefore(l),i=[0],r&&n.eachBefore(I),n}function l(r){var t=i[r.depth],e=r.x0+t,h=r.y0+t,l=r.x1-t,p=r.y1-t;l<e&&(e=l=(e+l)/2),p<h&&(h=p=(h+p)/2),r.x0=e,r.y0=h,r.x1=l,r.y1=p,r.children&&(t=i[r.depth+1]=u(r)/2,e+=c(r)-t,h+=o(r)-t,(l-=f(r)-t)<e&&(e=l=(e+l)/2),(p-=a(r)-t)<h&&(h=p=(h+p)/2),n(r,e,h,l,p))}return h.round=function(n){return arguments.length?(r=!!n,h):r},h.size=function(n){return arguments.length?(t=+n[0],e=+n[1],h):[t,e]},h.tile=function(r){return arguments.length?(n=M(r),h):n},h.padding=function(n){return arguments.length?h.paddingInner(n).paddingOuter(n):h.paddingInner()},h.paddingInner=function(n){return arguments.length?(u="function"==typeof n?n:q(+n),h):u},h.paddingOuter=function(n){return arguments.length?h.paddingTop(n).paddingRight(n).paddingBottom(n).paddingLeft(n):h.paddingTop()},h.paddingTop=function(n){return arguments.length?(o="function"==typeof n?n:q(+n),h):o},h.paddingRight=function(n){return arguments.length?(f="function"==typeof n?n:q(+n),h):f},h.paddingBottom=function(n){return arguments.length?(a="function"==typeof n?n:q(+n),h):a},h.paddingLeft=function(n){return arguments.length?(c="function"==typeof n?n:q(+n),h):c},h},n.treemapBinary=function(n,r,t,e,i){var u,o,f=n.children,a=f.length,c=new Array(a+1);for(c[0]=o=u=0;u<a;++u)c[u+1]=o+=f[u].value;!function n(r,t,e,i,u,o,a){if(r>=t-1){var h=f[r];return h.x0=i,h.y0=u,h.x1=o,void(h.y1=a)}for(var l=c[r],p=e/2+l,d=r+1,s=t-1;d<s;){var v=d+s>>>1;c[v]<p?d=v+1:s=v}p-c[d-1]<c[d]-p&&r+1<d&&--d;var x=c[d]-l,y=e-x;if(o-i>a-u){var g=(i*y+o*x)/e;n(r,d,x,i,u,g,a),n(d,t,y,g,u,o,a)}else{var m=(u*y+a*x)/e;n(r,d,x,i,u,o,m),n(d,t,y,i,m,o,a)}}(0,a,n.value,r,t,e,i)},n.treemapDice=j,n.treemapResquarify=U,n.treemapSlice=J,n.treemapSliceDice=function(n,r,t,e,i){(1&n.depth?J:j)(n,r,t,e,i)},n.treemapSquarify=Q,Object.defineProperty(n,"__esModule",{value:!0})});
{
"name": "d3-hierarchy",
"version": "1.1.9",
"version": "2.0.0-rc.1",
"publishConfig": {
"tag": "next"
},
"description": "Layout algorithms for visualizing hierarchical data.",

@@ -35,4 +38,3 @@ "keywords": [

"test": "tape 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && yarn test",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
"prepublishOnly": "rm -rf dist && yarn test"
},

@@ -39,0 +41,0 @@ "sideEffects": false,

@@ -177,14 +177,24 @@ # d3-hierarchy

<a name="node_each" href="#node_each">#</a> <i>node</i>.<b>each</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/each.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
<a name="node_iterator" href="#node_iterator">#</a> <i>node</i>[<b>Symbol.iterator</b>]() [<>](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/iterator.js "Source")
Invokes the specified *function* for *node* and each descendant in [breadth-first order](https://en.wikipedia.org/wiki/Breadth-first_search), such that a given *node* is only visited if all nodes of lesser depth have already been visited, as well as all preceding nodes of the same depth. The specified function is passed the current *node*.
Returns an iterator over the *node*’s descendants in breadth-first order. For example:
<a name="node_eachAfter" href="#node_eachAfter">#</a> <i>node</i>.<b>eachAfter</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachAfter.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
```js
for (const descendant of node) {
console.log(descendant);
}
```
Invokes the specified *function* for *node* and each descendant in [post-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Post-order), such that a given *node* is only visited after all of its descendants have already been visited. The specified function is passed the current *node*.
<a name="node_each" href="#node_each">#</a> <i>node</i>.<b>each</b>(<i>function</i>[, <i>that</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/each.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
<a name="node_eachBefore" href="#node_eachBefore">#</a> <i>node</i>.<b>eachBefore</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachBefore.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
Invokes the specified *function* for *node* and each descendant in [breadth-first order](https://en.wikipedia.org/wiki/Breadth-first_search), such that a given *node* is only visited if all nodes of lesser depth have already been visited, as well as all preceding nodes of the same depth. The specified function is passed the current *descendant*, the zero-based traversal *index*, and this *node*. If *that* is specified, it is the this context of the callback.
Invokes the specified *function* for *node* and each descendant in [pre-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order), such that a given *node* is only visited after all of its ancestors have already been visited. The specified function is passed the current *node*.
<a name="node_eachAfter" href="#node_eachAfter">#</a> <i>node</i>.<b>eachAfter</b>(<i>function</i>[, <i>that</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachAfter.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
Invokes the specified *function* for *node* and each descendant in [post-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Post-order), such that a given *node* is only visited after all of its descendants have already been visited. The specified function is passed the current *descendant*, the zero-based traversal *index*, and this *node*. If *that* is specified, it is the this context of the callback.
<a name="node_eachBefore" href="#node_eachBefore">#</a> <i>node</i>.<b>eachBefore</b>(<i>function</i>[, <i>that</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachBefore.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
Invokes the specified *function* for *node* and each descendant in [pre-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order), such that a given *node* is only visited after all of its ancestors have already been visited. The specified function is passed the current *descendant*, the zero-based traversal *index*, and this *node*. If *that* is specified, it is the this context of the callback.
<a name="node_copy" href="#node_copy">#</a> <i>node</i>.<b>copy</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)

@@ -191,0 +201,0 @@

@@ -1,2 +0,6 @@

export var slice = Array.prototype.slice;
export default function(x) {
return typeof x === "object" && "length" in x
? x // Array, TypedArray, NodeList, array-like
: Array.from(x); // Map, Set, iterable, string, or anything else
}

@@ -3,0 +7,0 @@ export function shuffle(array) {

export default function() {
var nodes = [];
this.each(function(node) {
nodes.push(node);
});
return nodes;
return Array.from(this);
}

@@ -1,13 +0,7 @@

export default function(callback) {
var node = this, current, next = [node], children, i, n;
do {
current = next.reverse(), next = [];
while (node = current.pop()) {
callback(node), children = node.children;
if (children) for (i = 0, n = children.length; i < n; ++i) {
next.push(children[i]);
}
}
} while (next.length);
export default function(callback, that) {
let index = -1;
for (const node of this) {
callback.call(that, node, ++index, this);
}
return this;
}

@@ -1,13 +0,15 @@

export default function(callback) {
var node = this, nodes = [node], next = [], children, i, n;
export default function(callback, that) {
var node = this, nodes = [node], next = [], children, i, n, index = -1;
while (node = nodes.pop()) {
next.push(node), children = node.children;
if (children) for (i = 0, n = children.length; i < n; ++i) {
nodes.push(children[i]);
next.push(node);
if (children = node.children) {
for (i = 0, n = children.length; i < n; ++i) {
nodes.push(children[i]);
}
}
}
while (node = next.pop()) {
callback(node);
callback.call(that, node, ++index, this);
}
return this;
}

@@ -1,7 +0,9 @@

export default function(callback) {
var node = this, nodes = [node], children, i;
export default function(callback, that) {
var node = this, nodes = [node], children, i, index = -1;
while (node = nodes.pop()) {
callback(node), children = node.children;
if (children) for (i = children.length - 1; i >= 0; --i) {
nodes.push(children[i]);
callback.call(that, node, ++index, this);
if (children = node.children) {
for (i = children.length - 1; i >= 0; --i) {
nodes.push(children[i]);
}
}

@@ -8,0 +10,0 @@ }

@@ -5,2 +5,3 @@ import node_count from "./count.js";

import node_eachAfter from "./eachAfter.js";
import node_find from "./find.js";
import node_sum from "./sum.js";

@@ -13,2 +14,3 @@ import node_sort from "./sort.js";

import node_links from "./links.js";
import node_iterator from "./iterator.js";

@@ -29,6 +31,6 @@ export default function hierarchy(data, children) {

if (valued) node.value = +node.data.value;
if ((childs = children(node.data)) && (n = childs.length)) {
node.children = new Array(n);
if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
node.children = childs;
for (i = n - 1; i >= 0; --i) {
nodes.push(child = node.children[i] = new Node(childs[i]));
nodes.push(child = childs[i] = new Node(childs[i]));
child.parent = node;

@@ -74,2 +76,3 @@ child.depth = node.depth + 1;

eachBefore: node_eachBefore,
find: node_find,
sum: node_sum,

@@ -82,3 +85,4 @@ sort: node_sort,

links: node_links,
copy: node_copy
copy: node_copy,
[Symbol.iterator]: node_iterator
};

@@ -1,5 +0,5 @@

import {shuffle, slice} from "../array.js";
import {shuffle} from "../array.js";
export default function(circles) {
var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
var i = 0, n = (circles = shuffle(Array.from(circles))).length, B = [], p, e;

@@ -6,0 +6,0 @@ while (i < n) {

@@ -0,1 +1,2 @@

import array from "../array.js";
import enclose from "./enclose.js";

@@ -48,3 +49,3 @@

export function packEnclose(circles) {
if (!(n = circles.length)) return 0;
if (!(n = (circles = array(circles)).length)) return 0;

@@ -51,0 +52,0 @@ var a, b, c, n, aa, ca, i, j, k, sj, sk;

import {required} from "./accessors.js";
import {Node, computeHeight} from "./hierarchy/index.js";
var keyPrefix = "$", // Protect against keys like “__proto__”.
preroot = {depth: -1},
var preroot = {depth: -1},
ambiguous = {};

@@ -21,28 +20,28 @@

function stratify(data) {
var d,
var nodes = Array.from(data),
n = nodes.length,
d,
i,
n = data.length,
root,
parent,
node,
nodes = new Array(n),
nodeId,
nodeKey,
nodeByKey = {};
nodeByKey = new Map;
for (i = 0; i < n; ++i) {
d = data[i], node = nodes[i] = new Node(d);
d = nodes[i], node = nodes[i] = new Node(d);
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
nodeKey = keyPrefix + (node.id = nodeId);
nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
nodeKey = node.id = nodeId;
nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
}
if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
node.parent = nodeId;
}
}
for (i = 0; i < n; ++i) {
node = nodes[i], nodeId = parentId(data[i], i, data);
if (nodeId == null || !(nodeId += "")) {
if (root) throw new Error("multiple roots");
root = node;
} else {
parent = nodeByKey[keyPrefix + nodeId];
node = nodes[i];
if (nodeId = node.parent) {
parent = nodeByKey.get(nodeId);
if (!parent) throw new Error("missing: " + nodeId);

@@ -53,2 +52,5 @@ if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);

node.parent = parent;
} else {
if (root) throw new Error("multiple roots");
root = node;
}

@@ -55,0 +57,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc