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
2 lines
7.7 KiB
5 years ago
|
// 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
|