Socket
Socket
Sign inDemoInstall

d3-hierarchy

Package Overview
Dependencies
0
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.1.0

92

dist/d3-hierarchy.js

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

// https://d3js.org/d3-hierarchy/ v3.0.1 Copyright 2010-2021 Mike Bostock
// https://d3js.org/d3-hierarchy/ v3.1.0 Copyright 2010-2021 Mike Bostock
(function (global, factory) {

@@ -6,3 +6,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
}(this, (function (exports) { 'use strict';
})(this, (function (exports) { 'use strict';

@@ -748,3 +748,4 @@ function defaultSeparation$1(a, b) {

var preroot = {depth: -1},
ambiguous = {};
ambiguous = {},
imputed = {};

@@ -761,7 +762,10 @@ function defaultId(d) {

var id = defaultId,
parentId = defaultParentId;
parentId = defaultParentId,
path;
function stratify(data) {
var nodes = Array.from(data),
n = nodes.length,
currentId = id,
currentParentId = parentId,
n,
d,

@@ -776,9 +780,25 @@ i,

for (i = 0; i < n; ++i) {
if (path != null) {
const I = nodes.map((d, i) => normalize(path(d, i, data)));
const P = I.map(parentof);
const S = new Set(I).add("");
for (const i of P) {
if (!S.has(i)) {
S.add(i);
I.push(i);
P.push(parentof(i));
nodes.push(imputed);
}
}
currentId = (_, i) => I[i];
currentParentId = (_, i) => P[i];
}
for (i = 0, n = nodes.length; i < n; ++i) {
d = nodes[i], node = nodes[i] = new Node$1(d);
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
nodeKey = node.id = nodeId;
nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
}
if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
node.parent = nodeId;

@@ -804,2 +824,16 @@ }

if (!root) throw new Error("no root");
// When imputing internal nodes, only introduce roots if needed.
// Then replace the imputed marker data with null.
if (path != null) {
while (root.data === imputed && root.children.length === 1) {
root = root.children[0], --n;
}
for (let i = nodes.length - 1; i >= 0; --i) {
node = nodes[i];
if (node.data !== imputed) break;
node.data = null;
}
}
root.parent = preroot;

@@ -814,12 +848,48 @@ root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);

stratify.id = function(x) {
return arguments.length ? (id = required(x), stratify) : id;
return arguments.length ? (id = optional(x), stratify) : id;
};
stratify.parentId = function(x) {
return arguments.length ? (parentId = required(x), stratify) : parentId;
return arguments.length ? (parentId = optional(x), stratify) : parentId;
};
stratify.path = function(x) {
return arguments.length ? (path = optional(x), stratify) : path;
};
return stratify;
}
// To normalize a path, we coerce to a string, strip trailing slash if present,
// and add leading slash if missing. This requires counting the number of
// preceding backslashes which may be used to escape the forward slash: an odd
// number indicates an escaped forward slash.
function normalize(path) {
path = `${path}`;
let i = path.length - 1;
if (path[i] === "/") {
let k = 0;
while (i > 0 && path[--i] === "\\") ++k;
if ((k & 1) === 0) path = path.slice(0, -1);
}
return path[0] === "/" ? path : `/${path}`;
}
// Walk backwards to find the first slash that is not the leading slash, e.g.:
// "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
// because the id of the root must be a truthy value.) The slash may be escaped,
// which again requires counting the number of preceding backslashes. Note that
// normalized paths cannot end with a slash except for the root.
function parentof(path) {
let i = path.length;
while (i > 2) {
if (path[--i] === "/") {
let j = i, k = 0;
while (j > 0 && path[--j] === "\\") ++k;
if ((k & 1) === 0) break;
}
}
return path.slice(0, i < 3 ? i - 1 : i);
}
function defaultSeparation(a, b) {

@@ -1331,2 +1401,2 @@ return a.parent === b.parent ? 1 : 2;

})));
}));

4

dist/d3-hierarchy.min.js

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

