// 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=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=[];t0&&e*e>t*t+u*u}function v(n,r){for(var e=0;e(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;ap&&(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:f1?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;++l1?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;o0)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.xh.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=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>>1;c[v]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})});