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
7.7 KiB

// https://d3js.org/d3-force/ Version 1.1.0. Copyright 2017 Mike Bostock.
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-collection"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-collection","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i){"use strict";function u(n){return n.x+n.vx}function o(n){return n.y+n.vy}function f(n){return n.index}function a(n,t){var e=n.get(t);if(!e)throw new Error("missing: "+t);return e}function c(n){return n.x}function l(n){return n.y}var h=function(n){return function(){return n}},v=function(){return 1e-6*(Math.random()-.5)},y=10,d=Math.PI*(3-Math.sqrt(5));n.forceCenter=function(n,t){function e(){var e,i,u=r.length,o=0,f=0;for(e=0;e<u;++e)o+=(i=r[e]).x,f+=i.y;for(o=o/u-n,f=f/u-t,e=0;e<u;++e)(i=r[e]).x-=o,i.y-=f}var r;return null==n&&(n=0),null==t&&(t=0),e.initialize=function(n){r=n},e.x=function(t){return arguments.length?(n=+t,e):n},e.y=function(n){return arguments.length?(t=+n,e):t},e},n.forceCollide=function(n){function e(){for(var n,e,i,h,y,d,x,g=f.length,s=0;s<l;++s)for(e=t.quadtree(f,u,o).visitAfter(r),n=0;n<g;++n)i=f[n],d=a[i.index],x=d*d,h=i.x+i.vx,y=i.y+i.vy,e.visit(function(n,t,e,r,u){var o=n.data,f=n.r,a=d+f;if(!o)return t>h+a||r<h-a||e>y+a||u<y-a;if(o.index>i.index){var l=h-o.x-o.vx,g=y-o.y-o.vy,s=l*l+g*g;s<a*a&&(0===l&&(l=v(),s+=l*l),0===g&&(g=v(),s+=g*g),s=(a-(s=Math.sqrt(s)))/s*c,i.vx+=(l*=s)*(a=(f*=f)/(x+f)),i.vy+=(g*=s)*a,o.vx-=l*(a=1-a),o.vy-=g*a)}})}function r(n){if(n.data)return n.r=a[n.data.index];for(var t=n.r=0;t<4;++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}function i(){if(f){var t,e,r=f.length;for(a=new Array(r),t=0;t<r;++t)e=f[t],a[e.index]=+n(e,t,f)}}var f,a,c=1,l=1;return"function"!=typeof n&&(n=h(null==n?1:+n)),e.initialize=function(n){f=n,i()},e.iterations=function(n){return arguments.length?(l=+n,e):l},e.strength=function(n){return arguments.length?(c=+n,e):c},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:h(+t),i(),e):n},e},n.forceLink=function(n){function t(t){for(var e=0,r=n.length;e<p;++e)for(var i,u,f,a,l,h,y,x=0;x<r;++x)u=(i=n[x]).source,a=(f=i.target).x+f.vx-u.x-u.vx||v(),l=f.y+f.vy-u.y-u.vy||v(),a*=h=((h=Math.sqrt(a*a+l*l))-c[x])/h*t*o[x],l*=h,f.vx-=a*(y=d[x]),f.vy-=l*y,u.vx+=a*(y=1-y),u.vy+=l*y}function r(){if(l){var t,r,f=l.length,h=n.length,v=e.map(l,x);for(t=0,y=new Array(f);t<h;++t)(r=n[t]).index=t,"object"!=typeof r.source&&(r.source=a(v,r.source)),"object"!=typeof r.target&&(r.target=a(v,r.target)),y[r.source.index]=(y[r.source.index]||0)+1,y[r.target.index]=(y[r.target.index]||0)+1;for(t=0,d=new Array(h);t<h;++t)r=n[t],d[t]=y[r.source.index]/(y[r.source.index]+y[r.target.index]);o=new Array(h),i(),c=new Array(h),u()}}function i(){if(l)for(var t=0,e=n.length;t<e;++t)o[t]=+g(n[t],t,n)}function u(){if(l)for(var t=0,e=n.length;t<e;++t)c[t]=+s(n[t],t,n)}var o,c,l,y,d,x=f,g=function(n){return 1/Math.min(y[n.source.index],y[n.target.index])},s=h(30),p=1;return null==n&&(n=[]),t.initialize=function(n){l=n,r()},t.links=function(e){return arguments.length?(n=e,r(),t):n},t.id=function(n){return arguments.length?(x=n,t):x},t.iterations=function(n){return arguments.length?(p=+n,t):p},t.strength=function(n){return arguments.length?(g="function"==typeof n?n:h(+n),i(),t):g},t.distance=function(n){return arguments.length?(s="function"==typeof n?n:h(+n),u(),t):s},t},n.forceManyBody=function(){function n(n){var e,a=u.length,h=t.quadtree(u,c,l).visitAfter(r);for(f=n,e=0;e<a;++e)o=u[e],h.visit(i)}function e(){if(u){var n,t,e=u.length;for(a=new Array(e),n=0;n<e;++n)t=u[n],a[t.index]=+y(t,n,u)}}function r(n){var t,e,r,i,u,o=0,f=0;if(n.length){for(r=i=u=0;u<4;++u)(t=n[u])&&(e=Math.abs(t.value))&&(o+=t.value,f+=e,r+=e*t.x,i+=e*t.y);n.x=r/f,n.y=i/f}else{(t=n).x=t.data.x,t.y=t.data.y;do{o+=a[t.data.index]}while(t=t.next)}n.value=o}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-o.x,u=n.y-o.y,c=r-t,l=i*i+u*u;if(c*c/g<l)return l<x&&(0===i&&(i=v(),l+=i*i),0===u&&(u=v(),l+=u*u),l<d&&(l=Math.sqrt(d*l)),o.vx+=i*n.value*f/l,o.vy+=u*n.value*f/l),!0;if(!(n.length||l>=x)){(n.data!==o||n.next)&&(0===i&&(i=v(),l+=i*i),0===u&&(u=v(),l+=u*u),l<d&&(l=Math.sqrt(d*l)));do{n.data!==o&&(c=a[n.data.index]*f/l,o.vx+=i*c,o.vy+=u*c)}while(n=n.next)}}var u,o,f,a,y=h(-30),d=1,x=1/0,g=.81;return n.initialize=function(n){u=n,e()},n.strength=function(t){return arguments.length?(y="function"==typeof t?t:h(+t),e(),n):y},n.distanceMin=function(t){return arguments.length?(d=t*t,n):Math.sqrt(d)},n.distanceMax=function(t){return arguments.length?(x=t*t,n):Math.sqrt(x)},n.theta=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n},n.forceRadial=function(n,t,e){function r(n){for(var r=0,i=u.length;r<i;++r){var a=u[r],c=a.x-t||1e-6,l=a.y-e||1e-6,h=Math.sqrt(c*c+l*l),v=(f[r]-h)*o[r]*n/h;a.vx+=c*v,a.vy+=l*v}}function i(){if(u){var t,e=u.length;for(o=new Array(e),f=new Array(e),t=0;t<e;++t)f[t]=+n(u[t],t,u),o[t]=isNaN(f[t])?0:+a(u[t],t,u)}}var u,o,f,a=h(.1);return"function"!=typeof n&&(n=h(+n)),null==t&&(t=0),null==e&&(e=0),r.initialize=function(n){u=n,i()},r.strength=function(n){return arguments.length?(a="function"==typeof n?n:h(+n),i(),r):a},r.radius=function(t){return arguments.length?(n="function"==typeof t?t:h(+t),i(),r):n},r.x=function(n){return arguments.length?(t=+n,r):t},r.y=function(n){return arguments.length?(e=+n,r):e},r},n.forceSimulation=function(n){function t(){u(),p.call("tick",a),c<l&&(s.stop(),p.call("end",a))}function u(){var t,e,r=n.length;for(c+=(v-c)*h,g.each(function(n){n(c)}),t=0;t<r;++t)null==(e=n[t]).fx?e.x+=e.vx*=x:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=x:(e.y=e.fy,e.vy=0)}function o(){for(var t,e=0,r=n.length;e<r;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=y*Math.sqrt(e),u=e*d;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function f(t){return t.initialize&&t.initialize(n),t}var a,c=1,l=.001,h=1-Math.pow(l,1/300),v=0,x=.6,g=e.map(),s=i.timer(t),p=r.dispatch("tick","end");return null==n&&(n=[]),o(),a={tick:u,restart:function(){return s.restart(t),a},stop:function(){return s.stop(),a},nodes:function(t){return arguments.length?(n=t,o(),g.each(f),a):n},alpha:function(n){return arguments.length?(c=+n,a):c},alphaMin:function(n){return arguments.length?(l=+n,a):l},alphaDecay:function(n){return arguments.length?(h=+n,a):+h},alphaTarget:function(n){return arguments.length?(v=+n,a):v},velocityDecay:function(n){return arguments.length?(x=1-n,a):1-x},force:function(n,t){return arguments.length>1?(null==t?g.remove(n):g.set(n,f(t)),a):g.get(n)},find:function(t,e,r){var i,u,o,f,a,c=0,l=n.length;for(null==r?r=1/0:r*=r,c=0;c<l;++c)(o=(i=t-(f=n[c]).x)*i+(u=e-f.y)*u)<r&&(a=f,r=o);return a},on:function(n,t){return arguments.length>1?(p.on(n,t),a):p.on(n)}}},n.forceX=function(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)(t=r[e]).vx+=(u[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+o(r[t],t,r)}}var r,i,u,o=h(.1);return"function"!=typeof n&&(n=h(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:h(+n),e(),t):o},t.x=function(r){return arguments.length?(n="function"==typeof r?r:h(+r),e(),t):n},t},n.forceY=function(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)(t=r[e]).vy+=(u[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+o(r[t],t,r)}}var r,i,u,o=h(.1);return"function"!=typeof n&&(n=h(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:h(+n),e(),t):o},t.y=function(r){return arguments.length?(n="function"==typeof r?r:h(+r),e(),t):n},t},Object.defineProperty(n,"__esModule",{value:!0})});