Comparing version 1.1.2 to 2.0.0
@@ -1,7 +0,7 @@ | ||
// https://d3js.org/d3-force/ v1.1.2 Copyright 2018 Mike Bostock | ||
// https://d3js.org/d3-force/ v2.0.0 Copyright 2018 Mike Bostock | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-collection'), require('d3-dispatch'), require('d3-timer')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-collection', 'd3-dispatch', 'd3-timer'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Quadtree,d3Collection,d3Dispatch,d3Timer) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-dispatch'), require('d3-timer')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-dispatch', 'd3-timer'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Quadtree,d3Dispatch,d3Timer) { 'use strict'; | ||
@@ -200,3 +200,3 @@ function center(x, y) { | ||
m = links.length, | ||
nodeById = d3Collection.map(nodes, id), | ||
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])), | ||
link; | ||
@@ -282,3 +282,3 @@ | ||
velocityDecay = 0.6, | ||
forces = d3Collection.map(), | ||
forces = new Map(), | ||
stepper = d3Timer.timer(step), | ||
@@ -298,18 +298,24 @@ event = d3Dispatch.dispatch("tick", "end"); | ||
function tick() { | ||
function tick(iterations) { | ||
var i, n = nodes.length, node; | ||
alpha += (alphaTarget - alpha) * alphaDecay; | ||
if (iterations === undefined) iterations = 1; | ||
forces.each(function(force) { | ||
force(alpha); | ||
}); | ||
for (var k = 0; k < iterations; ++k) { | ||
alpha += (alphaTarget - alpha) * alphaDecay; | ||
for (i = 0; i < n; ++i) { | ||
node = nodes[i]; | ||
if (node.fx == null) node.x += node.vx *= velocityDecay; | ||
else node.x = node.fx, node.vx = 0; | ||
if (node.fy == null) node.y += node.vy *= velocityDecay; | ||
else node.y = node.fy, node.vy = 0; | ||
forces.forEach(function(force) { | ||
force(alpha); | ||
}); | ||
for (i = 0; i < n; ++i) { | ||
node = nodes[i]; | ||
if (node.fx == null) node.x += node.vx *= velocityDecay; | ||
else node.x = node.fx, node.vx = 0; | ||
if (node.fy == null) node.y += node.vy *= velocityDecay; | ||
else node.y = node.fy, node.vy = 0; | ||
} | ||
} | ||
return simulation; | ||
} | ||
@@ -320,2 +326,4 @@ | ||
node = nodes[i], node.index = i; | ||
if (!isNaN(node.fx)) node.x = node.fx; | ||
if (!isNaN(node.fy)) node.y = node.fy; | ||
if (isNaN(node.x) || isNaN(node.y)) { | ||
@@ -351,3 +359,3 @@ var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle; | ||
nodes: function(_) { | ||
return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes; | ||
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes; | ||
}, | ||
@@ -376,3 +384,3 @@ | ||
force: function(name, _) { | ||
return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name); | ||
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name); | ||
}, | ||
@@ -379,0 +387,0 @@ |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-force/ v1.1.2 Copyright 2018 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 function(){return n}}function o(){return 1e-6*(Math.random()-.5)}function f(n){return n.x+n.vx}function a(n){return n.y+n.vy}function c(n){return n.index}function l(n,t){var e=n.get(t);if(!e)throw new Error("missing: "+t);return e}function h(n){return n.x}function v(n){return n.y}var y=10,d=Math.PI*(3-Math.sqrt(5));n.forceCenter=function(n,t){var e;function r(){var r,i,u=e.length,o=0,f=0;for(r=0;r<u;++r)o+=(i=e[r]).x,f+=i.y;for(o=o/u-n,f=f/u-t,r=0;r<u;++r)(i=e[r]).x-=o,i.y-=f}return null==n&&(n=0),null==t&&(t=0),r.initialize=function(n){e=n},r.x=function(t){return arguments.length?(n=+t,r):n},r.y=function(n){return arguments.length?(t=+n,r):t},r},n.forceCollide=function(n){var e,r,i=1,c=1;function l(){for(var n,u,l,v,y,d,x,g=e.length,s=0;s<c;++s)for(u=t.quadtree(e,f,a).visitAfter(h),n=0;n<g;++n)l=e[n],d=r[l.index],x=d*d,v=l.x+l.vx,y=l.y+l.vy,u.visit(p);function p(n,t,e,r,u){var f=n.data,a=n.r,c=d+a;if(!f)return t>v+c||r<v-c||e>y+c||u<y-c;if(f.index>l.index){var h=v-f.x-f.vx,g=y-f.y-f.vy,s=h*h+g*g;s<c*c&&(0===h&&(s+=(h=o())*h),0===g&&(s+=(g=o())*g),s=(c-(s=Math.sqrt(s)))/s*i,l.vx+=(h*=s)*(c=(a*=a)/(x+a)),l.vy+=(g*=s)*c,f.vx-=h*(c=1-c),f.vy-=g*c)}}}function h(n){if(n.data)return n.r=r[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 v(){if(e){var t,i,u=e.length;for(r=new Array(u),t=0;t<u;++t)i=e[t],r[i.index]=+n(i,t,e)}}return"function"!=typeof n&&(n=u(null==n?1:+n)),l.initialize=function(n){e=n,v()},l.iterations=function(n){return arguments.length?(c=+n,l):c},l.strength=function(n){return arguments.length?(i=+n,l):i},l.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),v(),l):n},l},n.forceLink=function(n){var t,r,i,f,a,h=c,v=function(n){return 1/Math.min(f[n.source.index],f[n.target.index])},y=u(30),d=1;function x(e){for(var i=0,u=n.length;i<d;++i)for(var f,c,l,h,v,y,x,g=0;g<u;++g)c=(f=n[g]).source,h=(l=f.target).x+l.vx-c.x-c.vx||o(),v=l.y+l.vy-c.y-c.vy||o(),h*=y=((y=Math.sqrt(h*h+v*v))-r[g])/y*e*t[g],v*=y,l.vx-=h*(x=a[g]),l.vy-=v*x,c.vx+=h*(x=1-x),c.vy+=v*x}function g(){if(i){var u,o,c=i.length,v=n.length,y=e.map(i,h);for(u=0,f=new Array(c);u<v;++u)(o=n[u]).index=u,"object"!=typeof o.source&&(o.source=l(y,o.source)),"object"!=typeof o.target&&(o.target=l(y,o.target)),f[o.source.index]=(f[o.source.index]||0)+1,f[o.target.index]=(f[o.target.index]||0)+1;for(u=0,a=new Array(v);u<v;++u)o=n[u],a[u]=f[o.source.index]/(f[o.source.index]+f[o.target.index]);t=new Array(v),s(),r=new Array(v),p()}}function s(){if(i)for(var e=0,r=n.length;e<r;++e)t[e]=+v(n[e],e,n)}function p(){if(i)for(var t=0,e=n.length;t<e;++t)r[t]=+y(n[t],t,n)}return null==n&&(n=[]),x.initialize=function(n){i=n,g()},x.links=function(t){return arguments.length?(n=t,g(),x):n},x.id=function(n){return arguments.length?(h=n,x):h},x.iterations=function(n){return arguments.length?(d=+n,x):d},x.strength=function(n){return arguments.length?(v="function"==typeof n?n:u(+n),s(),x):v},x.distance=function(n){return arguments.length?(y="function"==typeof n?n:u(+n),p(),x):y},x},n.forceManyBody=function(){var n,e,r,i,f=u(-30),a=1,c=1/0,l=.81;function y(i){var u,o=n.length,f=t.quadtree(n,h,v).visitAfter(x);for(r=i,u=0;u<o;++u)e=n[u],f.visit(g)}function d(){if(n){var t,e,r=n.length;for(i=new Array(r),t=0;t<r;++t)e=n[t],i[e.index]=+f(e,t,n)}}function x(n){var t,e,r,u,o,f=0,a=0;if(n.length){for(r=u=o=0;o<4;++o)(t=n[o])&&(e=Math.abs(t.value))&&(f+=t.value,a+=e,r+=e*t.x,u+=e*t.y);n.x=r/a,n.y=u/a}else{(t=n).x=t.data.x,t.y=t.data.y;do{f+=i[t.data.index]}while(t=t.next)}n.value=f}function g(n,t,u,f){if(!n.value)return!0;var h=n.x-e.x,v=n.y-e.y,y=f-t,d=h*h+v*v;if(y*y/l<d)return d<c&&(0===h&&(d+=(h=o())*h),0===v&&(d+=(v=o())*v),d<a&&(d=Math.sqrt(a*d)),e.vx+=h*n.value*r/d,e.vy+=v*n.value*r/d),!0;if(!(n.length||d>=c)){(n.data!==e||n.next)&&(0===h&&(d+=(h=o())*h),0===v&&(d+=(v=o())*v),d<a&&(d=Math.sqrt(a*d)));do{n.data!==e&&(y=i[n.data.index]*r/d,e.vx+=h*y,e.vy+=v*y)}while(n=n.next)}}return y.initialize=function(t){n=t,d()},y.strength=function(n){return arguments.length?(f="function"==typeof n?n:u(+n),d(),y):f},y.distanceMin=function(n){return arguments.length?(a=n*n,y):Math.sqrt(a)},y.distanceMax=function(n){return arguments.length?(c=n*n,y):Math.sqrt(c)},y.theta=function(n){return arguments.length?(l=n*n,y):Math.sqrt(l)},y},n.forceRadial=function(n,t,e){var r,i,o,f=u(.1);function a(n){for(var u=0,f=r.length;u<f;++u){var a=r[u],c=a.x-t||1e-6,l=a.y-e||1e-6,h=Math.sqrt(c*c+l*l),v=(o[u]-h)*i[u]*n/h;a.vx+=c*v,a.vy+=l*v}}function c(){if(r){var t,e=r.length;for(i=new Array(e),o=new Array(e),t=0;t<e;++t)o[t]=+n(r[t],t,r),i[t]=isNaN(o[t])?0:+f(r[t],t,r)}}return"function"!=typeof n&&(n=u(+n)),null==t&&(t=0),null==e&&(e=0),a.initialize=function(n){r=n,c()},a.strength=function(n){return arguments.length?(f="function"==typeof n?n:u(+n),c(),a):f},a.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),c(),a):n},a.x=function(n){return arguments.length?(t=+n,a):t},a.y=function(n){return arguments.length?(e=+n,a):e},a},n.forceSimulation=function(n){var t,u=1,o=.001,f=1-Math.pow(o,1/300),a=0,c=.6,l=e.map(),h=i.timer(x),v=r.dispatch("tick","end");function x(){g(),v.call("tick",t),u<o&&(h.stop(),v.call("end",t))}function g(){var t,e,r=n.length;for(u+=(a-u)*f,l.each(function(n){n(u)}),t=0;t<r;++t)null==(e=n[t]).fx?e.x+=e.vx*=c:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=c:(e.y=e.fy,e.vy=0)}function s(){for(var t,e=0,r=n.length;e<r;++e){if((t=n[e]).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 p(t){return t.initialize&&t.initialize(n),t}return null==n&&(n=[]),s(),t={tick:g,restart:function(){return h.restart(x),t},stop:function(){return h.stop(),t},nodes:function(e){return arguments.length?(n=e,s(),l.each(p),t):n},alpha:function(n){return arguments.length?(u=+n,t):u},alphaMin:function(n){return arguments.length?(o=+n,t):o},alphaDecay:function(n){return arguments.length?(f=+n,t):+f},alphaTarget:function(n){return arguments.length?(a=+n,t):a},velocityDecay:function(n){return arguments.length?(c=1-n,t):1-c},force:function(n,e){return arguments.length>1?(null==e?l.remove(n):l.set(n,p(e)),t):l.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,e){return arguments.length>1?(v.on(n,e),t):v.on(n)}}},n.forceX=function(n){var t,e,r,i=u(.1);function o(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vx+=(r[u]-i.x)*e[u]*n}function f(){if(t){var u,o=t.length;for(e=new Array(o),r=new Array(o),u=0;u<o;++u)e[u]=isNaN(r[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=u(null==n?0:+n)),o.initialize=function(n){t=n,f()},o.strength=function(n){return arguments.length?(i="function"==typeof n?n:u(+n),f(),o):i},o.x=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),f(),o):n},o},n.forceY=function(n){var t,e,r,i=u(.1);function o(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vy+=(r[u]-i.y)*e[u]*n}function f(){if(t){var u,o=t.length;for(e=new Array(o),r=new Array(o),u=0;u<o;++u)e[u]=isNaN(r[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=u(null==n?0:+n)),o.initialize=function(n){t=n,f()},o.strength=function(n){return arguments.length?(i="function"==typeof n?n:u(+n),f(),o):i},o.y=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),f(),o):n},o},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-force/ v2.0.0 Copyright 2018 Mike Bostock | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3)}(this,function(n,t,r,e){"use strict";function i(n){return function(){return n}}function u(){return 1e-6*(Math.random()-.5)}function o(n){return n.x+n.vx}function f(n){return n.y+n.vy}function a(n){return n.index}function c(n,t){var r=n.get(t);if(!r)throw new Error("missing: "+t);return r}function l(n){return n.x}function h(n){return n.y}var v=10,y=Math.PI*(3-Math.sqrt(5));n.forceCenter=function(n,t){var r;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}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){var r,e,a=1,c=1;function l(){for(var n,i,l,v,y,d,x,g=r.length,s=0;s<c;++s)for(i=t.quadtree(r,o,f).visitAfter(h),n=0;n<g;++n)l=r[n],d=e[l.index],x=d*d,v=l.x+l.vx,y=l.y+l.vy,i.visit(p);function p(n,t,r,e,i){var o=n.data,f=n.r,c=d+f;if(!o)return t>v+c||e<v-c||r>y+c||i<y-c;if(o.index>l.index){var h=v-o.x-o.vx,g=y-o.y-o.vy,s=h*h+g*g;s<c*c&&(0===h&&(s+=(h=u())*h),0===g&&(s+=(g=u())*g),s=(c-(s=Math.sqrt(s)))/s*a,l.vx+=(h*=s)*(c=(f*=f)/(x+f)),l.vy+=(g*=s)*c,o.vx-=h*(c=1-c),o.vy-=g*c)}}}function h(n){if(n.data)return n.r=e[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 v(){if(r){var t,i,u=r.length;for(e=new Array(u),t=0;t<u;++t)i=r[t],e[i.index]=+n(i,t,r)}}return"function"!=typeof n&&(n=i(null==n?1:+n)),l.initialize=function(n){r=n,v()},l.iterations=function(n){return arguments.length?(c=+n,l):c},l.strength=function(n){return arguments.length?(a=+n,l):a},l.radius=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),v(),l):n},l},n.forceLink=function(n){var t,r,e,o,f,l=a,h=function(n){return 1/Math.min(o[n.source.index],o[n.target.index])},v=i(30),y=1;function d(e){for(var i=0,o=n.length;i<y;++i)for(var a,c,l,h,v,d,x,g=0;g<o;++g)c=(a=n[g]).source,h=(l=a.target).x+l.vx-c.x-c.vx||u(),v=l.y+l.vy-c.y-c.vy||u(),h*=d=((d=Math.sqrt(h*h+v*v))-r[g])/d*e*t[g],v*=d,l.vx-=h*(x=f[g]),l.vy-=v*x,c.vx+=h*(x=1-x),c.vy+=v*x}function x(){if(e){var i,u,a=e.length,h=n.length,v=new Map(e.map((n,t)=>[l(n,t,e),n]));for(i=0,o=new Array(a);i<h;++i)(u=n[i]).index=i,"object"!=typeof u.source&&(u.source=c(v,u.source)),"object"!=typeof u.target&&(u.target=c(v,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,f=new Array(h);i<h;++i)u=n[i],f[i]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);t=new Array(h),g(),r=new Array(h),s()}}function g(){if(e)for(var r=0,i=n.length;r<i;++r)t[r]=+h(n[r],r,n)}function s(){if(e)for(var t=0,i=n.length;t<i;++t)r[t]=+v(n[t],t,n)}return null==n&&(n=[]),d.initialize=function(n){e=n,x()},d.links=function(t){return arguments.length?(n=t,x(),d):n},d.id=function(n){return arguments.length?(l=n,d):l},d.iterations=function(n){return arguments.length?(y=+n,d):y},d.strength=function(n){return arguments.length?(h="function"==typeof n?n:i(+n),g(),d):h},d.distance=function(n){return arguments.length?(v="function"==typeof n?n:i(+n),s(),d):v},d},n.forceManyBody=function(){var n,r,e,o,f=i(-30),a=1,c=1/0,v=.81;function y(i){var u,o=n.length,f=t.quadtree(n,l,h).visitAfter(x);for(e=i,u=0;u<o;++u)r=n[u],f.visit(g)}function d(){if(n){var t,r,e=n.length;for(o=new Array(e),t=0;t<e;++t)r=n[t],o[r.index]=+f(r,t,n)}}function x(n){var t,r,e,i,u,f=0,a=0;if(n.length){for(e=i=u=0;u<4;++u)(t=n[u])&&(r=Math.abs(t.value))&&(f+=t.value,a+=r,e+=r*t.x,i+=r*t.y);n.x=e/a,n.y=i/a}else{(t=n).x=t.data.x,t.y=t.data.y;do{f+=o[t.data.index]}while(t=t.next)}n.value=f}function g(n,t,i,f){if(!n.value)return!0;var l=n.x-r.x,h=n.y-r.y,y=f-t,d=l*l+h*h;if(y*y/v<d)return d<c&&(0===l&&(d+=(l=u())*l),0===h&&(d+=(h=u())*h),d<a&&(d=Math.sqrt(a*d)),r.vx+=l*n.value*e/d,r.vy+=h*n.value*e/d),!0;if(!(n.length||d>=c)){(n.data!==r||n.next)&&(0===l&&(d+=(l=u())*l),0===h&&(d+=(h=u())*h),d<a&&(d=Math.sqrt(a*d)));do{n.data!==r&&(y=o[n.data.index]*e/d,r.vx+=l*y,r.vy+=h*y)}while(n=n.next)}}return y.initialize=function(t){n=t,d()},y.strength=function(n){return arguments.length?(f="function"==typeof n?n:i(+n),d(),y):f},y.distanceMin=function(n){return arguments.length?(a=n*n,y):Math.sqrt(a)},y.distanceMax=function(n){return arguments.length?(c=n*n,y):Math.sqrt(c)},y.theta=function(n){return arguments.length?(v=n*n,y):Math.sqrt(v)},y},n.forceRadial=function(n,t,r){var e,u,o,f=i(.1);function a(n){for(var i=0,f=e.length;i<f;++i){var a=e[i],c=a.x-t||1e-6,l=a.y-r||1e-6,h=Math.sqrt(c*c+l*l),v=(o[i]-h)*u[i]*n/h;a.vx+=c*v,a.vy+=l*v}}function c(){if(e){var t,r=e.length;for(u=new Array(r),o=new Array(r),t=0;t<r;++t)o[t]=+n(e[t],t,e),u[t]=isNaN(o[t])?0:+f(e[t],t,e)}}return"function"!=typeof n&&(n=i(+n)),null==t&&(t=0),null==r&&(r=0),a.initialize=function(n){e=n,c()},a.strength=function(n){return arguments.length?(f="function"==typeof n?n:i(+n),c(),a):f},a.radius=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),c(),a):n},a.x=function(n){return arguments.length?(t=+n,a):t},a.y=function(n){return arguments.length?(r=+n,a):r},a},n.forceSimulation=function(n){var t,i=1,u=.001,o=1-Math.pow(u,1/300),f=0,a=.6,c=new Map,l=e.timer(d),h=r.dispatch("tick","end");function d(){x(),h.call("tick",t),i<u&&(l.stop(),h.call("end",t))}function x(r){var e,u,l=n.length;void 0===r&&(r=1);for(var h=0;h<r;++h)for(i+=(f-i)*o,c.forEach(function(n){n(i)}),e=0;e<l;++e)null==(u=n[e]).fx?u.x+=u.vx*=a:(u.x=u.fx,u.vx=0),null==u.fy?u.y+=u.vy*=a:(u.y=u.fy,u.vy=0);return t}function g(){for(var t,r=0,e=n.length;r<e;++r){if((t=n[r]).index=r,isNaN(t.fx)||(t.x=t.fx),isNaN(t.fy)||(t.y=t.fy),isNaN(t.x)||isNaN(t.y)){var i=v*Math.sqrt(r),u=r*y;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function s(t){return t.initialize&&t.initialize(n),t}return null==n&&(n=[]),g(),t={tick:x,restart:function(){return l.restart(d),t},stop:function(){return l.stop(),t},nodes:function(r){return arguments.length?(n=r,g(),c.forEach(s),t):n},alpha:function(n){return arguments.length?(i=+n,t):i},alphaMin:function(n){return arguments.length?(u=+n,t):u},alphaDecay:function(n){return arguments.length?(o=+n,t):+o},alphaTarget:function(n){return arguments.length?(f=+n,t):f},velocityDecay:function(n){return arguments.length?(a=1-n,t):1-a},force:function(n,r){return arguments.length>1?(null==r?c.delete(n):c.set(n,s(r)),t):c.get(n)},find:function(t,r,e){var i,u,o,f,a,c=0,l=n.length;for(null==e?e=1/0:e*=e,c=0;c<l;++c)(o=(i=t-(f=n[c]).x)*i+(u=r-f.y)*u)<e&&(a=f,e=o);return a},on:function(n,r){return arguments.length>1?(h.on(n,r),t):h.on(n)}}},n.forceX=function(n){var t,r,e,u=i(.1);function o(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vx+=(e[u]-i.x)*r[u]*n}function f(){if(t){var i,o=t.length;for(r=new Array(o),e=new Array(o),i=0;i<o;++i)r[i]=isNaN(e[i]=+n(t[i],i,t))?0:+u(t[i],i,t)}}return"function"!=typeof n&&(n=i(null==n?0:+n)),o.initialize=function(n){t=n,f()},o.strength=function(n){return arguments.length?(u="function"==typeof n?n:i(+n),f(),o):u},o.x=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),f(),o):n},o},n.forceY=function(n){var t,r,e,u=i(.1);function o(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vy+=(e[u]-i.y)*r[u]*n}function f(){if(t){var i,o=t.length;for(r=new Array(o),e=new Array(o),i=0;i<o;++i)r[i]=isNaN(e[i]=+n(t[i],i,t))?0:+u(t[i],i,t)}}return"function"!=typeof n&&(n=i(null==n?0:+n)),o.initialize=function(n){t=n,f()},o.strength=function(n){return arguments.length?(u="function"==typeof n?n:i(+n),f(),o):u},o.y=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),f(),o):n},o},Object.defineProperty(n,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-force", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Force-directed graph layout using velocity Verlet integration.", | ||
@@ -35,4 +35,7 @@ "keywords": [ | ||
}, | ||
"files": [ | ||
"src/**/*.js", | ||
"dist/**/*.js" | ||
], | ||
"dependencies": { | ||
"d3-collection": "1", | ||
"d3-dispatch": "1", | ||
@@ -39,0 +42,0 @@ "d3-quadtree": "1", |
@@ -21,10 +21,9 @@ # d3-force | ||
If you use NPM, `npm install d3-force`. Otherwise, download the [latest release](https://github.com/d3/d3-force/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-force.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported: | ||
If you use NPM, `npm install d3-force`. Otherwise, download the [latest release](https://github.com/d3/d3-force/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-force.v2.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported: | ||
```html | ||
<script src="https://d3js.org/d3-collection.v1.min.js"></script> | ||
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script> | ||
<script src="https://d3js.org/d3-quadtree.v1.min.js"></script> | ||
<script src="https://d3js.org/d3-timer.v1.min.js"></script> | ||
<script src="https://d3js.org/d3-force.v1.min.js"></script> | ||
<script src="https://d3js.org/d3-force.v2.min.js"></script> | ||
<script> | ||
@@ -37,3 +36,3 @@ | ||
[Try d3-force in your browser.](https://tonicdev.com/npm/d3-force) | ||
[Try d3-force in your browser.](https://beta.observablehq.com/@mbostock/d3-force-directed-graph) | ||
@@ -48,14 +47,16 @@ ## API Reference | ||
<a name="simulation_restart" href="#simulation_restart">#</a> <i>simulation</i>.<b>restart</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L80 "Source") | ||
<a name="simulation_restart" href="#simulation_restart">#</a> <i>simulation</i>.<b>restart</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L86 "Source") | ||
Restarts the simulation’s internal timer and returns the simulation. In conjunction with [*simulation*.alphaTarget](#simulation_alphaTarget) or [*simulation*.alpha](#simulation_alpha), this method can be used to “reheat” the simulation during interaction, such as when dragging a node, or to resume the simulation after temporarily pausing it with [*simulation*.stop](#simulation_stop). | ||
<a name="simulation_stop" href="#simulation_stop">#</a> <i>simulation</i>.<b>stop</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L84 "Source") | ||
<a name="simulation_stop" href="#simulation_stop">#</a> <i>simulation</i>.<b>stop</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L90 "Source") | ||
Stops the simulation’s internal timer, if it is running, and returns the simulation. If the timer is already stopped, this method does nothing. This method is useful for running the simulation manually; see [*simulation*.tick](#simulation_tick). | ||
<a name="simulation_tick" href="#simulation_tick">#</a> <i>simulation</i>.<b>tick</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L38 "Source") | ||
<a name="simulation_tick" href="#simulation_tick">#</a> <i>simulation</i>.<b>tick</b>([<i>iterations</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L38 "Source") | ||
Increments the current [*alpha*](#simulation_alpha) by ([*alphaTarget*](#simulation_alphaTarget) - *alpha*) × [*alphaDecay*](#simulation_alphaDecay); then invokes each registered [force](#simulation_force), passing the new *alpha*; then decrements each [node](#simulation_nodes)’s velocity by *velocity* × [*velocityDecay*](#simulation_velocityDecay); lastly increments each node’s position by *velocity*. | ||
Manually steps the simulation by the specified number of *iterations*, and returns the simulation. If *iterations* is not specified, it defaults to 1 (single step). | ||
For each iteration, it increments the current [*alpha*](#simulation_alpha) by ([*alphaTarget*](#simulation_alphaTarget) - *alpha*) × [*alphaDecay*](#simulation_alphaDecay); then invokes each registered [force](#simulation_force), passing the new *alpha*; then decrements each [node](#simulation_nodes)’s velocity by *velocity* × [*velocityDecay*](#simulation_velocityDecay); lastly increments each node’s position by *velocity*. | ||
This method does not dispatch [events](#simulation_on); events are only dispatched by the internal timer when the simulation is started automatically upon [creation](#forceSimulation) or by calling [*simulation*.restart](#simulation_restart). The natural number of ticks when the simulation is started is ⌈*log*([*alphaMin*](#simulation_alphaMin)) / *log*(1 - [*alphaDecay*](#simulation_alphaDecay))⌉; by default, this is 300. | ||
@@ -65,3 +66,3 @@ | ||
<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L88 "Source") | ||
<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L94 "Source") | ||
@@ -89,11 +90,11 @@ If *nodes* is specified, sets the simulation’s nodes to the specified array of objects, initializing their positions and velocities if necessary, and then [re-initializes](#force_initialize) any bound [forces](#simulation_force); returns the simulation. If *nodes* is not specified, returns the simulation’s array of nodes as specified to the [constructor](#forceSimulation). | ||
<a name="simulation_alpha" href="#simulation_alpha">#</a> <i>simulation</i>.<b>alpha</b>([<i>alpha</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L92 "Source") | ||
<a name="simulation_alpha" href="#simulation_alpha">#</a> <i>simulation</i>.<b>alpha</b>([<i>alpha</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L98 "Source") | ||
If *alpha* is specified, sets the current alpha to the specified number in the range [0,1] and returns this simulation. If *alpha* is not specified, returns the current alpha value, which defaults to 1. | ||
<a name="simulation_alphaMin" href="#simulation_alphaMin">#</a> <i>simulation</i>.<b>alphaMin</b>([<i>min</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L96 "Source") | ||
<a name="simulation_alphaMin" href="#simulation_alphaMin">#</a> <i>simulation</i>.<b>alphaMin</b>([<i>min</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L102 "Source") | ||
If *min* is specified, sets the minimum *alpha* to the specified number in the range [0,1] and returns this simulation. If *min* is not specified, returns the current minimum *alpha* value, which defaults to 0.001. The simulation’s internal timer stops when the current [*alpha*](#simulation_alpha) is less than the minimum *alpha*. The default [alpha decay rate](#simulation_alphaDecay) of ~0.0228 corresponds to 300 iterations. | ||
<a name="simulation_alphaDecay" href="#simulation_alphaDecay">#</a> <i>simulation</i>.<b>alphaDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L100 "Source") | ||
<a name="simulation_alphaDecay" href="#simulation_alphaDecay">#</a> <i>simulation</i>.<b>alphaDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L106 "Source") | ||
@@ -104,11 +105,11 @@ If *decay* is specified, sets the [*alpha*](#simulation_alpha) decay rate to the specified number in the range [0,1] and returns this simulation. If *decay* is not specified, returns the current *alpha* decay rate, which defaults to 0.0228… = 1 - *pow*(0.001, 1 / 300) where 0.001 is the default [minimum *alpha*](#simulation_alphaMin). | ||
<a name="simulation_alphaTarget" href="#simulation_alphaTarget">#</a> <i>simulation</i>.<b>alphaTarget</b>([<i>target</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L104 "Source") | ||
<a name="simulation_alphaTarget" href="#simulation_alphaTarget">#</a> <i>simulation</i>.<b>alphaTarget</b>([<i>target</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L110 "Source") | ||
If *target* is specified, sets the current target [*alpha*](#simulation_alpha) to the specified number in the range [0,1] and returns this simulation. If *target* is not specified, returns the current target alpha value, which defaults to 0. | ||
<a name="simulation_velocityDecay" href="#simulation_velocityDecay">#</a> <i>simulation</i>.<b>velocityDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L108 "Source") | ||
<a name="simulation_velocityDecay" href="#simulation_velocityDecay">#</a> <i>simulation</i>.<b>velocityDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L114 "Source") | ||
If *decay* is specified, sets the velocity decay factor to the specified number in the range [0,1] and returns this simulation. If *decay* is not specified, returns the current velocity decay factor, which defaults to 0.4. The decay factor is akin to atmospheric friction; after the application of any forces during a [tick](#simulation_tick), each node’s velocity is multiplied by 1 - *decay*. As with lowering the [alpha decay rate](#simulation_alphaDecay), less velocity decay may converge on a better solution, but risks numerical instabilities and oscillation. | ||
<a name="simulation_force" href="#simulation_force">#</a> <i>simulation</i>.<b>force</b>(<i>name</i>[, <i>force</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L112 "Source") | ||
<a name="simulation_force" href="#simulation_force">#</a> <i>simulation</i>.<b>force</b>(<i>name</i>[, <i>force</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L118 "Source") | ||
@@ -130,7 +131,7 @@ If *force* is specified, assigns the [force](#forces) for the specified *name* and returns this simulation. If *force* is not specified, returns the force with the specified name, or undefined if there is no such force. (By default, new simulations have no forces.) For example, to create a new simulation to layout a graph, you might say: | ||
<a name="simulation_find" href="#simulation_find">#</a> <i>simulation</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>radius</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L116 "Source") | ||
<a name="simulation_find" href="#simulation_find">#</a> <i>simulation</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>radius</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L122 "Source") | ||
Returns the node closest to the position ⟨*x*,*y*⟩ with the given search *radius*. If *radius* is not specified, it defaults to infinity. If there is no node within the search area, returns undefined. | ||
<a name="simulation_on" href="#simulation_on">#</a> <i>simulation</i>.<b>on</b>(<i>typenames</i>, [<i>listener</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L139 "Source") | ||
<a name="simulation_on" href="#simulation_on">#</a> <i>simulation</i>.<b>on</b>(<i>typenames</i>, [<i>listener</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L145 "Source") | ||
@@ -174,7 +175,7 @@ If *listener* is specified, sets the event *listener* for the specified *typenames* and returns this simulation. If an event listener was already registered for the same type and name, the existing listener is removed before the new listener is added. If *listener* is null, removes the current event listeners for the specified *typenames*, if any. If *listener* is not specified, returns the first currently-assigned listener matching the specified *typenames*, if any. When a specified event is dispatched, each *listener* will be invoked with the `this` context as the simulation. | ||
<a name="_force" href="#_force">#</a> <i>force</i>(<i>alpha</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L44 "Source") | ||
<a name="_force" href="#_force">#</a> <i>force</i>(<i>alpha</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L47 "Source") | ||
Applies this force, optionally observing the specified *alpha*. Typically, the force is applied to the array of nodes previously passed to [*force*.initialize](#force_initialize), however, some forces may apply to a subset of nodes, or behave differently. For example, [d3.forceLink](#links) applies to the source and target of each link. | ||
<a name="force_initialize" href="#force_initialize">#</a> <i>force</i>.<b>initialize</b>(<i>nodes</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L71 "Source") | ||
<a name="force_initialize" href="#force_initialize">#</a> <i>force</i>.<b>initialize</b>(<i>nodes</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L77 "Source") | ||
@@ -181,0 +182,0 @@ Assigns the array of *nodes* to this force. This method is called when a force is bound to a simulation via [*simulation*.force](#simulation_force) and when the simulation’s nodes change via [*simulation*.nodes](#simulation_nodes). A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force. |
@@ -1,4 +0,4 @@ | ||
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {quadtree} from "d3-quadtree"; | ||
import constant from "./constant.js"; | ||
import jiggle from "./jiggle.js"; | ||
@@ -5,0 +5,0 @@ function x(d) { |
@@ -1,4 +0,3 @@ | ||
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {map} from "d3-collection"; | ||
import constant from "./constant.js"; | ||
import jiggle from "./jiggle.js"; | ||
@@ -55,3 +54,3 @@ function index(d) { | ||
m = links.length, | ||
nodeById = map(nodes, id), | ||
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])), | ||
link; | ||
@@ -58,0 +57,0 @@ |
@@ -1,5 +0,5 @@ | ||
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {quadtree} from "d3-quadtree"; | ||
import {x, y} from "./simulation"; | ||
import constant from "./constant.js"; | ||
import jiggle from "./jiggle.js"; | ||
import {x, y} from "./simulation.js"; | ||
@@ -6,0 +6,0 @@ export default function() { |
@@ -1,2 +0,2 @@ | ||
import constant from "./constant"; | ||
import constant from "./constant.js"; | ||
@@ -3,0 +3,0 @@ export default function(radius, x, y) { |
import {dispatch} from "d3-dispatch"; | ||
import {map} from "d3-collection"; | ||
import {timer} from "d3-timer"; | ||
@@ -23,3 +22,3 @@ | ||
velocityDecay = 0.6, | ||
forces = map(), | ||
forces = new Map(), | ||
stepper = timer(step), | ||
@@ -39,18 +38,24 @@ event = dispatch("tick", "end"); | ||
function tick() { | ||
function tick(iterations) { | ||
var i, n = nodes.length, node; | ||
alpha += (alphaTarget - alpha) * alphaDecay; | ||
if (iterations === undefined) iterations = 1; | ||
forces.each(function(force) { | ||
force(alpha); | ||
}); | ||
for (var k = 0; k < iterations; ++k) { | ||
alpha += (alphaTarget - alpha) * alphaDecay; | ||
for (i = 0; i < n; ++i) { | ||
node = nodes[i]; | ||
if (node.fx == null) node.x += node.vx *= velocityDecay; | ||
else node.x = node.fx, node.vx = 0; | ||
if (node.fy == null) node.y += node.vy *= velocityDecay; | ||
else node.y = node.fy, node.vy = 0; | ||
forces.forEach(function(force) { | ||
force(alpha); | ||
}); | ||
for (i = 0; i < n; ++i) { | ||
node = nodes[i]; | ||
if (node.fx == null) node.x += node.vx *= velocityDecay; | ||
else node.x = node.fx, node.vx = 0; | ||
if (node.fy == null) node.y += node.vy *= velocityDecay; | ||
else node.y = node.fy, node.vy = 0; | ||
} | ||
} | ||
return simulation; | ||
} | ||
@@ -61,2 +66,4 @@ | ||
node = nodes[i], node.index = i; | ||
if (!isNaN(node.fx)) node.x = node.fx; | ||
if (!isNaN(node.fy)) node.y = node.fy; | ||
if (isNaN(node.x) || isNaN(node.y)) { | ||
@@ -92,3 +99,3 @@ var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle; | ||
nodes: function(_) { | ||
return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes; | ||
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes; | ||
}, | ||
@@ -117,3 +124,3 @@ | ||
force: function(name, _) { | ||
return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name); | ||
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name); | ||
}, | ||
@@ -120,0 +127,0 @@ |
@@ -1,2 +0,2 @@ | ||
import constant from "./constant"; | ||
import constant from "./constant.js"; | ||
@@ -3,0 +3,0 @@ export default function(x) { |
@@ -1,2 +0,2 @@ | ||
import constant from "./constant"; | ||
import constant from "./constant.js"; | ||
@@ -3,0 +3,0 @@ export default function(y) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
459
86988
16
1124
- Removedd3-collection@1
- Removedd3-collection@1.0.7(transitive)