You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
13 KiB
2 lines
13 KiB
5 years ago
|
// https://d3js.org/d3-hierarchy/ Version 1.1.5. Copyright 2017 Mike Bostock.
|
||
|
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.d3=n.d3||{})}(this,function(n){"use strict";function r(n,r){return n.parent===r.parent?1:2}function e(n){return n.reduce(t,0)/n.length}function t(n,r){return n+r.x}function u(n){return 1+n.reduce(i,0)}function i(n,r){return Math.max(n,r.y)}function o(n){for(var r;r=n.children;)n=r[0];return n}function f(n){for(var r;r=n.children;)n=r[r.length-1];return n}function a(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 c(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}function h(n,r){var e,t,u,i,o,f=new v(n),a=+n.value&&(f.value=n.value),c=[f];for(null==r&&(r=p);e=c.pop();)if(a&&(e.value=+e.data.value),(u=r(e.data))&&(o=u.length))for(e.children=new Array(o),i=o-1;i>=0;--i)c.push(t=e.children[i]=new v(u[i])),t.parent=e,t.depth=e.depth+1;return f.eachBefore(s)}function l(){return h(this).eachBefore(d)}function p(n){return n.children}function d(n){n.data=n.data.data}function s(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function v(n){this.data=n,this.depth=this.height=0,this.parent=null}function x(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}function y(n,r){var e,t;if(w(r,n))return[r];for(e=0;e<n.length;++e)if(g(r,n[e])&&w(B(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(g(B(n[e],n[t]),r)&&g(B(n[e],r),n[t])&&g(B(n[t],r),n[e])&&w(M(n[e],n[t],r),n))return[n[e],n[t],r];throw new Error}function g(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 m(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 w(n,r){for(var e=0;e<r.length;++e)if(!m(n,r[e]))return!1;return!0}function _(n){switch(n.length){case 1:return z(n[0]);case 2:return B(n[0],n[1]);case 3:return M(n[0],n[1],n[2])}}function z(n){return{x:n.x,y:n.y,r:n.r}}function B(n,r){var e=n.x,t=n.y,u=n.r,i=r.x,o=r.y,f=r.r,a=i-e,c=o-t,h=f-u,l=Math.sqrt(a*a+c*c);return{x:(e+i+a/l*h)/2,y:(t+o+c/l*h)/2,r:(l+u+f)/2}}function M(n,r,e){var t=n.x,u=n.y,i=n.r,o=r.x,f=r.y,a=r.r,c=e.x,h=e.y,l=e.r,p=t-o,d=t-c,s=u-f,v=u-h,x=a-i,y=l-i,g=t*t+u*u-i*i,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*_)-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 A(n,r,e){var t=n.x,u=n.y,i=r.r+e.r,o=n.r+e.r,f=r.x-t,a=r.y-u,c=f*f+a*a;if(c){var h=.5+((o*=o)-(i*=i))/(2*c),l=Math.sqrt(Math.max(0,2*i*(o+c)-(o-=c)*o-i*i))/(2*c);e.x=t+h*f+l*a,e.y=u+h*a-l*f}else e.x=t+o,e.y=u}function q(n,r){var e=r.x-n.x,t=r.y-n.y,u=n.r+r.r;return u*u-1e-6>e*e+t*t}function E(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 b(n){this._=n,this.next=null,this.previous=null}function S(n){if(!(u=n.length))return 0;var r,e,t,u,i,o,f,a,c,h,l;if(r=n[0],r.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;A(e,r,t=n[2]),r=new b(r),e=new b(e),t=new b(t),r.next=t.previous=e,e.next=r.previous=t,t.next=e.previous=r;n:for(f=3;f<u;++f){A(r._,e._,t=n[f]),t=new b(t),a=e.next,c=r.previous,h=e._.r,l=r._.r;do{if(h<=l){if(q(a._,t._)){e=a,r.next=e,e.previous=r,--f;continue n}h+=a._.r,a=a.next}else{if(q(c._,t._)){(r=c).next=e,e.previous=r,--f;continue n}l+=c._.r,c=c.previous}}while(a!==c.next);for(t.previous=r,t.next=e,r.next=e.previous=e=t,i=E(r);(t=t.next)!==e;)(o=E(t))<i&&(r=t,i=o);e=r.next}for(r=[e._],t=e;(t=t.next)!==e;)r.push(t._);for(t=an(r),f=0;f<u;++f)r=n[f],r.x-=t.x,r.y-=t.y;return t.r}function k(n){return null==n?null:I(n)}function I(n){if("function"!=typeof n)throw new Error;return n}function O(){return 0}function j(n){return Math.sqrt(n.value)}function R(n){return function(r){r.children||(r.r=Math.max(0,+n(r)||0))}}function T(n,r){return function(e){if(t=e.children){var t,u,i,o=t.length,f=n(e)*r||0;if(f)for(u=0;u<o;++u)t[u].r+=f;if(i=S(
|