// https://d3js.org/d3-hierarchy/ v3.0.1 Copyright 2010-2021 Mike Bostock
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n="undefined"!=typeof globalThis?globalThis: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){n instanceof Map?(n=[void 0,n],void 0===r&&(r=a)):void 0===r&&(r=o);for(var t,e,i,u,f,l=new h(n),p=[l];t=p.pop();)if((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 h(i[u])),e.parent=t,e.depth=t.depth+1;return l.eachBefore(c)}function o(n){return n.children}function a(n){return Array.isArray(n)?n[1]:null}function f(n){void 0!==n.data.value&&(n.value=n.data.value),n.data=n.data.data}function c(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function h(n){this.data=n,this.depth=this.height=0,this.parent=null}function l(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&&s(t,r)?++e:(t=x(u=p(u,r)),e=0);return t}function p(n,r){var t,e;if(v(r,n))return[r];for(t=0;t<n.length;++t)if(d(r,n[t])&&v(y(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(d(y(n[t],n[e]),r)&&d(y(n[t],r),n[e])&&d(y(n[e],r),n[t])&&v(g(n[t],n[e],r),n))return[n[t],n[e],r];throw new Error}function d(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 s(n,r){var t=n.r-r.r+1e-9*Math.max(n.r,r.r,1),e=r.x-n.x,i=r.y-n.y;return t>0&&t*t>e*e+i*i}function v(n,r){for(var t=0;t<r.length;++t)if(!s(n,r[t]))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 t=n.x,e=n.y,i=n.r,u=r.x,o=r.y,a=r.r,f=u-t,c=o-e,h=a-i,l=Math.sqrt(f*f+c*c);return{x:(t+u+f/l*h)/2,y:(e+o+c/l*h)/2,r:(l+i+a)/2}}function g(n,r,t){var e=n.x,i=n.y,u=n.r,o=r.x,a=r.y,f=r.r,c=t.x,h=t.y,l=t.r,p=e-o,d=e-c,s=i-a,v=i-h,x=f-u,y=l-u,g=e*e+i*i-u*u,m=g-o*o-a*a+f*f,w=g-c*c-h*h+l*l,_=d*s-p*v,M=(s*w-v*m)/(2*_)-e,z=(v*x-s*y)/_,B=(d*m-p*w)/(2*_)-i,A=(p*y-d*x)/_,b=z*z+A*A-1,q=2*(u+M*z+B*A),E=M*M+B*B-u*u,S=-(b?(q+Math.sqrt(q*q-4*b*E))/(2*b):E/q);return{x:e+M+z*S,y:i+B+A*S,r:S}}function m(n,r,t){var e,i,u,o,a=n.x-r.x,f=n.y-r.y,c=a*a+f*f;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*a-u*f,t.y=n.y-e*f+u*a):(e=(c+i-o)/(2*c),u=Math.sqrt(Math.max(0,i/c-e*e)),t.x=r.x+e*a-u*f,t.y=r.y+e*f+u*a)):(t.x=r.x+t.r,t.y=r.y)}function w(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 _(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 Node(n){this._=n,this.next=null,this.previous=null}function M(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,a,f,c,h,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;m(e,t,i=n[2]),t=new Node(t),e=new Node(e),i=new Node(i),t.next=i.previous=e,e.next=t.previous=i,i.next=e.previous=t;n:for(f=3;f<u;++f){m(t._,e._,i=n[f]),i=new Node(i),c=e.next,h=t.previous,p=e._.r,d=t._.r;do{if(p<=d){if(w(c._,i._)){e=c,t.next=e,e.previous=t,--f;continue n}p+=c._.r,c=c.next}else{if(w(h._,i._)){(t=h).next=e,e.previous=t,--f;continue n}d+=h._.r,h=h.previous}}while(c!==h.next);for(i.previous=t,i.next=e,t.next=e.previous=e=i,o=_(t);(i=i.next)!==e;)(a=_(i))<o&&(t=i,o=a);e=t.next}for(t=[e._],i=e;(i=i.next)!==e;)t.push(i._);for(i=l(t),f=0;f<u;++f)(t=n[f]).x-=i.x,t.y-=i.y;return i.r}function z(n){return null==n?null:B(n)}function B(n){if("function"!=typeof n)throw new Error;return n}function A(){return 0}function b(n){return function(){return n}}function q(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,a=n(t)*r||0;if(a)for(i=0;i<o;++i)e[i].r+=a;if(u=M(e),a)for(i=0;i<o;++i)e[i].r-=a;t.r=u+a}}}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 T(n,r,t,e,i){for(var u,o=n.children,a=-1,f=o.length,c=n.value&&(e-r)/n.value;++a<f;)(u=o[a]).y0=t,u.y1=i,u.x0=r,u.x1=r+=u.value*c}h.prototype=u.prototype={constructor:h,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],a=[],f=-1;u=o.pop();)if(a.push(u),t=u.children)for(e=0,i=t.length;e<i;++e)o.push(t[e]);for(;u=a.pop();)n.call(r,u,++f,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;n=t.pop(),r=e.pop();for(;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 j={depth:-1},O={};function R(n){return n.id}function D(n){return n.parentId}function L(n,r){return n.parent===r.parent?1:2}function N(n){var r=n.children;return r?r[0]:n.t}function P(n){var r=n.children;return r?r[r.length-1]:n.t}function C(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 F(n,r,t){return n.a.parent===r.parent?n.a:t}function G(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 H(n,r,t,e,i){for(var u,o=n.children,a=-1,f=o.length,c=n.value&&(i-t)/n.value;++a<f;)(u=o[a]).x0=r,u.x1=e,u.y0=t,u.y1=t+=u.value*c}G.prototype=Object.create(h.prototype);var J=(1+Math.sqrt(5))/2;function K(n,r,t,e,i,u){for(var o,a,f,c,h,l,p,d,s,v,x,y=[],g=r.children,m=0,w=0,_=g.length,M=r.value;m<_;){f=i-t,c=u-e;do{h=g[w++].value}while(!h&&w<_);for(l=p=h,x=h*h*(v=Math.max(c/f,f/c)/(M*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?T(o,t,e,i,M?e+=c*h/M:u):H(o,t,e,M?t+=f*h/M:i,u),M-=h,m=w}return y}var Q=function n(r){function t(n,t,e,i,u){K(r,n,t,e,i,u)}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(J);var U=function n(r){function t(n,t,e,i,u){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?T(a,t,e,i,d?e+=(u-e)*a.value/d:u):H(a,t,e,d?t+=(i-t)*a.value/d:i,u),d-=a.value}else n._squarify=o=K(r,n,t,e,i,u),o.ratio=r}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(J);n.Node=h,n.cluster=function(){var n=r,i=1,u=1,o=!1;function a(r){var a,f=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=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)*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 a.separation=function(r){return arguments.length?(n=r,a):n},a.size=function(n){return arguments.length?(o=!1,i=+n[0],u=+n[1],a):o?null:[i,u]},a.nodeSize=function(n){return arguments.length?(o=!0,i=+n[0],u=+n[1],a):o?[i,u]:null},a},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(q)).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=z(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:b(+n),i):e},i},n.packEnclose=l,n.packSiblings=function(n){return M(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&&T(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,a=e.y1-t;o<i&&(i=o=(i+o)/2),a<u&&(u=a=(u+a)/2),e.x0=i,e.y0=u,e.x1=o,e.y1=a}}(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=R,r=D;function t(t){var e,i,u,o,a,f,l,p=Array.from(t),d=p.length,s=new Map;for(i=0;i<d;++i)e=p[i],a=p[i]=new h(e),null!=(f=n(e,i,t))&&(f+="")&&(l=a.id=f,s.set(l,s.has(l)?O:a)),null!=(f=r(e,i,t))&&(f+="")&&(a.parent=f);for(i=0;i<d;++i)if(f=(a=p[i]).parent){if(!(o=s.get(f)))throw new Error("missing: "+f);if(o===O)throw new Error("ambiguous: "+f);o.children?o.children.push(a):o.children=[a],a.parent=o}else{if(u)throw new Error("multiple roots");u=a}if(!u)throw new Error("no root");if(u.parent=j,u.eachBefore((function(n){n.depth=n.parent.depth+1,--d})).eachBefore(c),u.parent=null,d>0)throw new Error("cycle");return u}return t.id=function(r){return arguments.length?(n=B(r),t):n},t.parentId=function(n){return arguments.length?(r=B(n),t):r},t},n.tree=function(){var n=L,r=1,t=1,e=null;function i(i){var f=function(n){for(var r,t,e,i,u,o=new G(n,0),a=[o];r=a.pop();)if(e=r._.children)for(r.children=new Array(u=e.length),i=u-1;i>=0;--i)a.push(t=r.children[i]=new G(e[i],i)),t.parent=r;return(o.parent=new G(null,0)).children=[o],o}(i);if(f.eachAfter(u),f.parent.m=-f.z,f.eachBefore(o),e)i.eachBefore(a);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,a=t,f=u.parent.children[0],c=u.m,h=o.m,l=a.m,p=f.m;a=P(a),u=N(u),a&&u;)f=N(f),(o=P(o)).a=r,(i=a.z+l-u.z-c+n(a._,u._))>0&&(C(F(a,r,e),r,i),c+=i,h+=i),l+=a.m,c+=u.m,p+=f.m,h+=o.m;a&&!P(o)&&(o.t=a,o.m+=l-h),u&&!N(f)&&(f.t=u,f.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 a(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,a=A,f=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-=a(r)-t)<e&&(e=l=(e+l)/2),(p-=f(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=B(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:b(+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:b(+n),h):o},h.paddingRight=function(n){return arguments.length?(a="function"==typeof n?n:b(+n),h):a},h.paddingBottom=function(n){return arguments.length?(f="function"==typeof n?n:b(+n),h):f},h.paddingLeft=function(n){return arguments.length?(c="function"==typeof n?n:b(+n),h):c},h},n.treemapBinary=function(n,r,t,e,i){var u,o,a=n.children,f=a.length,c=new Array(f+1);for(c[0]=o=u=0;u<f;++u)c[u+1]=o+=a[u].value;!function n(r,t,e,i,u,o,f){if(r>=t-1){var h=a[r];return h.x0=i,h.y0=u,h.x1=o,void(h.y1=f)}var l=c[r],p=e/2+l,d=r+1,s=t-1;for(;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>f-u){var g=e?(i*y+o*x)/e:o;n(r,d,x,i,u,g,f),n(d,t,y,g,u,o,f)}else{var m=e?(u*y+f*x)/e:f;n(r,d,x,i,u,o,m),n(d,t,y,i,m,o,f)}}(0,f,n.value,r,t,e,i)},n.treemapDice=T,n.treemapResquarify=U,n.treemapSlice=H,n.treemapSliceDice=function(n,r,t,e,i){(1&n.depth?H:T)(n,r,t,e,i)},n.treemapSquarify=Q,Object.defineProperty(n,"__esModule",{value:!0})}));
// https://d3js.org/d3-hierarchy/ v3.1.0 Copyright 2010-2021 Mike Bostock
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n="undefined"!=typeof globalThis?globalThis: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){n instanceof Map?(n=[void 0,n],void 0===r&&(r=a)):void 0===r&&(r=o);for(var t,e,i,u,f,l=new h(n),p=[l];t=p.pop();)if((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 h(i[u])),e.parent=t,e.depth=t.depth+1;return l.eachBefore(c)}function o(n){return n.children}function a(n){return Array.isArray(n)?n[1]:null}function f(n){void 0!==n.data.value&&(n.value=n.data.value),n.data=n.data.data}function c(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function h(n){this.data=n,this.depth=this.height=0,this.parent=null}function l(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&&s(t,r)?++e:(t=x(u=p(u,r)),e=0);return t}function p(n,r){var t,e;if(v(r,n))return[r];for(t=0;t<n.length;++t)if(d(r,n[t])&&v(y(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(d(y(n[t],n[e]),r)&&d(y(n[t],r),n[e])&&d(y(n[e],r),n[t])&&v(g(n[t],n[e],r),n))return[n[t],n[e],r];throw new Error}function d(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 s(n,r){var t=n.r-r.r+1e-9*Math.max(n.r,r.r,1),e=r.x-n.x,i=r.y-n.y;return t>0&&t*t>e*e+i*i}function v(n,r){for(var t=0;t<r.length;++t)if(!s(n,r[t]))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 t=n.x,e=n.y,i=n.r,u=r.x,o=r.y,a=r.r,f=u-t,c=o-e,h=a-i,l=Math.sqrt(f*f+c*c);return{x:(t+u+f/l*h)/2,y:(e+o+c/l*h)/2,r:(l+i+a)/2}}function g(n,r,t){var e=n.x,i=n.y,u=n.r,o=r.x,a=r.y,f=r.r,c=t.x,h=t.y,l=t.r,p=e-o,d=e-c,s=i-a,v=i-h,x=f-u,y=l-u,g=e*e+i*i-u*u,m=g-o*o-a*a+f*f,w=g-c*c-h*h+l*l,_=d*s-p*v,M=(s*w-v*m)/(2*_)-e,z=(v*x-s*y)/_,B=(d*m-p*w)/(2*_)-i,A=(p*y-d*x)/_,b=z*z+A*A-1,q=2*(u+M*z+B*A),E=M*M+B*B-u*u,S=-(b?(q+Math.sqrt(q*q-4*b*E))/(2*b):E/q);return{x:e+M+z*S,y:i+B+A*S,r:S}}function m(n,r,t){var e,i,u,o,a=n.x-r.x,f=n.y-r.y,c=a*a+f*f;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*a-u*f,t.y=n.y-e*f+u*a):(e=(c+i-o)/(2*c),u=Math.sqrt(Math.max(0,i/c-e*e)),t.x=r.x+e*a-u*f,t.y=r.y+e*f+u*a)):(t.x=r.x+t.r,t.y=r.y)}function w(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 _(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 Node(n){this._=n,this.next=null,this.previous=null}function M(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,a,f,c,h,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;m(e,t,i=n[2]),t=new Node(t),e=new Node(e),i=new Node(i),t.next=i.previous=e,e.next=t.previous=i,i.next=e.previous=t;n:for(f=3;f<u;++f){m(t._,e._,i=n[f]),i=new Node(i),c=e.next,h=t.previous,p=e._.r,d=t._.r;do{if(p<=d){if(w(c._,i._)){e=c,t.next=e,e.previous=t,--f;continue n}p+=c._.r,c=c.next}else{if(w(h._,i._)){(t=h).next=e,e.previous=t,--f;continue n}d+=h._.r,h=h.previous}}while(c!==h.next);for(i.previous=t,i.next=e,t.next=e.previous=e=i,o=_(t);(i=i.next)!==e;)(a=_(i))<o&&(t=i,o=a);e=t.next}for(t=[e._],i=e;(i=i.next)!==e;)t.push(i._);for(i=l(t),f=0;f<u;++f)(t=n[f]).x-=i.x,t.y-=i.y;return i.r}function z(n){return null==n?null:B(n)}function B(n){if("function"!=typeof n)throw new Error;return n}function A(){return 0}function b(n){return function(){return n}}function q(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,a=n(t)*r||0;if(a)for(i=0;i<o;++i)e[i].r+=a;if(u=M(e),a)for(i=0;i<o;++i)e[i].r-=a;t.r=u+a}}}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 T(n,r,t,e,i){for(var u,o=n.children,a=-1,f=o.length,c=n.value&&(e-r)/n.value;++a<f;)(u=o[a]).y0=t,u.y1=i,u.x0=r,u.x1=r+=u.value*c}h.prototype=u.prototype={constructor:h,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],a=[],f=-1;u=o.pop();)if(a.push(u),t=u.children)for(e=0,i=t.length;e<i;++e)o.push(t[e]);for(;u=a.pop();)n.call(r,u,++f,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;n=t.pop(),r=e.pop();for(;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 j={depth:-1},O={},R={};function D(n){return n.id}function L(n){return n.parentId}function $(n){let r=n.length;for(;r>2;)if("/"===n[--r]){let t=r,e=0;for(;t>0&&"\\"===n[--t];)++e;if(0==(1&e))break}return n.slice(0,r<3?r-1:r)}function N(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,a=-1,f=o.length,c=n.value&&(i-t)/n.value;++a<f;)(u=o[a]).x0=r,u.x1=e,u.y0=t,u.y1=t+=u.value*c}H.prototype=Object.create(h.prototype);var K=(1+Math.sqrt(5))/2;function Q(n,r,t,e,i,u){for(var o,a,f,c,h,l,p,d,s,v,x,y=[],g=r.children,m=0,w=0,_=g.length,M=r.value;m<_;){f=i-t,c=u-e;do{h=g[w++].value}while(!h&&w<_);for(l=p=h,x=h*h*(v=Math.max(c/f,f/c)/(M*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?T(o,t,e,i,M?e+=c*h/M:u):J(o,t,e,M?t+=f*h/M:i,u),M-=h,m=w}return y}var U=function n(r){function t(n,t,e,i,u){Q(r,n,t,e,i,u)}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(K);var V=function n(r){function t(n,t,e,i,u){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?T(a,t,e,i,d?e+=(u-e)*a.value/d:u):J(a,t,e,d?t+=(i-t)*a.value/d:i,u),d-=a.value}else n._squarify=o=Q(r,n,t,e,i,u),o.ratio=r}return t.ratio=function(r){return n((r=+r)>1?r:1)},t}(K);n.Node=h,n.cluster=function(){var n=r,i=1,u=1,o=!1;function a(r){var a,f=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=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)*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 a.separation=function(r){return arguments.length?(n=r,a):n},a.size=function(n){return arguments.length?(o=!1,i=+n[0],u=+n[1],a):o?null:[i,u]},a.nodeSize=function(n){return arguments.length?(o=!0,i=+n[0],u=+n[1],a):o?[i,u]:null},a},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(q)).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=z(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:b(+n),i):e},i},n.packEnclose=l,n.packSiblings=function(n){return M(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&&T(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,a=e.y1-t;o<i&&(i=o=(i+o)/2),a<u&&(u=a=(u+a)/2),e.x0=i,e.y0=u,e.x1=o,e.y1=a}}(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,r=D,t=L;function e(e){var i,u,o,a,f,l,p,d,s=Array.from(e),v=r,x=t,y=new Map;if(null!=n){const r=s.map(((r,t)=>function(n){let r=(n=`${n}`).length-1;if("/"===n[r]){let t=0;for(;r>0&&"\\"===n[--r];)++t;0==(1&t)&&(n=n.slice(0,-1))}return"/"===n[0]?n:`/${n}`}(n(r,t,e)))),t=r.map($),i=new Set(r).add("");for(const n of t)i.has(n)||(i.add(n),r.push(n),t.push($(n)),s.push(R));v=(n,t)=>r[t],x=(n,r)=>t[r]}for(o=0,i=s.length;o<i;++o)u=s[o],l=s[o]=new h(u),null!=(p=v(u,o,e))&&(p+="")&&(d=l.id=p,y.set(d,y.has(d)?O:l)),null!=(p=x(u,o,e))&&(p+="")&&(l.parent=p);for(o=0;o<i;++o)if(p=(l=s[o]).parent){if(!(f=y.get(p)))throw new Error("missing: "+p);if(f===O)throw new Error("ambiguous: "+p);f.children?f.children.push(l):f.children=[l],l.parent=f}else{if(a)throw new Error("multiple roots");a=l}if(!a)throw new Error("no root");if(null!=n){for(;a.data===R&&1===a.children.length;)a=a.children[0],--i;for(let n=s.length-1;n>=0&&(l=s[n],l.data===R);--n)l.data=null}if(a.parent=j,a.eachBefore((function(n){n.depth=n.parent.depth+1,--i})).eachBefore(c),a.parent=null,i>0)throw new Error("cycle");return a}return e.id=function(n){return arguments.length?(r=z(n),e):r},e.parentId=function(n){return arguments.length?(t=z(n),e):t},e.path=function(r){return arguments.length?(n=z(r),e):n},e},n.tree=function(){var n=N,r=1,t=1,e=null;function i(i){var f=function(n){for(var r,t,e,i,u,o=new H(n,0),a=[o];r=a.pop();)if(e=r._.children)for(r.children=new Array(u=e.length),i=u-1;i>=0;--i)a.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(f.eachAfter(u),f.parent.m=-f.z,f.eachBefore(o),e)i.eachBefore(a);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,a=t,f=u.parent.children[0],c=u.m,h=o.m,l=a.m,p=f.m;a=C(a),u=P(u),a&&u;)f=P(f),(o=C(o)).a=r,(i=a.z+l-u.z-c+n(a._,u._))>0&&(F(G(a,r,e),r,i),c+=i,h+=i),l+=a.m,c+=u.m,p+=f.m,h+=o.m;a&&!C(o)&&(o.t=a,o.m+=l-h),u&&!P(f)&&(f.t=u,f.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 a(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=U,r=!1,t=1,e=1,i=[0],u=A,o=A,a=A,f=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-=a(r)-t)<e&&(e=l=(e+l)/2),(p-=f(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=B(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:b(+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:b(+n),h):o},h.paddingRight=function(n){return arguments.length?(a="function"==typeof n?n:b(+n),h):a},h.paddingBottom=function(n){return arguments.length?(f="function"==typeof n?n:b(+n),h):f},h.paddingLeft=function(n){return arguments.length?(c="function"==typeof n?n:b(+n),h):c},h},n.treemapBinary=function(n,r,t,e,i){var u,o,a=n.children,f=a.length,c=new Array(f+1);for(c[0]=o=u=0;u<f;++u)c[u+1]=o+=a[u].value;!function n(r,t,e,i,u,o,f){if(r>=t-1){var h=a[r];return h.x0=i,h.y0=u,h.x1=o,void(h.y1=f)}var l=c[r],p=e/2+l,d=r+1,s=t-1;for(;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>f-u){var g=e?(i*y+o*x)/e:o;n(r,d,x,i,u,g,f),n(d,t,y,g,u,o,f)}else{var m=e?(u*y+f*x)/e:f;n(r,d,x,i,u,o,m),n(d,t,y,i,m,o,f)}}(0,f,n.value,r,t,e,i)},n.treemapDice=T,n.treemapResquarify=V,n.treemapSlice=J,n.treemapSliceDice=function(n,r,t,e,i){(1&n.depth?J:T)(n,r,t,e,i)},n.treemapSquarify=U,Object.defineProperty(n,"__esModule",{value:!0})}));
{
"name": "d3-hierarchy",
"version": "3.0.1",
"version": "3.1.0",
"description": "Layout algorithms for visualizing hierarchical data.",

@@ -40,7 +40,7 @@ "homepage": "https://d3js.org/d3-hierarchy/",

"benchmark": "2",
"d3-array": "1.2.0 - 2",
"d3-dsv": "1 - 2",
"d3-array": "1.2.0 - 3",
"d3-dsv": "1 - 3",
"d3-random": "1.1.0 - 3",
"eslint": "7",
"mocha": "8",
"eslint": "8",
"mocha": "9",
"rollup": "2",

@@ -47,0 +47,0 @@ "rollup-plugin-terser": "7"

@@ -53,3 +53,3 @@ # d3-hierarchy

<a name="hierarchy" href="#hierarchy">#</a> d3.<b>hierarchy</b>(<i>data</i>[, <i>children</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="hierarchy" href="#hierarchy">#</a> d3.<b>hierarchy</b>(<i>data</i>[, <i>children</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)

@@ -110,3 +110,3 @@ Constructs a root node from the specified hierarchical *data*. The specified *data* must be an object representing the root node. For example:

This allows you to pass the result of [d3.group](https://github.com/d3/d3-array/blob/master/README.md#group) or [d3.rollup](https://github.com/d3/d3-array/blob/master/README.md#rollup) to d3.hierarchy.
This allows you to pass the result of [d3.group](https://github.com/d3/d3-array/blob/main/README.md#group) or [d3.rollup](https://github.com/d3/d3-array/blob/main/README.md#rollup) to d3.hierarchy.

@@ -124,27 +124,27 @@ The returned node and each descendant has the following properties:

<a name="node_ancestors" href="#node_ancestors">#</a> <i>node</i>.<b>ancestors</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/ancestors.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="node_ancestors" href="#node_ancestors">#</a> <i>node</i>.<b>ancestors</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/ancestors.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
Returns the array of ancestors nodes, starting with this node, then followed by each parent up to the root.
<a name="node_descendants" href="#node_descendants">#</a> <i>node</i>.<b>descendants</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/descendants.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="node_descendants" href="#node_descendants">#</a> <i>node</i>.<b>descendants</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/descendants.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
Returns the array of descendant nodes, starting with this node, then followed by each child in topological order.
<a name="node_leaves" href="#node_leaves">#</a> <i>node</i>.<b>leaves</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/leaves.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="node_leaves" href="#node_leaves">#</a> <i>node</i>.<b>leaves</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/leaves.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
Returns the array of leaf nodes in traversal order; leaves are nodes with no children.
<a name="node_find" href="#node_find">#</a> <i>node</i>.<b>find</b>(<i>filter</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/find.js)<!-- , [Examples](https://observablehq.com/@d3/d3-hierarchy) -->
<a name="node_find" href="#node_find">#</a> <i>node</i>.<b>find</b>(<i>filter</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/find.js)<!-- , [Examples](https://observablehq.com/@d3/d3-hierarchy) -->
Returns the first node in the hierarchy from this *node* for which the specified *filter* returns a truthy value. undefined if no such node is found.
<a name="node_path" href="#node_path">#</a> <i>node</i>.<b>path</b>(<i>target</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/path.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="node_path" href="#node_path">#</a> <i>node</i>.<b>path</b>(<i>target</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/path.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
Returns the shortest path through the hierarchy from this *node* to the specified *target* node. The path starts at this *node*, ascends to the least common ancestor of this *node* and the *target* node, and then descends to the *target* node. This is particularly useful for [hierarchical edge bundling](https://observablehq.com/@d3/hierarchical-edge-bundling).
<a name="node_links" href="#node_links">#</a> <i>node</i>.<b>links</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/links.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
<a name="node_links" href="#node_links">#</a> <i>node</i>.<b>links</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/links.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
Returns an array of links for this *node* and its descendants, where each *link* is an object that defines source and target properties. The source of each link is the parent node, and the target is a child node.
<a name="node_sum" href="#node_sum">#</a> <i>node</i>.<b>sum</b>(<i>value</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/sum.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
<a name="node_sum" href="#node_sum">#</a> <i>node</i>.<b>sum</b>(<i>value</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/sum.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)

@@ -172,7 +172,7 @@ Evaluates the specified *value* function for this *node* and each descendant in [post-order traversal](#node_eachAfter), and returns this *node*. The *node*.value property of each node is set to the numeric value returned by the specified function plus the combined value of all children. The function is passed the node’s data, and must return a non-negative number. The *value* accessor is evaluated for *node* and every descendant, including internal nodes; if you only want leaf nodes to have internal value, then return zero for any node with children. [For example](https://observablehq.com/@d3/treemap-by-count), as an alternative to [*node*.count](#node_count):

<a name="node_count" href="#node_count">#</a> <i>node</i>.<b>count</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/count.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
<a name="node_count" href="#node_count">#</a> <i>node</i>.<b>count</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/count.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
Computes the number of leaves under this *node* and assigns it to *node*.value, and similarly for every descendant of *node*. If this *node* is a leaf, its count is one. Returns this *node*. See also [*node*.sum](#node_sum).
<a name="node_sort" href="#node_sort">#</a> <i>node</i>.<b>sort</b>(<i>compare</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/sort.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
<a name="node_sort" href="#node_sort">#</a> <i>node</i>.<b>sort</b>(<i>compare</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/sort.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)

@@ -207,3 +207,3 @@ Sorts the children of this *node*, if any, and each of this *node*’s descendants’ children, in [pre-order traversal](#node_eachBefore) using the specified *compare* function, and returns this *node*. The specified function is passed two nodes *a* and *b* to compare. If *a* should be before *b*, the function must return a value less than zero; if *b* should be before *a*, the function must return a value greater than zero; otherwise, the relative order of *a* and *b* are not specified. See [*array*.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) for more.

<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")
<a name="node_iterator" href="#node_iterator">#</a> <i>node</i>\[<b>Symbol.iterator</b>\]() [<>](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/iterator.js "Source")

@@ -218,15 +218,15 @@ Returns an iterator over the *node*’s descendants in breadth-first order. For example:

<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_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/main/src/hierarchy/each.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.
<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)
<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/main/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)
<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/main/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)
<a name="node_copy" href="#node_copy">#</a> <i>node</i>.<b>copy</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)

@@ -299,15 +299,15 @@ Return a deep copy of the subtree starting at this *node*. (The returned deep copy shares the same data, however.) The returned node is the root of a new tree; the returned node’s parent is always null and its depth is always zero.

[<img alt="Stratify" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/stratify.png">](https://runkit.com/mbostock/56fed33d8630b01300f72daa)
[<img alt="Stratify" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/stratify.png">](https://runkit.com/mbostock/56fed33d8630b01300f72daa)
This hierarchy can now be passed to a hierarchical layout, such as [d3.tree](#_tree), for visualization.
<a name="stratify" href="#stratify">#</a> d3.<b>stratify</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
<a name="stratify" href="#stratify">#</a> d3.<b>stratify</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
Constructs a new stratify operator with the default settings.
<a name="_stratify" href="#_stratify">#</a> <i>stratify</i>(<i>data</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
<a name="_stratify" href="#_stratify">#</a> <i>stratify</i>(<i>data</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
Generates a new hierarchy from the specified tabular *data*.
<a name="stratify_id" href="#stratify_id">#</a> <i>stratify</i>.<b>id</b>([<i>id</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
<a name="stratify_id" href="#stratify_id">#</a> <i>stratify</i>.<b>id</b>([<i>id</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)

@@ -324,3 +324,3 @@ If *id* is specified, sets the id accessor to the given function and returns this stratify operator. Otherwise, returns the current id accessor, which defaults to:

<a name="stratify_parentId" href="#stratify_parentId">#</a> <i>stratify</i>.<b>parentId</b>([<i>parentId</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
<a name="stratify_parentId" href="#stratify_parentId">#</a> <i>stratify</i>.<b>parentId</b>([<i>parentId</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)

@@ -337,9 +337,17 @@ If *parentId* is specified, sets the parent id accessor to the given function and returns this stratify operator. Otherwise, returns the current parent id accessor, which defaults to:

<a name="stratify_path" href="#stratify_path">#</a> <i>stratify</i>.<b>path</b>([<i>path</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
If *path* is specified, sets the path accessor to the given function and returns this stratify operator. Otherwise, returns the current path accessor, which defaults to undefined. If a path accessor is set, the id and parentId arguments are ignored, and a unix-like hierarchy is computed on the slash-delimited strings returned by the path accessor, imputing parent nodes and ids as necessary.
```js
d3.stratify().path(d => d)(["a/b", "a/c"]); // nodes with id "/a", "/a/b", "/a/c"
```
### Cluster
[<img alt="Dendrogram" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/cluster.png">](https://observablehq.com/@d3/cluster-dendrogram)
[<img alt="Dendrogram" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/cluster.png">](https://observablehq.com/@d3/cluster-dendrogram)
The **cluster layout** produces [dendrograms](http://en.wikipedia.org/wiki/Dendrogram): node-link diagrams that place leaf nodes of the tree at the same depth. Dendrograms are typically less compact than [tidy trees](#tree), but are useful when all the leaves should be at the same level, such as for hierarchical clustering or [phylogenetic tree diagrams](https://observablehq.com/@mbostock/tree-of-life).
<a name="cluster" href="#cluster">#</a> d3.<b>cluster</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/cluster.js), [Examples](https://observablehq.com/@d3/cluster-dendrogram)
<a name="cluster" href="#cluster">#</a> d3.<b>cluster</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/cluster.js), [Examples](https://observablehq.com/@d3/cluster-dendrogram)

@@ -379,7 +387,7 @@ Creates a new cluster layout with default settings.

[<img alt="Tidy Tree" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/tree.png">](https://observablehq.com/@d3/tidy-tree)
[<img alt="Tidy Tree" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/tree.png">](https://observablehq.com/@d3/tidy-tree)
The **tree** layout produces tidy node-link diagrams of trees using the [Reingold–Tilford “tidy” algorithm](http://reingold.co/tidier-drawings.pdf), improved to run in linear time by [Buchheim *et al.*](http://dirk.jivas.de/papers/buchheim02improving.pdf) Tidy trees are typically more compact than [dendrograms](#cluster).
<a name="tree" href="#tree">#</a> d3.<b>tree</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/tree.js), [Examples](https://observablehq.com/@d3/tidy-tree)
<a name="tree" href="#tree">#</a> d3.<b>tree</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/tree.js), [Examples](https://observablehq.com/@d3/tidy-tree)

@@ -427,7 +435,7 @@ Creates a new tree layout with default settings.

[<img alt="Treemap" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/treemap.png">](https://observablehq.com/@d3/treemap)
[<img alt="Treemap" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/treemap.png">](https://observablehq.com/@d3/treemap)
Introduced by [Ben Shneiderman](http://www.cs.umd.edu/hcil/treemap-history/) in 1991, a **treemap** recursively subdivides area into rectangles according to each node’s associated value. D3’s treemap implementation supports an extensible [tiling method](#treemap_tile): the default [squarified](#treemapSquarify) method seeks to generate rectangles with a [golden](https://en.wikipedia.org/wiki/Golden_ratio) aspect ratio; this offers better readability and size estimation than [slice-and-dice](#treemapSliceDice), which simply alternates between horizontal and vertical subdivision by depth.
<a name="treemap" href="#treemap">#</a> d3.<b>treemap</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/index.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemap" href="#treemap">#</a> d3.<b>treemap</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/index.js), [Examples](https://observablehq.com/@d3/treemap)

@@ -491,27 +499,27 @@ Creates a new treemap layout with default settings.

<a name="treemapBinary" href="#treemapBinary">#</a> d3.<b>treemapBinary</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/binary.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemapBinary" href="#treemapBinary">#</a> d3.<b>treemapBinary</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/binary.js), [Examples](https://observablehq.com/@d3/treemap)
Recursively partitions the specified *nodes* into an approximately-balanced binary tree, choosing horizontal partitioning for wide rectangles and vertical partitioning for tall rectangles.
<a name="treemapDice" href="#treemapDice">#</a> d3.<b>treemapDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/dice.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemapDice" href="#treemapDice">#</a> d3.<b>treemapDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/dice.js), [Examples](https://observablehq.com/@d3/treemap)
Divides the rectangular area specified by *x0*, *y0*, *x1*, *y1* horizontally according the value of each of the specified *node*’s children. The children are positioned in order, starting with the left edge (*x0*) of the given rectangle. If the sum of the children’s values is less than the specified *node*’s value (*i.e.*, if the specified *node* has a non-zero internal value), the remaining empty space will be positioned on the right edge (*x1*) of the given rectangle.
<a name="treemapSlice" href="#treemapSlice">#</a> d3.<b>treemapSlice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/slice.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemapSlice" href="#treemapSlice">#</a> d3.<b>treemapSlice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/slice.js), [Examples](https://observablehq.com/@d3/treemap)
Divides the rectangular area specified by *x0*, *y0*, *x1*, *y1* vertically according the value of each of the specified *node*’s children. The children are positioned in order, starting with the top edge (*y0*) of the given rectangle. If the sum of the children’s values is less than the specified *node*’s value (*i.e.*, if the specified *node* has a non-zero internal value), the remaining empty space will be positioned on the bottom edge (*y1*) of the given rectangle.
<a name="treemapSliceDice" href="#treemapSliceDice">#</a> d3.<b>treemapSliceDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/sliceDice.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemapSliceDice" href="#treemapSliceDice">#</a> d3.<b>treemapSliceDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/sliceDice.js), [Examples](https://observablehq.com/@d3/treemap)
If the specified *node* has odd depth, delegates to [treemapSlice](#treemapSlice); otherwise delegates to [treemapDice](#treemapDice).
<a name="treemapSquarify" href="#treemapSquarify">#</a> d3.<b>treemapSquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="treemapSquarify" href="#treemapSquarify">#</a> d3.<b>treemapSquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)
Implements the [squarified treemap](https://www.win.tue.nl/~vanwijk/stm.pdf) algorithm by Bruls *et al.*, which seeks to produce rectangles of a given [aspect ratio](#squarify_ratio).
<a name="treemapResquarify" href="#treemapResquarify">#</a> d3.<b>treemapResquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/resquarify.js), [Examples](https://observablehq.com/@d3/animated-treemap)
<a name="treemapResquarify" href="#treemapResquarify">#</a> d3.<b>treemapResquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/resquarify.js), [Examples](https://observablehq.com/@d3/animated-treemap)
Like [d3.treemapSquarify](#treemapSquarify), except preserves the topology (node adjacencies) of the previous layout computed by d3.treemapResquarify, if there is one and it used the same [target aspect ratio](#squarify_ratio). This tiling method is good for animating changes to treemaps because it only changes node sizes and not their relative positions, thus avoiding distracting shuffling and occlusion. The downside of a stable update, however, is a suboptimal layout for subsequent updates: only the first layout uses the Bruls *et al.* squarified algorithm.
<a name="squarify_ratio" href="#squarify_ratio">#</a> <i>squarify</i>.<b>ratio</b>(<i>ratio</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)
<a name="squarify_ratio" href="#squarify_ratio">#</a> <i>squarify</i>.<b>ratio</b>(<i>ratio</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)

@@ -522,7 +530,7 @@ Specifies the desired aspect ratio of the generated rectangles. The *ratio* must be specified as a number greater than or equal to one. Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose *width*:*height* ratio is either 2:1 or 1:2. (However, you can approximately achieve this result by generating a square treemap at different dimensions, and then [stretching the treemap](https://observablehq.com/@d3/stretched-treemap) to the desired aspect ratio.) Furthermore, the specified *ratio* is merely a hint to the tiling algorithm; the rectangles are not guaranteed to have the specified aspect ratio. If not specified, the aspect ratio defaults to the golden ratio, φ = (1 + sqrt(5)) / 2, per [Kong *et al.*](http://vis.stanford.edu/papers/perception-treemaps)

[<img alt="Partition" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/partition.png">](https://observablehq.com/@d3/icicle)
[<img alt="Partition" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/partition.png">](https://observablehq.com/@d3/icicle)
The **partition layout** produces adjacency diagrams: a space-filling variant of a node-link tree diagram. Rather than drawing a link between parent and child in the hierarchy, nodes are drawn as solid areas (either arcs or rectangles), and their placement relative to other nodes reveals their position in the hierarchy. The size of the nodes encodes a quantitative dimension that would be difficult to show in a node-link diagram.
<a name="partition" href="#partition">#</a> d3.<b>partition</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/partition.js), [Examples](https://observablehq.com/@d3/icicle)
<a name="partition" href="#partition">#</a> d3.<b>partition</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/partition.js), [Examples](https://observablehq.com/@d3/icicle)

@@ -556,7 +564,7 @@ Creates a new partition layout with the default settings.

[<img alt="Circle-Packing" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/pack.png">](https://observablehq.com/@d3/circle-packing)
[<img alt="Circle-Packing" src="https://raw.githubusercontent.com/d3/d3-hierarchy/main/img/pack.png">](https://observablehq.com/@d3/circle-packing)
Enclosure diagrams use containment (nesting) to represent a hierarchy. The size of the leaf circles encodes a quantitative dimension of the data. The enclosing circles show the approximate cumulative size of each subtree, but due to wasted space there is some distortion; only the leaf nodes can be compared accurately. Although [circle packing](http://en.wikipedia.org/wiki/Circle_packing) does not use space as efficiently as a [treemap](#treemap), the “wasted” space more prominently reveals the hierarchical structure.
<a name="pack" href="#pack">#</a> d3.<b>pack</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/index.js), [Examples](https://observablehq.com/@d3/circle-packing)
<a name="pack" href="#pack">#</a> d3.<b>pack</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/pack/index.js), [Examples](https://observablehq.com/@d3/circle-packing)

@@ -587,3 +595,3 @@ Creates a new pack layout with the default settings.

<a name="packSiblings" href="#packSiblings">#</a> d3.<b>packSiblings</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/siblings.js)
<a name="packSiblings" href="#packSiblings">#</a> d3.<b>packSiblings</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/pack/siblings.js)

@@ -597,4 +605,4 @@ Packs the specified array of *circles*, each of which must have a *circle*.r property specifying the circle’s radius. Assigns the following properties to each circle:

<a name="packEnclose" href="#packEnclose">#</a> d3.<b>packEnclose</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/enclose.js), [Examples](https://observablehq.com/@d3/d3-packenclose)
<a name="packEnclose" href="#packEnclose">#</a> d3.<b>packEnclose</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/main/src/pack/enclose.js), [Examples](https://observablehq.com/@d3/d3-packenclose)
Computes the [smallest circle](https://en.wikipedia.org/wiki/Smallest-circle_problem) that encloses the specified array of *circles*, each of which must have a *circle*.r property specifying the circle’s radius, and *circle*.x and *circle*.y properties specifying the circle’s center. The enclosing circle is computed using the [Matoušek-Sharir-Welzl algorithm](http://www.inf.ethz.ch/personal/emo/PublFiles/SubexLinProg_ALG16_96.pdf). (See also [Apollonius’ Problem](https://bl.ocks.org/mbostock/751fdd637f4bc2e3f08b).)

@@ -1,6 +0,7 @@

import {required} from "./accessors.js";
import {optional} from "./accessors.js";
import {Node, computeHeight} from "./hierarchy/index.js";
var preroot = {depth: -1},
ambiguous = {};
ambiguous = {},
imputed = {};

@@ -17,7 +18,10 @@ function defaultId(d) {

var id = defaultId,
parentId = defaultParentId;
parentId = defaultParentId,
path;
function stratify(data) {
var nodes = Array.from(data),
n = nodes.length,
currentId = id,
currentParentId = parentId,
n,
d,

@@ -32,9 +36,25 @@ i,

for (i = 0; i < n; ++i) {
if (path != null) {
const I = nodes.map((d, i) => normalize(path(d, i, data)));
const P = I.map(parentof);
const S = new Set(I).add("");
for (const i of P) {
if (!S.has(i)) {
S.add(i);
I.push(i);
P.push(parentof(i));
nodes.push(imputed);
}
}
currentId = (_, i) => I[i];
currentParentId = (_, i) => P[i];
}
for (i = 0, n = nodes.length; i < n; ++i) {
d = nodes[i], node = nodes[i] = new Node(d);
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
nodeKey = node.id = nodeId;
nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
}
if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
node.parent = nodeId;

@@ -60,2 +80,16 @@ }

if (!root) throw new Error("no root");
// When imputing internal nodes, only introduce roots if needed.
// Then replace the imputed marker data with null.
if (path != null) {
while (root.data === imputed && root.children.length === 1) {
root = root.children[0], --n;
}
for (let i = nodes.length - 1; i >= 0; --i) {
node = nodes[i];
if (node.data !== imputed) break;
node.data = null;
}
}
root.parent = preroot;

@@ -70,10 +104,46 @@ root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);

stratify.id = function(x) {
return arguments.length ? (id = required(x), stratify) : id;
return arguments.length ? (id = optional(x), stratify) : id;
};
stratify.parentId = function(x) {
return arguments.length ? (parentId = required(x), stratify) : parentId;
return arguments.length ? (parentId = optional(x), stratify) : parentId;
};
stratify.path = function(x) {
return arguments.length ? (path = optional(x), stratify) : path;
};
return stratify;
}
// To normalize a path, we coerce to a string, strip trailing slash if present,
// and add leading slash if missing. This requires counting the number of
// preceding backslashes which may be used to escape the forward slash: an odd
// number indicates an escaped forward slash.
function normalize(path) {
path = `${path}`;
let i = path.length - 1;
if (path[i] === "/") {
let k = 0;
while (i > 0 && path[--i] === "\\") ++k;
if ((k & 1) === 0) path = path.slice(0, -1);
}
return path[0] === "/" ? path : `/${path}`;
}
// Walk backwards to find the first slash that is not the leading slash, e.g.:
// "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
// because the id of the root must be a truthy value.) The slash may be escaped,
// which again requires counting the number of preceding backslashes. Note that
// normalized paths cannot end with a slash except for the root.
function parentof(path) {
let i = path.length;
while (i > 2) {
if (path[--i] === "/") {
let j = i, k = 0;
while (j > 0 && path[--j] === "\\") ++k;
if ((k & 1) === 0) break;
}
}
return path.slice(0, i < 3 ? i - 1 : i);
}
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