aframe-forcegraph-component
Version:
A 3D Force-Directed Graph component for A-Frame.
2 lines • 116 kB
JavaScript
// Version 3.3.0 aframe-forcegraph-component - https://github.com/vasturiano/aframe-forcegraph-component#readme
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(require("three")):"function"==typeof define&&define.amd?define(["three"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).THREE)}(this,function(t){"use strict";function n(t,n,e){var r,i=1;function o(){var o,a,u=r.length,s=0,l=0,f=0;for(o=0;o<u;++o)s+=(a=r[o]).x||0,l+=a.y||0,f+=a.z||0;for(s=(s/u-t)*i,l=(l/u-n)*i,f=(f/u-e)*i,o=0;o<u;++o)a=r[o],s&&(a.x-=s),l&&(a.y-=l),f&&(a.z-=f)}return null==t&&(t=0),null==n&&(n=0),null==e&&(e=0),o.initialize=function(t){r=t},o.x=function(n){return arguments.length?(t=+n,o):t},o.y=function(t){return arguments.length?(n=+t,o):n},o.z=function(t){return arguments.length?(e=+t,o):e},o.strength=function(t){return arguments.length?(i=+t,o):i},o}function e(t,n,e){if(isNaN(n))return t;var r,i,o,a,u,s,l=t._root,f={data:e},c=t._x0,h=t._x1;if(!l)return t._root=f,t;for(;l.length;)if((a=n>=(i=(c+h)/2))?c=i:h=i,r=l,!(l=l[u=+a]))return r[u]=f,t;if(n===(o=+t._x.call(null,l.data)))return f.next=l,r?r[u]=f:t._root=f,t;do{r=r?r[u]=new Array(2):t._root=new Array(2),(a=n>=(i=(c+h)/2))?c=i:h=i}while((u=+a)===(s=+(o>=i)));return r[s]=l,r[u]=f,t}function r(t,n,e){this.node=t,this.x0=n,this.x1=e}function i(t){return t[0]}function o(t,n){var e=new a(null==n?i:n,NaN,NaN);return null==t?e:e.addAll(t)}function a(t,n,e){this._x=t,this._x0=n,this._x1=e,this._root=void 0}function u(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var s=o.prototype=a.prototype;function l(t,n,e,r){if(isNaN(n)||isNaN(e))return t;var i,o,a,u,s,l,f,c,h,d=t._root,p={data:r},g=t._x0,v=t._y0,y=t._x1,b=t._y1;if(!d)return t._root=p,t;for(;d.length;)if((l=n>=(o=(g+y)/2))?g=o:y=o,(f=e>=(a=(v+b)/2))?v=a:b=a,i=d,!(d=d[c=f<<1|l]))return i[c]=p,t;if(u=+t._x.call(null,d.data),s=+t._y.call(null,d.data),n===u&&e===s)return p.next=d,i?i[c]=p:t._root=p,t;do{i=i?i[c]=new Array(4):t._root=new Array(4),(l=n>=(o=(g+y)/2))?g=o:y=o,(f=e>=(a=(v+b)/2))?v=a:b=a}while((c=f<<1|l)==(h=(s>=a)<<1|u>=o));return i[h]=d,i[c]=p,t}function f(t,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function c(t){return t[0]}function h(t){return t[1]}function d(t,n,e){var r=new p(null==n?c:n,null==e?h:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function p(t,n,e,r,i,o){this._x=t,this._y=n,this._x0=e,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function g(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}s.copy=function(){var t,n,e=new a(this._x,this._x0,this._x1),r=this._root;if(!r)return e;if(!r.length)return e._root=u(r),e;for(t=[{source:r,target:e._root=new Array(2)}];r=t.pop();)for(var i=0;i<2;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(2)}):r.target[i]=u(n));return e},s.add=function(t){const n=+this._x.call(null,t);return e(this.cover(n),n,t)},s.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const n=t.length,r=new Float64Array(n);let i=1/0,o=-1/0;for(let e,a=0;a<n;++a)isNaN(e=+this._x.call(null,t[a]))||(r[a]=e,e<i&&(i=e),e>o&&(o=e));if(i>o)return this;this.cover(i).cover(o);for(let i=0;i<n;++i)e(this,r[i],t[i]);return this},s.cover=function(t){if(isNaN(t=+t))return this;var n=this._x0,e=this._x1;if(isNaN(n))e=(n=Math.floor(t))+1;else{for(var r,i,o=e-n||1,a=this._root;n>t||t>=e;)switch(i=+(t<n),(r=new Array(2))[i]=a,a=r,o*=2,i){case 0:e=n+o;break;case 1:n=e-o}this._root&&this._root.length&&(this._root=a)}return this._x0=n,this._x1=e,this},s.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},s.extent=function(t){return arguments.length?this.cover(+t[0][0]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]},s.find=function(t,n){var e,i,o,a,u,s=this._x0,l=this._x1,f=[],c=this._root;for(c&&f.push(new r(c,s,l)),null==n?n=1/0:(s=t-n,l=t+n);a=f.pop();)if(!(!(c=a.node)||(i=a.x0)>l||(o=a.x1)<s))if(c.length){var h=(i+o)/2;f.push(new r(c[1],h,o),new r(c[0],i,h)),(u=+(t>=h))&&(a=f[f.length-1],f[f.length-1]=f[f.length-1-u],f[f.length-1-u]=a)}else{var d=Math.abs(t-+this._x.call(null,c.data));d<n&&(n=d,s=t-d,l=t+d,e=c.data)}return e},s.remove=function(t){if(isNaN(o=+this._x.call(null,t)))return this;var n,e,r,i,o,a,u,s,l,f=this._root,c=this._x0,h=this._x1;if(!f)return this;if(f.length)for(;;){if((u=o>=(a=(c+h)/2))?c=a:h=a,n=f,!(f=f[s=+u]))return this;if(!f.length)break;n[s+1&1]&&(e=n,l=s)}for(;f.data!==t;)if(r=f,!(f=f.next))return this;return(i=f.next)&&delete f.next,r?(i?r.next=i:delete r.next,this):n?(i?n[s]=i:delete n[s],(f=n[0]||n[1])&&f===(n[1]||n[0])&&!f.length&&(e?e[l]=f:this._root=f),this):(this._root=i,this)},s.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},s.root=function(){return this._root},s.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},s.visit=function(t){var n,e,i,o,a=[],u=this._root;for(u&&a.push(new r(u,this._x0,this._x1));n=a.pop();)if(!t(u=n.node,i=n.x0,o=n.x1)&&u.length){var s=(i+o)/2;(e=u[1])&&a.push(new r(e,s,o)),(e=u[0])&&a.push(new r(e,i,s))}return this},s.visitAfter=function(t){var n,e=[],i=[];for(this._root&&e.push(new r(this._root,this._x0,this._x1));n=e.pop();){var o=n.node;if(o.length){var a,u=n.x0,s=n.x1,l=(u+s)/2;(a=o[0])&&e.push(new r(a,u,l)),(a=o[1])&&e.push(new r(a,l,s))}i.push(n)}for(;n=i.pop();)t(n.node,n.x0,n.x1);return this},s.x=function(t){return arguments.length?(this._x=t,this):this._x};var v=d.prototype=p.prototype;function y(t,n,e,r,i){if(isNaN(n)||isNaN(e)||isNaN(r))return t;var o,a,u,s,l,f,c,h,d,p,g,v,y=t._root,b={data:i},m=t._x0,_=t._y0,w=t._z0,x=t._x1,k=t._y1,M=t._z1;if(!y)return t._root=b,t;for(;y.length;)if((h=n>=(a=(m+x)/2))?m=a:x=a,(d=e>=(u=(_+k)/2))?_=u:k=u,(p=r>=(s=(w+M)/2))?w=s:M=s,o=y,!(y=y[g=p<<2|d<<1|h]))return o[g]=b,t;if(l=+t._x.call(null,y.data),f=+t._y.call(null,y.data),c=+t._z.call(null,y.data),n===l&&e===f&&r===c)return b.next=y,o?o[g]=b:t._root=b,t;do{o=o?o[g]=new Array(8):t._root=new Array(8),(h=n>=(a=(m+x)/2))?m=a:x=a,(d=e>=(u=(_+k)/2))?_=u:k=u,(p=r>=(s=(w+M)/2))?w=s:M=s}while((g=p<<2|d<<1|h)==(v=(c>=s)<<2|(f>=u)<<1|l>=a));return o[v]=y,o[g]=b,t}function b(t,n,e,r,i,o,a){this.node=t,this.x0=n,this.y0=e,this.z0=r,this.x1=i,this.y1=o,this.z1=a}v.copy=function(){var t,n,e=new p(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=g(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(4)}):r.target[i]=g(n));return e},v.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t);return l(this.cover(n,e),n,e,t)},v.addAll=function(t){var n,e,r,i,o=t.length,a=new Array(o),u=new Array(o),s=1/0,f=1/0,c=-1/0,h=-1/0;for(e=0;e<o;++e)isNaN(r=+this._x.call(null,n=t[e]))||isNaN(i=+this._y.call(null,n))||(a[e]=r,u[e]=i,r<s&&(s=r),r>c&&(c=r),i<f&&(f=i),i>h&&(h=i));if(s>c||f>h)return this;for(this.cover(s,f).cover(c,h),e=0;e<o;++e)l(this,a[e],u[e],t[e]);return this},v.cover=function(t,n){if(isNaN(t=+t)||isNaN(n=+n))return this;var e=this._x0,r=this._y0,i=this._x1,o=this._y1;if(isNaN(e))i=(e=Math.floor(t))+1,o=(r=Math.floor(n))+1;else{for(var a,u,s=i-e||1,l=this._root;e>t||t>=i||r>n||n>=o;)switch(u=(n<r)<<1|t<e,(a=new Array(4))[u]=l,l=a,s*=2,u){case 0:i=e+s,o=r+s;break;case 1:e=i-s,o=r+s;break;case 2:i=e+s,r=o-s;break;case 3:e=i-s,r=o-s}this._root&&this._root.length&&(this._root=l)}return this._x0=e,this._y0=r,this._x1=i,this._y1=o,this},v.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},v.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},v.find=function(t,n,e){var r,i,o,a,u,s,l,c=this._x0,h=this._y0,d=this._x1,p=this._y1,g=[],v=this._root;for(v&&g.push(new f(v,c,h,d,p)),null==e?e=1/0:(c=t-e,h=n-e,d=t+e,p=n+e,e*=e);s=g.pop();)if(!(!(v=s.node)||(i=s.x0)>d||(o=s.y0)>p||(a=s.x1)<c||(u=s.y1)<h))if(v.length){var y=(i+a)/2,b=(o+u)/2;g.push(new f(v[3],y,b,a,u),new f(v[2],i,b,y,u),new f(v[1],y,o,a,b),new f(v[0],i,o,y,b)),(l=(n>=b)<<1|t>=y)&&(s=g[g.length-1],g[g.length-1]=g[g.length-1-l],g[g.length-1-l]=s)}else{var m=t-+this._x.call(null,v.data),_=n-+this._y.call(null,v.data),w=m*m+_*_;if(w<e){var x=Math.sqrt(e=w);c=t-x,h=n-x,d=t+x,p=n+x,r=v.data}}return r},v.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t)))return this;var n,e,r,i,o,a,u,s,l,f,c,h,d=this._root,p=this._x0,g=this._y0,v=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((l=o>=(u=(p+v)/2))?p=u:v=u,(f=a>=(s=(g+y)/2))?g=s:y=s,n=d,!(d=d[c=f<<1|l]))return this;if(!d.length)break;(n[c+1&3]||n[c+2&3]||n[c+3&3])&&(e=n,h=c)}for(;d.data!==t;)if(r=d,!(d=d.next))return this;return(i=d.next)&&delete d.next,r?(i?r.next=i:delete r.next,this):n?(i?n[c]=i:delete n[c],(d=n[0]||n[1]||n[2]||n[3])&&d===(n[3]||n[2]||n[1]||n[0])&&!d.length&&(e?e[h]=d:this._root=d),this):(this._root=i,this)},v.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},v.root=function(){return this._root},v.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},v.visit=function(t){var n,e,r,i,o,a,u=[],s=this._root;for(s&&u.push(new f(s,this._x0,this._y0,this._x1,this._y1));n=u.pop();)if(!t(s=n.node,r=n.x0,i=n.y0,o=n.x1,a=n.y1)&&s.length){var l=(r+o)/2,c=(i+a)/2;(e=s[3])&&u.push(new f(e,l,c,o,a)),(e=s[2])&&u.push(new f(e,r,c,l,a)),(e=s[1])&&u.push(new f(e,l,i,o,c)),(e=s[0])&&u.push(new f(e,r,i,l,c))}return this},v.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new f(this._root,this._x0,this._y0,this._x1,this._y1));n=e.pop();){var i=n.node;if(i.length){var o,a=n.x0,u=n.y0,s=n.x1,l=n.y1,c=(a+s)/2,h=(u+l)/2;(o=i[0])&&e.push(new f(o,a,u,c,h)),(o=i[1])&&e.push(new f(o,c,u,s,h)),(o=i[2])&&e.push(new f(o,a,h,c,l)),(o=i[3])&&e.push(new f(o,c,h,s,l))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.y1);return this},v.x=function(t){return arguments.length?(this._x=t,this):this._x},v.y=function(t){return arguments.length?(this._y=t,this):this._y};const m=(t,n,e,r,i,o)=>Math.sqrt((t-r)**2+(n-i)**2+(e-o)**2);function _(t){return t[0]}function w(t){return t[1]}function x(t){return t[2]}function k(t,n,e,r){var i=new M(null==n?_:n,null==e?w:e,null==r?x:r,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function M(t,n,e,r,i,o,a,u,s){this._x=t,this._y=n,this._z=e,this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this._root=void 0}function O(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var A=k.prototype=M.prototype;function j(t){return function(){return t}}function P(t){return 1e-6*(t()-.5)}function C(t){return t.index}function N(t,n){var e=t.get(n);if(!e)throw new Error("node not found: "+n);return e}function E(t){var n,e,r,i,o,a,u,s=C,l=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},f=j(30),c=1;function h(r){for(var o=0,s=t.length;o<c;++o)for(var l,f,h,d,p,g=0,v=0,y=0,b=0;g<s;++g)f=(l=t[g]).source,v=(h=l.target).x+h.vx-f.x-f.vx||P(u),i>1&&(y=h.y+h.vy-f.y-f.vy||P(u)),i>2&&(b=h.z+h.vz-f.z-f.vz||P(u)),v*=d=((d=Math.sqrt(v*v+y*y+b*b))-e[g])/d*r*n[g],y*=d,b*=d,h.vx-=v*(p=a[g]),i>1&&(h.vy-=y*p),i>2&&(h.vz-=b*p),f.vx+=v*(p=1-p),i>1&&(f.vy+=y*p),i>2&&(f.vz+=b*p)}function d(){if(r){var i,u,l=r.length,f=t.length,c=new Map(r.map((t,n)=>[s(t,n,r),t]));for(i=0,o=new Array(l);i<f;++i)(u=t[i]).index=i,"object"!=typeof u.source&&(u.source=N(c,u.source)),"object"!=typeof u.target&&(u.target=N(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(i=0,a=new Array(f);i<f;++i)u=t[i],a[i]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);n=new Array(f),p(),e=new Array(f),g()}}function p(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+l(t[e],e,t)}function g(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+f(t[n],n,t)}return null==t&&(t=[]),h.initialize=function(t,...n){r=t,u=n.find(t=>"function"==typeof t)||Math.random,i=n.find(t=>[1,2,3].includes(t))||2,d()},h.links=function(n){return arguments.length?(t=n,d(),h):t},h.id=function(t){return arguments.length?(s=t,h):s},h.iterations=function(t){return arguments.length?(c=+t,h):c},h.strength=function(t){return arguments.length?(l="function"==typeof t?t:j(+t),p(),h):l},h.distance=function(t){return arguments.length?(f="function"==typeof t?t:j(+t),g(),h):f},h}A.copy=function(){var t,n,e=new M(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),r=this._root;if(!r)return e;if(!r.length)return e._root=O(r),e;for(t=[{source:r,target:e._root=new Array(8)}];r=t.pop();)for(var i=0;i<8;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(8)}):r.target[i]=O(n));return e},A.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t),r=+this._z.call(null,t);return y(this.cover(n,e,r),n,e,r,t)},A.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const n=t.length,e=new Float64Array(n),r=new Float64Array(n),i=new Float64Array(n);let o=1/0,a=1/0,u=1/0,s=-1/0,l=-1/0,f=-1/0;for(let c,h,d,p,g=0;g<n;++g)isNaN(h=+this._x.call(null,c=t[g]))||isNaN(d=+this._y.call(null,c))||isNaN(p=+this._z.call(null,c))||(e[g]=h,r[g]=d,i[g]=p,h<o&&(o=h),h>s&&(s=h),d<a&&(a=d),d>l&&(l=d),p<u&&(u=p),p>f&&(f=p));if(o>s||a>l||u>f)return this;this.cover(o,a,u).cover(s,l,f);for(let o=0;o<n;++o)y(this,e[o],r[o],i[o],t[o]);return this},A.cover=function(t,n,e){if(isNaN(t=+t)||isNaN(n=+n)||isNaN(e=+e))return this;var r=this._x0,i=this._y0,o=this._z0,a=this._x1,u=this._y1,s=this._z1;if(isNaN(r))a=(r=Math.floor(t))+1,u=(i=Math.floor(n))+1,s=(o=Math.floor(e))+1;else{for(var l,f,c=a-r||1,h=this._root;r>t||t>=a||i>n||n>=u||o>e||e>=s;)switch(f=(e<o)<<2|(n<i)<<1|t<r,(l=new Array(8))[f]=h,h=l,c*=2,f){case 0:a=r+c,u=i+c,s=o+c;break;case 1:r=a-c,u=i+c,s=o+c;break;case 2:a=r+c,i=u-c,s=o+c;break;case 3:r=a-c,i=u-c,s=o+c;break;case 4:a=r+c,u=i+c,o=s-c;break;case 5:r=a-c,u=i+c,o=s-c;break;case 6:a=r+c,i=u-c,o=s-c;break;case 7:r=a-c,i=u-c,o=s-c}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this},A.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},A.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1],+t[0][2]).cover(+t[1][0],+t[1][1],+t[1][2]):isNaN(this._x0)?void 0:[[this._x0,this._y0,this._z0],[this._x1,this._y1,this._z1]]},A.find=function(t,n,e,r){var i,o,a,u,s,l,f,c,h,d=this._x0,p=this._y0,g=this._z0,v=this._x1,y=this._y1,m=this._z1,_=[],w=this._root;for(w&&_.push(new b(w,d,p,g,v,y,m)),null==r?r=1/0:(d=t-r,p=n-r,g=e-r,v=t+r,y=n+r,m=e+r,r*=r);c=_.pop();)if(!(!(w=c.node)||(o=c.x0)>v||(a=c.y0)>y||(u=c.z0)>m||(s=c.x1)<d||(l=c.y1)<p||(f=c.z1)<g))if(w.length){var x=(o+s)/2,k=(a+l)/2,M=(u+f)/2;_.push(new b(w[7],x,k,M,s,l,f),new b(w[6],o,k,M,x,l,f),new b(w[5],x,a,M,s,k,f),new b(w[4],o,a,M,x,k,f),new b(w[3],x,k,u,s,l,M),new b(w[2],o,k,u,x,l,M),new b(w[1],x,a,u,s,k,M),new b(w[0],o,a,u,x,k,M)),(h=(e>=M)<<2|(n>=k)<<1|t>=x)&&(c=_[_.length-1],_[_.length-1]=_[_.length-1-h],_[_.length-1-h]=c)}else{var O=t-+this._x.call(null,w.data),A=n-+this._y.call(null,w.data),j=e-+this._z.call(null,w.data),P=O*O+A*A+j*j;if(P<r){var C=Math.sqrt(r=P);d=t-C,p=n-C,g=e-C,v=t+C,y=n+C,m=e+C,i=w.data}}return i},A.findAllWithinRadius=function(t,n,e,r){const i=[],o=t-r,a=n-r,u=e-r,s=t+r,l=n+r,f=e+r;return this.visit((c,h,d,p,g,v,y)=>{if(!c.length)do{const o=c.data;m(t,n,e,this._x(o),this._y(o),this._z(o))<=r&&i.push(o)}while(c=c.next);return h>s||d>l||p>f||g<o||v<a||y<u}),i},A.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t))||isNaN(u=+this._z.call(null,t)))return this;var n,e,r,i,o,a,u,s,l,f,c,h,d,p,g,v=this._root,y=this._x0,b=this._y0,m=this._z0,_=this._x1,w=this._y1,x=this._z1;if(!v)return this;if(v.length)for(;;){if((c=o>=(s=(y+_)/2))?y=s:_=s,(h=a>=(l=(b+w)/2))?b=l:w=l,(d=u>=(f=(m+x)/2))?m=f:x=f,n=v,!(v=v[p=d<<2|h<<1|c]))return this;if(!v.length)break;(n[p+1&7]||n[p+2&7]||n[p+3&7]||n[p+4&7]||n[p+5&7]||n[p+6&7]||n[p+7&7])&&(e=n,g=p)}for(;v.data!==t;)if(r=v,!(v=v.next))return this;return(i=v.next)&&delete v.next,r?(i?r.next=i:delete r.next,this):n?(i?n[p]=i:delete n[p],(v=n[0]||n[1]||n[2]||n[3]||n[4]||n[5]||n[6]||n[7])&&v===(n[7]||n[6]||n[5]||n[4]||n[3]||n[2]||n[1]||n[0])&&!v.length&&(e?e[g]=v:this._root=v),this):(this._root=i,this)},A.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},A.root=function(){return this._root},A.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},A.visit=function(t){var n,e,r,i,o,a,u,s,l=[],f=this._root;for(f&&l.push(new b(f,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=l.pop();)if(!t(f=n.node,r=n.x0,i=n.y0,o=n.z0,a=n.x1,u=n.y1,s=n.z1)&&f.length){var c=(r+a)/2,h=(i+u)/2,d=(o+s)/2;(e=f[7])&&l.push(new b(e,c,h,d,a,u,s)),(e=f[6])&&l.push(new b(e,r,h,d,c,u,s)),(e=f[5])&&l.push(new b(e,c,i,d,a,h,s)),(e=f[4])&&l.push(new b(e,r,i,d,c,h,s)),(e=f[3])&&l.push(new b(e,c,h,o,a,u,d)),(e=f[2])&&l.push(new b(e,r,h,o,c,u,d)),(e=f[1])&&l.push(new b(e,c,i,o,a,h,d)),(e=f[0])&&l.push(new b(e,r,i,o,c,h,d))}return this},A.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new b(this._root,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=e.pop();){var i=n.node;if(i.length){var o,a=n.x0,u=n.y0,s=n.z0,l=n.x1,f=n.y1,c=n.z1,h=(a+l)/2,d=(u+f)/2,p=(s+c)/2;(o=i[0])&&e.push(new b(o,a,u,s,h,d,p)),(o=i[1])&&e.push(new b(o,h,u,s,l,d,p)),(o=i[2])&&e.push(new b(o,a,d,s,h,f,p)),(o=i[3])&&e.push(new b(o,h,d,s,l,f,p)),(o=i[4])&&e.push(new b(o,a,u,p,h,d,c)),(o=i[5])&&e.push(new b(o,h,u,p,l,d,c)),(o=i[6])&&e.push(new b(o,a,d,p,h,f,c)),(o=i[7])&&e.push(new b(o,h,d,p,l,f,c))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.z0,n.x1,n.y1,n.z1);return this},A.x=function(t){return arguments.length?(this._x=t,this):this._x},A.y=function(t){return arguments.length?(this._y=t,this):this._y},A.z=function(t){return arguments.length?(this._z=t,this):this._z};var S={value:()=>{}};function D(){for(var t,n=0,e=arguments.length,r={};n<e;++n){if(!(t=arguments[n]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new T(r)}function T(t){this._=t}function z(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}function B(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=S,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}T.prototype=D.prototype={constructor:T,on:function(t,n){var e,r,i=this._,o=(r=i,(t+"").trim().split(/^|\s+/).map(function(t){var n="",e=t.indexOf(".");if(e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})),a=-1,u=o.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++a<u;)if(e=(t=o[a]).type)i[e]=B(i[e],t.name,n);else if(null==n)for(e in i)i[e]=B(i[e],t.name,null);return this}for(;++a<u;)if((e=(t=o[a]).type)&&(e=z(i[e],t.name)))return e},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new T(t)},call:function(t,n){if((e=arguments.length-2)>0)for(var e,r,i=new Array(e),o=0;o<e;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,e=(r=this._[t]).length;o<e;++o)r[o].value.apply(n,i)},apply:function(t,n,e){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(n,e)}};var $,I,L=0,R=0,F=0,q=0,G=0,U=0,V="object"==typeof performance&&performance.now?performance:Date,H="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function W(){return G||(H(Q),G=V.now()+U)}function Q(){G=0}function J(){this._call=this._time=this._next=null}function X(t,n,e){var r=new J;return r.restart(t,n,e),r}function Y(){G=(q=V.now())+U,L=R=0;try{!function(){W(),++L;for(var t,n=$;n;)(t=G-n._time)>=0&&n._call.call(void 0,t),n=n._next;--L}()}finally{L=0,function(){var t,n,e=$,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:$=n);I=t,Z(r)}(),G=0}}function K(){var t=V.now(),n=t-q;n>1e3&&(U-=n,q=t)}function Z(t){L||(R&&(R=clearTimeout(R)),t-G>24?(t<1/0&&(R=setTimeout(Y,t-V.now()-U)),F&&(F=clearInterval(F))):(F||(q=V.now(),F=setInterval(K,1e3)),L=1,H(Y)))}J.prototype=X.prototype={constructor:J,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?W():+e)+(null==n?0:+n),this._next||I===this||(I?I._next=this:$=this,I=this),this._call=t,this._time=e,Z()},stop:function(){this._call&&(this._call=null,this._time=1/0,Z())}};const tt=4294967296;function nt(t){return t.x}function et(t){return t.y}function rt(t){return t.z}var it,ot,at,ut,st=Math.PI*(3-Math.sqrt(5)),lt=20*Math.PI/(9+Math.sqrt(221));function ft(t,n){n=n||2;var e,r=Math.min(3,Math.max(1,Math.round(n))),i=1,o=.001,a=1-Math.pow(o,1/300),u=0,s=.6,l=new Map,f=X(d),c=D("tick","end"),h=function(){let t=1;return()=>(t=(1664525*t+1013904223)%tt)/tt}();function d(){p(),c.call("tick",e),i<o&&(f.stop(),c.call("end",e))}function p(n){var o,f,c=t.length;void 0===n&&(n=1);for(var h=0;h<n;++h)for(i+=(u-i)*a,l.forEach(function(t){t(i)}),o=0;o<c;++o)null==(f=t[o]).fx?f.x+=f.vx*=s:(f.x=f.fx,f.vx=0),r>1&&(null==f.fy?f.y+=f.vy*=s:(f.y=f.fy,f.vy=0)),r>2&&(null==f.fz?f.z+=f.vz*=s:(f.z=f.fz,f.vz=0));return e}function g(){for(var n,e=0,i=t.length;e<i;++e){if((n=t[e]).index=e,null!=n.fx&&(n.x=n.fx),null!=n.fy&&(n.y=n.fy),null!=n.fz&&(n.z=n.fz),isNaN(n.x)||r>1&&isNaN(n.y)||r>2&&isNaN(n.z)){var o=10*(r>2?Math.cbrt(.5+e):r>1?Math.sqrt(.5+e):e),a=e*st,u=e*lt;1===r?n.x=o:2===r?(n.x=o*Math.cos(a),n.y=o*Math.sin(a)):(n.x=o*Math.sin(a)*Math.cos(u),n.y=o*Math.cos(a),n.z=o*Math.sin(a)*Math.sin(u))}(isNaN(n.vx)||r>1&&isNaN(n.vy)||r>2&&isNaN(n.vz))&&(n.vx=0,r>1&&(n.vy=0),r>2&&(n.vz=0))}}function v(n){return n.initialize&&n.initialize(t,h,r),n}return null==t&&(t=[]),g(),e={tick:p,restart:function(){return f.restart(d),e},stop:function(){return f.stop(),e},numDimensions:function(t){return arguments.length?(r=Math.min(3,Math.max(1,Math.round(t))),l.forEach(v),e):r},nodes:function(n){return arguments.length?(t=n,g(),l.forEach(v),e):t},alpha:function(t){return arguments.length?(i=+t,e):i},alphaMin:function(t){return arguments.length?(o=+t,e):o},alphaDecay:function(t){return arguments.length?(a=+t,e):+a},alphaTarget:function(t){return arguments.length?(u=+t,e):u},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(h=t,l.forEach(v),e):h},force:function(t,n){return arguments.length>1?(null==n?l.delete(t):l.set(t,v(n)),e):l.get(t)},find:function(){var n,e,i,o,a,u,s=Array.prototype.slice.call(arguments),l=s.shift()||0,f=(r>1?s.shift():null)||0,c=(r>2?s.shift():null)||0,h=s.shift()||1/0,d=0,p=t.length;for(h*=h,d=0;d<p;++d)(o=(n=l-(a=t[d]).x)*n+(e=f-(a.y||0))*e+(i=c-(a.z||0))*i)<h&&(u=a,h=o);return u},on:function(t,n){return arguments.length>1?(c.on(t,n),e):c.on(t)}}}function ct(){var t,n,e,r,i,a,u=j(-30),s=1,l=1/0,f=.81;function c(r){var a,u=t.length,s=(1===n?o(t,nt):2===n?d(t,nt,et):3===n?k(t,nt,et,rt):null).visitAfter(p);for(i=r,a=0;a<u;++a)e=t[a],s.visit(g)}function h(){if(t){var n,e,r=t.length;for(a=new Array(r),n=0;n<r;++n)e=t[n],a[e.index]=+u(e,n,t)}}function p(t){var e,r,i,o,u,s,l=0,f=0,c=t.length;if(c){for(i=o=u=s=0;s<c;++s)(e=t[s])&&(r=Math.abs(e.value))&&(l+=e.value,f+=r,i+=r*(e.x||0),o+=r*(e.y||0),u+=r*(e.z||0));l*=Math.sqrt(4/c),t.x=i/f,n>1&&(t.y=o/f),n>2&&(t.z=u/f)}else{(e=t).x=e.data.x,n>1&&(e.y=e.data.y),n>2&&(e.z=e.data.z);do{l+=a[e.data.index]}while(e=e.next)}t.value=l}function g(t,o,u,c,h){if(!t.value)return!0;var d=[u,c,h][n-1],p=t.x-e.x,g=n>1?t.y-e.y:0,v=n>2?t.z-e.z:0,y=d-o,b=p*p+g*g+v*v;if(y*y/f<b)return b<l&&(0===p&&(b+=(p=P(r))*p),n>1&&0===g&&(b+=(g=P(r))*g),n>2&&0===v&&(b+=(v=P(r))*v),b<s&&(b=Math.sqrt(s*b)),e.vx+=p*t.value*i/b,n>1&&(e.vy+=g*t.value*i/b),n>2&&(e.vz+=v*t.value*i/b)),!0;if(!(t.length||b>=l)){(t.data!==e||t.next)&&(0===p&&(b+=(p=P(r))*p),n>1&&0===g&&(b+=(g=P(r))*g),n>2&&0===v&&(b+=(v=P(r))*v),b<s&&(b=Math.sqrt(s*b)));do{t.data!==e&&(y=a[t.data.index]*i/b,e.vx+=p*y,n>1&&(e.vy+=g*y),n>2&&(e.vz+=v*y))}while(t=t.next)}}return c.initialize=function(e,...i){t=e,r=i.find(t=>"function"==typeof t)||Math.random,n=i.find(t=>[1,2,3].includes(t))||2,h()},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:j(+t),h(),c):u},c.distanceMin=function(t){return arguments.length?(s=t*t,c):Math.sqrt(s)},c.distanceMax=function(t){return arguments.length?(l=t*t,c):Math.sqrt(l)},c.theta=function(t){return arguments.length?(f=t*t,c):Math.sqrt(f)},c}function ht(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function dt(){if(ot)return it;return ot=1,it=function(t){!function(t){if(!t)throw new Error("Eventify cannot use falsy object as events subject");for(var n=["on","fire","off"],e=0;e<n.length;++e)if(t.hasOwnProperty(n[e]))throw new Error("Subject cannot be eventified, since it already has property '"+n[e]+"'")}(t);var n=function(t){var n=Object.create(null);return{on:function(e,r,i){if("function"!=typeof r)throw new Error("callback is expected to be a function");var o=n[e];return o||(o=n[e]=[]),o.push({callback:r,ctx:i}),t},off:function(e,r){if(void 0===e)return n=Object.create(null),t;if(n[e])if("function"!=typeof r)delete n[e];else for(var i=n[e],o=0;o<i.length;++o)i[o].callback===r&&i.splice(o,1);return t},fire:function(e){var r,i=n[e];if(!i)return t;arguments.length>1&&(r=Array.prototype.splice.call(arguments,1));for(var o=0;o<i.length;++o){var a=i[o];a.callback.apply(a.ctx,r)}return t}}}(t);return t.on=n.on,t.off=n.off,t.fire=n.fire,t},it}var pt,gt,vt,yt,bt,mt=function(){if(ut)return at;ut=1,at=function(o){"uniqueLinkId"in(o=o||{})&&(console.warn("ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n","\n","Note: there is also change in default behavior: From now on each graph\nis considered to be not a multigraph by default (each edge is unique)."),o.multigraph=o.uniqueLinkId);void 0===o.multigraph&&(o.multigraph=!1);if("function"!=typeof Map)throw new Error("ngraph.graph requires `Map` to be defined. Please polyfill it before using ngraph");var a=new Map,u=new Map,s={},l=0,f=o.multigraph?function(t,n,e){var o=i(t,n),a=s.hasOwnProperty(o);if(a||O(t,n)){a||(s[o]=0);var u="@"+ ++s[o];o=i(t+u,n+u)}return new r(t,n,e,o)}:function(t,n,e){var o=i(t,n),a=u.get(o);if(a)return a.data=e,a;return new r(t,n,e,o)},c=[],h=A,d=A,p=A,g=A,v={version:20,addNode:m,addLink:function(t,n,r){p();var i=_(t)||m(t),o=_(n)||m(n),a=f(t,n,r),s=u.has(a.id);u.set(a.id,a),e(i,a),t!==n&&e(o,a);return h(a,s?"update":"add"),g(),a},removeLink:function(t,n){void 0!==n&&(t=O(t,n));return M(t)},removeNode:w,getNode:_,getNodeCount:x,getLinkCount:k,getEdgeCount:k,getLinksCount:k,getNodesCount:x,getLinks:function(t){var n=_(t);return n?n.links:null},forEachNode:C,forEachLinkedNode:function(t,n,e){var r=_(t);if(r&&r.links&&"function"==typeof n)return e?function(t,n,e){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value;if(o.fromId===n&&e(a.get(o.toId),o))return!0;i=r.next()}}(r.links,t,n):function(t,n,e){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value,u=o.fromId===n?o.toId:o.fromId;if(e(a.get(u),o))return!0;i=r.next()}}(r.links,t,n)},forEachLink:function(t){if("function"==typeof t)for(var n=u.values(),e=n.next();!e.done;){if(t(e.value))return!0;e=n.next()}},beginUpdate:p,endUpdate:g,clear:function(){p(),C(function(t){w(t.id)}),g()},hasLink:O,hasNode:_,getLink:O};return t(v),function(){var t=v.on;function n(){return v.beginUpdate=p=j,v.endUpdate=g=P,h=y,d=b,v.on=t,t.apply(v,arguments)}v.on=n}(),v;function y(t,n){c.push({link:t,changeType:n})}function b(t,n){c.push({node:t,changeType:n})}function m(t,e){if(void 0===t)throw new Error("Invalid node identifier");p();var r=_(t);return r?(r.data=e,d(r,"update")):(r=new n(t,e),d(r,"add")),a.set(t,r),g(),r}function _(t){return a.get(t)}function w(t){var n=_(t);if(!n)return!1;p();var e=n.links;return e&&(e.forEach(M),n.links=null),a.delete(t),d(n,"remove"),g(),!0}function x(){return a.size}function k(){return u.size}function M(t){if(!t)return!1;if(!u.get(t.id))return!1;p(),u.delete(t.id);var n=_(t.fromId),e=_(t.toId);return n&&n.links.delete(t),e&&e.links.delete(t),h(t,"remove"),g(),!0}function O(t,n){if(void 0!==t&&void 0!==n)return u.get(i(t,n))}function A(){}function j(){l+=1}function P(){0===(l-=1)&&c.length>0&&(v.fire("changed",c),c.length=0)}function C(t){if("function"!=typeof t)throw new Error("Function is expected to iterate over graph nodes. You passed "+t);for(var n=a.values(),e=n.next();!e.done;){if(t(e.value))return!0;e=n.next()}}};var t=dt();function n(t,n){this.id=t,this.links=null,this.data=n}function e(t,n){t.links?t.links.add(n):t.links=new Set([n])}function r(t,n,e,r){this.fromId=t,this.toId=n,this.data=e,this.id=r}function i(t,n){return t.toString()+"👉 "+n.toString()}return at}(),_t=ht(mt),wt={exports:{}},xt={exports:{}};function kt(){return gt||(gt=1,pt=function(t){return 0===t?"x":1===t?"y":2===t?"z":"c"+(t+1)}),pt}function Mt(){if(yt)return vt;yt=1;const t=kt();return vt=function(n){return function(e,r){let i=r&&r.indent||0,o=r&&void 0!==r.join?r.join:"\n",a=Array(i+1).join(" "),u=[];for(let r=0;r<n;++r){let n=t(r),i=0===r?"":a;u.push(i+e.replace(/{var}/g,n))}return u.join(o)}}}var Ot,At={exports:{}};var jt,Pt={exports:{}};var Ct,Nt={exports:{}};var Et,St={exports:{}};var Dt,Tt,zt,Bt,$t,It={exports:{}};var Lt,Rt,Ft,qt,Gt={exports:{}};function Ut(){if(Ft)return Rt;Ft=1,Rt=function(s){var l=zt?Tt:(zt=1,Tt=function(t,n,e,r){this.from=t,this.to=n,this.length=e,this.coefficient=r}),f=($t||($t=1,Bt=function t(n,e){var r;if(n||(n={}),e)for(r in e)if(e.hasOwnProperty(r)){var i=n.hasOwnProperty(r),o=typeof e[r];i&&typeof n[r]===o?"object"===o&&(n[r]=t(n[r],e[r])):n[r]=e[r]}return n}),Bt),c=dt();if(s){if(void 0!==s.springCoeff)throw new Error("springCoeff was renamed to springCoefficient");if(void 0!==s.dragCoeff)throw new Error("dragCoeff was renamed to dragCoefficient")}s=f(s,{springLength:10,springCoefficient:.8,gravity:-12,theta:.8,dragCoefficient:.9,timeStep:.5,adaptiveTimeStepWeight:0,dimensions:2,debug:!1});var h=a[s.dimensions];if(!h){var d=s.dimensions;h={Body:t(d,s.debug),createQuadTree:n(d),createBounds:e(d),createDragForce:r(d),createSpringForce:i(d),integrate:o(d)},a[d]=h}var p=h.Body,g=h.createQuadTree,v=h.createBounds,y=h.createDragForce,b=h.createSpringForce,m=h.integrate,_=function(){if(Lt)return Gt.exports;function t(t){return new n("number"==typeof t?t:+new Date)}function n(t){this.seed=t}function e(t){return Math.sqrt(2*Math.PI/t)*Math.pow(1/Math.E*(t+1/(12*t-1/(10*t))),t)}function r(){var t=this.seed;return t=4294967295&(3042594569^(t=4251993797+(t=4294967295&(3550635116+(t=374761393+(t=4294967295&(3345072700^(t=t+2127912214+(t<<12)&4294967295)^t>>>19))+(t<<5)&4294967295)^t<<9))+(t<<3)&4294967295)^t>>>16),this.seed=t,(268435455&t)/268435456}return Lt=1,Gt.exports=t,Gt.exports.random=t,Gt.exports.randomIterator=function(n,e){var r=e||t();if("function"!=typeof r.next)throw new Error("customRandom does not match expected API: next() function is missing");return{forEach:function(t){var e,i,o;for(e=n.length-1;e>0;--e)i=r.next(e+1),o=n[i],n[i]=n[e],n[e]=o,t(o);n.length&&t(n[0])},shuffle:function(){var t,e,i;for(t=n.length-1;t>0;--t)e=r.next(t+1),i=n[e],n[e]=n[t],n[t]=i;return n}}},n.prototype.next=function(t){return Math.floor(this.nextDouble()*t)},n.prototype.nextDouble=r,n.prototype.uniform=r,n.prototype.gaussian=function(){var t,n,e;do{t=(n=2*this.nextDouble()-1)*n+(e=2*this.nextDouble()-1)*e}while(t>=1||0===t);return n*Math.sqrt(-2*Math.log(t)/t)},n.prototype.random=r,n.prototype.levy=function(){var t=1.5,n=Math.pow(e(2.5)*Math.sin(Math.PI*t/2)/(e(1.25)*t*Math.pow(2,.25)),1/t);return this.gaussian()*n/Math.pow(Math.abs(this.gaussian()),1/t)},Gt.exports}().random(42),w=[],x=[],k=g(s,_),M=v(w,s,_),O=b(s,_),A=y(s),j=[],P=new Map,C=0;S("nbody",function(){if(0===w.length)return;k.insertBodies(w);var t=w.length;for(;t--;){var n=w[t];n.isPinned||(n.reset(),k.updateBodyForce(n),A.update(n))}}),S("spring",function(){var t=x.length;for(;t--;)O.update(x[t])});var N={bodies:w,quadTree:k,springs:x,settings:s,addForce:S,removeForce:function(t){var n=j.indexOf(P.get(t));if(n<0)return;j.splice(n,1),P.delete(t)},getForces:function(){return P},step:function(){for(var t=0;t<j.length;++t)j[t](C);var n=m(w,s.timeStep,s.adaptiveTimeStepWeight);return C+=1,n},addBody:function(t){if(!t)throw new Error("Body is required");return w.push(t),t},addBodyAt:function(t){if(!t)throw new Error("Body position is required");var n=(t=>new p(t))(t);return w.push(n),n},removeBody:function(t){if(t){var n=w.indexOf(t);if(!(n<0))return w.splice(n,1),0===w.length&&M.reset(),!0}},addSpring:function(t,n,e,r){if(!t||!n)throw new Error("Cannot add null spring to force simulator");"number"!=typeof e&&(e=-1);var i=new l(t,n,e,r>=0?r:-1);return x.push(i),i},getTotalMovement:function(){return 0},removeSpring:function(t){if(t){var n=x.indexOf(t);return n>-1?(x.splice(n,1),!0):void 0}},getBestNewBodyPosition:function(t){return M.getBestNewPosition(t)},getBBox:E,getBoundingBox:E,invalidateBBox:function(){console.warn("invalidateBBox() is deprecated, bounds always recomputed on `getBBox()` call")},gravity:function(t){return void 0!==t?(s.gravity=t,k.options({gravity:t}),this):s.gravity},theta:function(t){return void 0!==t?(s.theta=t,k.options({theta:t}),this):s.theta},random:_};return function(t,n){for(var e in t)u(t,n,e)}(s,N),c(N),N;function E(){return M.update(),M.box}function S(t,n){if(P.has(t))throw new Error("Force "+t+" is already added");P.set(t,n),j.push(n)}};var t=function(){if(bt)return xt.exports;bt=1;const t=Mt();function n(t,n){return`\n${r(t,n)}\n${e(t)}\nreturn {Body: Body, Vector: Vector};\n`}function e(n){let e=t(n),r=e("{var}",{join:", "});return`\nfunction Body(${r}) {\n this.isPinned = false;\n this.pos = new Vector(${r});\n this.force = new Vector();\n this.velocity = new Vector();\n this.mass = 1;\n\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.reset = function() {\n this.force.reset();\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.setPosition = function (${r}) {\n ${e("this.pos.{var} = {var} || 0;",{indent:2})}\n};`}function r(n,e){let r=t(n),i="";return e&&(i=`${r("\n\t var v{var};\n\tObject.defineProperty(this, '{var}', {\n\t set: function(v) { \n\t if (!Number.isFinite(v)) throw new Error('Cannot set non-numbers to {var}');\n\t v{var} = v; \n\t },\n\t get: function() { return v{var}; }\n\t});")}`),`function Vector(${r("{var}",{join:", "})}) {\n ${i}\n if (typeof arguments[0] === 'object') {\n // could be another vector\n let v = arguments[0];\n ${r('if (!Number.isFinite(v.{var})) throw new Error("Expected value is not a finite number at Vector constructor ({var})");',{indent:4})}\n ${r("this.{var} = v.{var};",{indent:4})}\n } else {\n ${r('this.{var} = typeof {var} === "number" ? {var} : 0;',{indent:4})}\n }\n }\n \n Vector.prototype.reset = function () {\n ${r("this.{var} = ",{join:""})}0;\n };`}return xt.exports=function(t,e){let r=n(t,e),{Body:i}=new Function(r)();return i},xt.exports.generateCreateBodyFunctionBody=n,xt.exports.getVectorCode=r,xt.exports.getBodyCode=e,xt.exports}(),n=function(){if(Ot)return At.exports;Ot=1;const t=Mt(),n=kt();function e(e){let s=t(e),l=Math.pow(2,e);return`\n${u()}\n${a(e)}\n${r(e)}\n${o(e)}\n${i(e)}\n\nfunction createQuadTree(options, random) {\n options = options || {};\n options.gravity = typeof options.gravity === 'number' ? options.gravity : -1;\n options.theta = typeof options.theta === 'number' ? options.theta : 0.8;\n\n var gravity = options.gravity;\n var updateQueue = [];\n var insertStack = new InsertStack();\n var theta = options.theta;\n\n var nodesCache = [];\n var currentInCache = 0;\n var root = newNode();\n\n return {\n insertBodies: insertBodies,\n\n /**\n * Gets root node if it is present\n */\n getRoot: function() {\n return root;\n },\n\n updateBodyForce: update,\n\n options: function(newOptions) {\n if (newOptions) {\n if (typeof newOptions.gravity === 'number') {\n gravity = newOptions.gravity;\n }\n if (typeof newOptions.theta === 'number') {\n theta = newOptions.theta;\n }\n\n return this;\n }\n\n return {\n gravity: gravity,\n theta: theta\n };\n }\n };\n\n function newNode() {\n // To avoid pressure on GC we reuse nodes.\n var node = nodesCache[currentInCache];\n if (node) {\n${function(t){let n=[];for(let e=0;e<l;++e)n.push(`${t}quad${e} = null;`);return n.join("\n")}(" node.")}\n node.body = null;\n node.mass = ${s("node.mass_{var} = ",{join:""})}0;\n ${s("node.min_{var} = node.max_{var} = ",{join:""})}0;\n } else {\n node = new QuadNode();\n nodesCache[currentInCache] = node;\n }\n\n ++currentInCache;\n return node;\n }\n\n function update(sourceBody) {\n var queue = updateQueue;\n var v;\n ${s("var d{var};",{indent:4})}\n var r; \n ${s("var f{var} = 0;",{indent:4})}\n var queueLength = 1;\n var shiftIdx = 0;\n var pushIdx = 1;\n\n queue[0] = root;\n\n while (queueLength) {\n var node = queue[shiftIdx];\n var body = node.body;\n\n queueLength -= 1;\n shiftIdx += 1;\n var differentBody = (body !== sourceBody);\n if (body && differentBody) {\n // If the current node is a leaf node (and it is not source body),\n // calculate the force exerted by the current node on body, and add this\n // amount to body's net force.\n ${s("d{var} = body.pos.{var} - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Poor man's protection against zero distance.\n ${s("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n }\n\n // This is standard gravitation force calculation but we divide\n // by r^3 to save two operations when normalizing force vector.\n v = gravity * body.mass * sourceBody.mass / (r * r * r);\n ${s("f{var} += v * d{var};",{indent:8})}\n } else if (differentBody) {\n // Otherwise, calculate the ratio s / r, where s is the width of the region\n // represented by the internal node, and r is the distance between the body\n // and the node's center-of-mass\n ${s("d{var} = node.mass_{var} / node.mass - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Sorry about code duplication. I don't want to create many functions\n // right away. Just want to see performance first.\n ${s("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n }\n // If s / r < θ, treat this internal node as a single body, and calculate the\n // force it exerts on sourceBody, and add this amount to sourceBody's net force.\n if ((node.max_${n(0)} - node.min_${n(0)}) / r < theta) {\n // in the if statement above we consider node's width only\n // because the region was made into square during tree creation.\n // Thus there is no difference between using width or height.\n v = gravity * node.mass * sourceBody.mass / (r * r * r);\n ${s("f{var} += v * d{var};",{indent:10})}\n } else {\n // Otherwise, run the procedure recursively on each of the current node's children.\n\n // I intentionally unfolded this loop, to save several CPU cycles.\n${function(){let t=Array(11).join(" "),n=[];for(let e=0;e<l;++e)n.push(t+`if (node.quad${e}) {`),n.push(t+` queue[pushIdx] = node.quad${e};`),n.push(t+" queueLength += 1;"),n.push(t+" pushIdx += 1;"),n.push(t+"}");return n.join("\n")}()}\n }\n }\n }\n\n ${s("sourceBody.force.{var} += f{var};",{indent:4})}\n }\n\n function insertBodies(bodies) {\n ${s("var {var}min = Number.MAX_VALUE;",{indent:4})}\n ${s("var {var}max = Number.MIN_VALUE;",{indent:4})}\n var i = bodies.length;\n\n // To reduce quad tree depth we are looking for exact bounding box of all particles.\n while (i--) {\n var pos = bodies[i].pos;\n ${s("if (pos.{var} < {var}min) {var}min = pos.{var};",{indent:6})}\n ${s("if (pos.{var} > {var}max) {var}max = pos.{var};",{indent:6})}\n }\n\n // Makes the bounds square.\n var maxSideLength = -Infinity;\n ${s("if ({var}max - {var}min > maxSideLength) maxSideLength = {var}max - {var}min ;",{indent:4})}\n\n currentInCache = 0;\n root = newNode();\n ${s("root.min_{var} = {var}min;",{indent:4})}\n ${s("root.max_{var} = {var}min + maxSideLength;",{indent:4})}\n\n i = bodies.length - 1;\n if (i >= 0) {\n root.body = bodies[i];\n }\n while (i--) {\n insert(bodies[i], root);\n }\n }\n\n function insert(newBody) {\n insertStack.reset();\n insertStack.push(root, newBody);\n\n while (!insertStack.isEmpty()) {\n var stackItem = insertStack.pop();\n var node = stackItem.node;\n var body = stackItem.body;\n\n if (!node.body) {\n // This is internal node. Update the total mass of the node and center-of-mass.\n ${s("var {var} = body.pos.{var};",{indent:8})}\n node.mass += body.mass;\n ${s("node.mass_{var} += body.mass * {var};",{indent:8})}\n\n // Recursively insert the body in the appropriate quadrant.\n // But first find the appropriate quadrant.\n var quadIdx = 0; // Assume we are in the 0's quad.\n ${s("var min_{var} = node.min_{var};",{indent:8})}\n ${s("var max_{var} = (min_{var} + node.max_{var}) / 2;",{indent:8})}\n\n${function(){let t=[],r=Array(8+1).join(" ");for(let i=0;i<e;++i)t.push(r+`if (${n(i)} > max_${n(i)}) {`),t.push(r+` quadIdx = quadIdx + ${Math.pow(2,i)};`),t.push(r+` min_${n(i)} = max_${n(i)};`),t.push(r+` max_${n(i)} = node.max_${n(i)};`),t.push(r+"}");return t.join("\n")}()}\n\n var child = getChild(node, quadIdx);\n\n if (!child) {\n // The node is internal but this quadrant is not taken. Add\n // subnode to it.\n child = newNode();\n ${s("child.min_{var} = min_{var};",{indent:10})}\n ${s("child.max_{var} = max_{var};",{indent:10})}\n child.body = body;\n\n setChild(node, quadIdx, child);\n } else {\n // continue searching in this quadrant.\n insertStack.push(child, body);\n }\n } else {\n // We are trying to add to the leaf node.\n // We have to convert current leaf into internal node\n // and continue adding two nodes.\n var oldBody = node.body;\n node.body = null; // internal nodes do not cary bodies\n\n if (isSamePosition(oldBody.pos, body.pos)) {\n // Prevent infinite subdivision by bumping one node\n // anywhere in this quadrant\n var retriesCount = 3;\n do {\n var offset = random.nextDouble();\n ${s("var d{var} = (node.max_{var} - node.min_{var}) * offset;",{indent:12})}\n\n ${s("oldBody.pos.{var} = node.min_{var} + d{var};",{indent:12})}\n retriesCount -= 1;\n // Make sure we don't bump it out of the box. If we do, next iteration should fix it\n } while (retriesCount > 0 && isSamePosition(oldBody.pos, body.pos));\n\n if (retriesCount === 0 && isSamePosition(oldBody.pos, body.pos)) {\n // This is very bad, we ran out of precision.\n // if we do not return from the method we'll get into\n // infinite loop here. So we sacrifice correctness of layout, and keep the app running\n // Next layout iteration should get larger bounding box in the first step and fix this\n return;\n }\n }\n // Next iteration should subdivide node further.\n insertStack.push(node, oldBody);\n insertStack.push(node, body);\n }\n }\n }\n}\nreturn createQuadTree;\n\n`}function r(n){let e=t(n);return`\n function isSamePosition(point1, point2) {\n ${e("var d{var} = Math.abs(point1.{var} - point2.{var});",{indent:2})}\n \n return ${e("d{var} < 1e-8",{join:" && "})};\n } \n`}function i(t){var n=Math.pow(2,t);return`\nfunction setChild(node, idx, child) {\n ${function(){let t=[];for(let e=0;e<n;++e){let n=0===e?" ":" else ";t.push(`${n}if (idx === ${e}) node.quad${e} = child;`)}return t.join("\n")}()}\n}`}function o(t){return`function getChild(node, idx) {\n${function(){let n=[],e=Math.pow(2,t);for(let t=0;t<e;++t)n.push(` if (idx === ${t}) return node.quad${t};`);return n.join("\n")}()}\n return null;\n}`}function a(n){let e=t(n),r=Math.pow(2,n);return`\nfunction QuadNode() {\n // body stored inside this node. In quad tree only leaf nodes (by construction)\n // contain bodies:\n this.body = null;\n\n // Child nodes are stored in quads. Each quad is presented by number:\n // 0 | 1\n // -----\n // 2 | 3\n${function(t){let n=[];for(let e=0;e<r;++e)n.push(`${t}quad${e} = null;`);return n.join("\n")}(" this.")}\n\n // Total mass of current node\n this.mass = 0;\n\n // Center of mass coordinates\n ${e("this.mass_{var} = 0;",{indent:2})}\n\n // bounding box coordinates\n ${e("this.min_{var} = 0;",{indent:2})}\n ${e("this.max_{var} = 0;",{indent:2})}\n}\n`}function u(){return"\n/**\n * Our implementation of QuadTree is non-recursive to avoid GC hit\n * This data structure represent stack of elements\n * which we are trying to insert into quad tree.\n */\nfunction InsertStack () {\n this.stack = [];\n this.popIdx = 0;\n}\n\nInsertStack.prototype = {\n isEmpty: function() {\n return this.popIdx === 0;\n },\n push: function (node, body) {\n var item = this.stack[this.popIdx];\n if (!item) {\n // we are trying to avoid memory pressure: create new element\n // only when absolutely necessary\n this.stack[this.popIdx] = new InsertStackElement(node, body);\n } else {\n item.node = node;\n item.body = body;\n }\n ++this.popIdx;\n },\n pop: function () {\n if (this.popIdx > 0) {\n return this.stack[--this.popIdx];\n }\n },\n reset: function () {\n this.popIdx = 0;\n }\n};\n\nfunction InsertStackElement(node, body) {\n this.node = node; // QuadTree node\n this.body = body; // physical body which needs to be inserted to node\n}\n"}return At.exports=function(t){let n=e(t);return new Function(n)()},At.exports.generateQuadTreeFunctionBody=e,At.exports.getInsertStackCode=u,At.exports.getQuadNodeCode=a,At.exports.isSamePosition=r,At.exports.getChildBodyCode=o,At.exports.setChildBodyCode=i,At.exports}(),e=function(){if(jt)return Pt.exports;jt=1,Pt.exports=function(t){let e=n(t);return new Function("bodies","settings","random",e)},Pt.exports.generateFunctionBody=n;const t=Mt();function n(n){let e=t(n);return`\n var boundingBox = {\n ${e("min_{var}: 0, max_{var}: 0,",{indent:4})}\n };\n\n return {\n box: boundingBox,\n\n update: updateBoundingBox,\n\n reset: resetBoundingBox,\n\n getBestNewPosition: function (neighbors) {\n var ${e("base_{var} = 0",{join:", "})};\n\n if (neighbors.length) {\n for (var i = 0; i < neighbors.length; ++i) {\n let neighborPos = neighbors[i].pos;\n ${e("base_{var} += neighborPos.{var};",{indent:10})}\n }\n\n ${e("base_{var} /= neighbors.length;",{indent:8})}\n } else {\n ${e("base_{var} = (boundingBox.min_{var} + boundingBox.max_{var}) / 2;",{indent:8})}\n }\n\n var springLength = settings.springLength;\n return {\n ${e("{var}: base_{var} + (random.nextDouble() - 0.5) * springLength,",{indent:8})}\n };\n }\n };\n\n function updateBoundingBox() {\n var i = bodies.length;\n if (i === 0) return; // No bodies - no borders.\n\n ${e("var max_{var} = -Infinity;",{indent:4})}\n ${e("var min_{var} = Infinity;",{indent:4})}\n\n while(i--) {\n // this is O(n), it could be done faster with quadtree, if we check the root node bounds\n var bodyPos = bodies[i].pos;\n ${e("if (bodyPos.{var} < min_{var}) min_{var} = bodyPos.{var};",{indent:6})}\n ${e("if (bodyPos.{var} > max_{var}) max_{var} = bodyPos.{var};",{indent:6})}\n }\n\n ${e("boundingBox.min_{var} = min_{var};",{indent:4})}\n ${e("boundingBox.max_{var} = max_{var};",{indent:4})}\n }\n\n function resetBoundingBox() {\n ${e("boundingBox.min_{var} = boundingBox.max_{var} = 0;",{indent:4})}\n }\n`}return Pt.exports}(),r=function(){if(Ct)return Nt.exports;Ct=1;const t=Mt();function n(n){return`\n if (!Number.isFinite(options.dragCoefficient)) throw new Error('dragCoefficient is not a finite number');\n\n return {\n update: function(body) {\n ${t(n)("body.force.{var} -= options.dragCoefficient * body.velocity.{var};",{indent:6})}\n }\n };\n`}return Nt.exports=function(t){let e=n(t);return new Function("options",e)},Nt.exports.generateCreateDragForceFunctionBody=n,Nt.exports}(),i=function(){if(Et)return St.exports;Et=1;const t=Mt();function n(n){let e=t(n);return`\n if (!Number.isFinite(options.springCoefficient)) throw new Error('Spring coefficient is not a number');\n if (!Number.isFinite(op