Comparing version 0.2.1 to 0.2.2
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
var version = "0.2.1"; | ||
var version = "0.2.2"; | ||
@@ -70,3 +70,3 @@ function center(x, y) { | ||
forces = d3Collection.map(), | ||
ticker = d3Timer.timer(tick), | ||
stepper = d3Timer.timer(step), | ||
event = d3Dispatch.dispatch("tick", "end"); | ||
@@ -78,3 +78,3 @@ | ||
iteration = 0; | ||
ticker.restart(tick); | ||
stepper.restart(step); | ||
return simulation; | ||
@@ -84,15 +84,18 @@ } | ||
function stop() { | ||
ticker.stop(); | ||
stepper.stop(); | ||
return simulation; | ||
} | ||
function step() { | ||
var stop = tick(); | ||
event.call("tick", simulation); | ||
if (stop) { | ||
stepper.stop(); | ||
event.call("end", simulation); | ||
} | ||
} | ||
function tick() { | ||
var alpha = Math.exp(++iteration * alphaDecay); | ||
if (!(alpha > alphaMin)) { | ||
ticker.stop(); | ||
event.call("end", simulation); | ||
return; | ||
} | ||
forces.each(function(force) { | ||
@@ -108,3 +111,3 @@ force(alpha); | ||
event.call("tick", simulation); | ||
return alpha < alphaMin; | ||
} | ||
@@ -111,0 +114,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-dispatch"),require("d3-collection"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-dispatch","d3-collection","d3-timer"],t):t(n.d3_force=n.d3_force||{},n.d3_quadtree,n.d3_dispatch,n.d3_collection,n.d3_timer)}(this,function(n,t,e,r,i){"use strict";function o(n,t){function e(){var e,i,o=r.length,u=0,f=0;for(e=0;o>e;++e)i=r[e],u+=i.x,f+=i.y;for(u=u/o-n,f=f/o-t,e=0;o>e;++e)i=r[e],i.x-=u,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}function u(n){return function(){return n}}function f(n){return n.x}function a(n){return n.y}function c(n){function t(){return l=0,g.restart(u),c}function o(){return g.stop(),c}function u(){var t=Math.exp(++l*y);if(!(t>h))return g.stop(),void v.call("end",c);s.each(function(n){n(t)});for(var e,r=0,i=n.length;i>r;++r)e=n[r],e.x+=e.vx*=d,e.y+=e.vy*=d;v.call("tick",c)}function f(){for(var t,e=0,r=n.length;r>e;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=x*Math.sqrt(e),o=e*p;t.x=i*Math.cos(o),t.y=i*Math.sin(o)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function a(t){return t.initialize&&t.initialize(n),t}var c,l=0,h=1e-4,y=-.02,d=.5,s=r.map(),g=i.timer(u),v=e.dispatch("tick","end");return null==n&&(n=[]),f(),c={start:t,stop:o,tick:u,nodes:function(t){return arguments.length?(n=t,f(),s.each(a),c):n},alphaMin:function(n){return arguments.length?(h=n,c):h},alphaDecay:function(n){return arguments.length?(l=+n?Math.round(l*y/-n):0,y=-n,c):-y},drag:function(n){return arguments.length?(d=1-n,c):1-d},force:function(n,t){return arguments.length>1?(null==t?s.remove(n):s.set(n,a(t)),c):s.get(n)},on:function(n,t){return arguments.length>1?(v.on(n,t),c):v.on(n)}}}function l(n){function e(){function n(n,t,r,o,f){if(t>y||l>o||r>d||h>f)return!0;if(!n.length){var a=u.x-n.data.x,c=u.y-n.data.y,v=a*a+c*c,x=i[e]+i[n.data.index];x*x>v&&(v=(x-(v=Math.sqrt(v)))/v,s+=a*v,g+=c*v)}}var e,u,l,h,y,d,s,g,v,x=r.length,p=t.quadtree(r,f,a);for(e=0;x>e;++e)u=r[e],v=i[e]+o,s=g=0,l=u.x-v,h=u.y-v,y=u.x+v,d=u.y+v,p.remove(u).visit(n),u.x+=s*c,u.y+=g*c,p.add(u)}var r,i,o,c=.7;return"function"!=typeof n&&(n=u(null==n?1:+n)),e.initialize=function(t){var e,u,f=(r=t).length;for(i=new Array(f),o=0,e=0;f>e;++e)(i[e]=u=+n(r[e],e,r))>o&&(o=u)},e.strength=function(n){return arguments.length?(c=+n,e):c},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),e):n},e}function h(n,t,e){function r(){for(var n,t,e,r,i,u=0,l=o.length;l>u;++u)n=o[u],t=n.x-a[u],e=n.y-c[u],(r=t*t+e*e)>(i=f[u])*i&&(r=Math.sqrt(r),r=(r-i)/r,n.vx-=t*r,n.vy-=e*r)}function i(){if(o){var r,i=o.length;for(f=new Array(i),a=new Array(i),c=new Array(i),r=0;i>r;++r)f[r]=+n(o[r],r,o),a[r]=+t(o[r],r,o),c[r]=+e(o[r],r,o)}}var o,f,a,c;return"function"!=typeof n&&(n=u(null==n?100:+n)),"function"!=typeof t&&(t=u(null==t?0:+t)),"function"!=typeof e&&(e=u(null==e?0:+e)),r.initialize=function(n){o=n,i()},r.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),i(),r):n},r.x=function(n){return arguments.length?(t="function"==typeof n?n:u(+n),i(),r):t},r.y=function(n){return arguments.length?(e="function"==typeof n?n:u(+n),i(),r):e},r}function y(n,t){return t}function d(n){function t(t){for(var e,r,u,f,c,l,h,y=0,d=n.length;d>y;++y)e=n[y],r=e.source,u=e.target,f=u.x-r.x,c=u.y-r.y,(l=f*f+c*c)?(l=Math.sqrt(l),l=(l-o[y])/l):(l=Math.random()*M,f=Math.cos(l),c=Math.sin(l),l=o[y]),l*=t*i[y],f*=l,c*=l,u.vx-=f*(h=a[y]),u.vy-=c*h,r.vx+=f*(h=1-h),r.vy+=c*h}function e(){if(f&&n){var t,e,u=f.length,y=n.length,d=new Array(u),s=r.map(f,c);for(t=0;u>t;++t)d[t]=0;for(t=0,a=new Array(y);y>t;++t)e=n[t],e.index=t,"object"!=typeof e.source&&(e.source=s.get(e.source)),"object"!=typeof e.target&&(e.target=s.get(e.target)),++d[e.source.index],++d[e.target.index];for(t=0;y>t;++t)e=n[t],a[t]=d[e.source.index]/(d[e.source.index]+d[e.target.index]);if(!i)for(t=0,i=new Array(y);y>t;++t)i[t]=+l(n[t]);if(!o)for(t=0,o=new Array(y);y>t;++t)o[t]=+h(n[t])}}var i,o,f,a,c=y,l=u(.5),h=u(30);return null==n&&(n=[]),t.initialize=function(n){f=n,e()},t.links=function(r){return arguments.length?(n=r,i=o=null,e(),t):n},t.id=function(n){return arguments.length?(c=n,e(),t):c},t.strength=function(n){return arguments.length?(l="function"==typeof n?n:u(+n),i=null,e(),t):l},t.distance=function(n){return arguments.length?(h="function"==typeof n?n:u(+n),o=null,e(),t):h},t}function s(){function n(n){var e,u=o.length,h=t.quadtree(o,f,a).visitAfter(r);for(l=n,e=0;u>e;++e)c=o[e],h.visit(i)}function e(){if(o){var n,t=o.length;for(h=new Array(t),n=0;t>n;++n)h[n]=+y(o[n],n,o)}}function r(n){var t,e,r,i,o,u=0;if(n.length){for(r=i=o=0;4>o;++o)(t=n[o])&&(e=t.value)&&(u+=e,r+=e*t.x,i+=e*t.y);n.x=r/u,n.y=i/u}else{t=n,t.x=t.data.x,t.y=t.data.y;do u+=h[t.data.index];while(t=t.next)}n.value=u}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-c.x,o=n.y-c.y,u=r-t,f=i*i+o*o;if(f>u*u/g)return s>f&&(d>f&&(f=Math.sqrt(f/d),i/=f,o/=f,f=d),f=n.value*l/f,c.vx+=i*f,c.vy+=o*f),!0;if(!(n.length||f>=s)){d>f&&(f||(f=Math.random()*q,i=Math.cos(f),o=Math.sin(f),f=1),f=Math.sqrt(f/d),i/=f,o/=f,f=d);do n.data!==c&&(u=h[n.data.index]*l/f,c.vx+=i*u,c.vy+=o*u);while(n=n.next)}}var o,c,l,h,y=u(-100),d=1,s=1/0,g=.81;return n.initialize=function(n){o=n,e()},n.strength=function(t){return arguments.length?(y="function"==typeof t?t:u(+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?(s=t*t,n):Math.sqrt(s)},n.theta=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n}function g(n,t){function e(n){for(var t,e,r=0,u=i.length;u>r;++r)t=i[r],e=o[r]*n,t.vx+=(f[r]-t.x)*e,t.vy+=(a[r]-t.y)*e}function r(){if(i){var e,r=i.length;for(o=new Array(r),f=new Array(r),a=new Array(r),e=0;r>e;++e)o[e]=+c(i[e],e,i),f[e]=+n(i[e],e,i),a[e]=+t(i[e],e,i)}}var i,o,f,a,c=u(.1);return"function"!=typeof n&&(n=u(null==n?0:+n)),"function"!=typeof t&&(t=u(null==t?0:+t)),e.initialize=function(n){i=n,r()},e.strength=function(n){return arguments.length?(c="function"==typeof n?n:u(+n),r(),e):c},e.x=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),r(),e):n},e.y=function(n){return arguments.length?(t="function"==typeof n?n:u(+n),r(),e):t},e}var v="0.2.1",x=10,p=Math.PI*(3-Math.sqrt(5)),M=2*Math.PI,q=2*Math.PI;n.version=v,n.forceCenter=o,n.forceCollide=l,n.forceContain=h,n.forceLink=d,n.forceManyBody=s,n.forcePosition=g,n.forceSimulation=c}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-dispatch"),require("d3-collection"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-dispatch","d3-collection","d3-timer"],t):t(n.d3_force=n.d3_force||{},n.d3_quadtree,n.d3_dispatch,n.d3_collection,n.d3_timer)}(this,function(n,t,e,r,i){"use strict";function o(n,t){function e(){var e,i,o=r.length,u=0,f=0;for(e=0;o>e;++e)i=r[e],u+=i.x,f+=i.y;for(u=u/o-n,f=f/o-t,e=0;o>e;++e)i=r[e],i.x-=u,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}function u(n){return function(){return n}}function f(n){return n.x}function a(n){return n.y}function c(n){function t(){return h=0,v.restart(u),l}function o(){return v.stop(),l}function u(){var n=f();M.call("tick",l),n&&(v.stop(),M.call("end",l))}function f(){var t=Math.exp(++h*d);g.each(function(n){n(t)});for(var e,r=0,i=n.length;i>r;++r)e=n[r],e.x+=e.vx*=s,e.y+=e.vy*=s;return y>t}function a(){for(var t,e=0,r=n.length;r>e;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=x*Math.sqrt(e),o=e*p;t.x=i*Math.cos(o),t.y=i*Math.sin(o)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function c(t){return t.initialize&&t.initialize(n),t}var l,h=0,y=1e-4,d=-.02,s=.5,g=r.map(),v=i.timer(u),M=e.dispatch("tick","end");return null==n&&(n=[]),a(),l={start:t,stop:o,tick:f,nodes:function(t){return arguments.length?(n=t,a(),g.each(c),l):n},alphaMin:function(n){return arguments.length?(y=n,l):y},alphaDecay:function(n){return arguments.length?(h=+n?Math.round(h*d/-n):0,d=-n,l):-d},drag:function(n){return arguments.length?(s=1-n,l):1-s},force:function(n,t){return arguments.length>1?(null==t?g.remove(n):g.set(n,c(t)),l):g.get(n)},on:function(n,t){return arguments.length>1?(M.on(n,t),l):M.on(n)}}}function l(n){function e(){function n(n,t,r,o,f){if(t>y||l>o||r>d||h>f)return!0;if(!n.length){var a=u.x-n.data.x,c=u.y-n.data.y,v=a*a+c*c,x=i[e]+i[n.data.index];x*x>v&&(v=(x-(v=Math.sqrt(v)))/v,s+=a*v,g+=c*v)}}var e,u,l,h,y,d,s,g,v,x=r.length,p=t.quadtree(r,f,a);for(e=0;x>e;++e)u=r[e],v=i[e]+o,s=g=0,l=u.x-v,h=u.y-v,y=u.x+v,d=u.y+v,p.remove(u).visit(n),u.x+=s*c,u.y+=g*c,p.add(u)}var r,i,o,c=.7;return"function"!=typeof n&&(n=u(null==n?1:+n)),e.initialize=function(t){var e,u,f=(r=t).length;for(i=new Array(f),o=0,e=0;f>e;++e)(i[e]=u=+n(r[e],e,r))>o&&(o=u)},e.strength=function(n){return arguments.length?(c=+n,e):c},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),e):n},e}function h(n,t,e){function r(){for(var n,t,e,r,i,u=0,l=o.length;l>u;++u)n=o[u],t=n.x-a[u],e=n.y-c[u],(r=t*t+e*e)>(i=f[u])*i&&(r=Math.sqrt(r),r=(r-i)/r,n.vx-=t*r,n.vy-=e*r)}function i(){if(o){var r,i=o.length;for(f=new Array(i),a=new Array(i),c=new Array(i),r=0;i>r;++r)f[r]=+n(o[r],r,o),a[r]=+t(o[r],r,o),c[r]=+e(o[r],r,o)}}var o,f,a,c;return"function"!=typeof n&&(n=u(null==n?100:+n)),"function"!=typeof t&&(t=u(null==t?0:+t)),"function"!=typeof e&&(e=u(null==e?0:+e)),r.initialize=function(n){o=n,i()},r.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),i(),r):n},r.x=function(n){return arguments.length?(t="function"==typeof n?n:u(+n),i(),r):t},r.y=function(n){return arguments.length?(e="function"==typeof n?n:u(+n),i(),r):e},r}function y(n,t){return t}function d(n){function t(t){for(var e,r,u,f,c,l,h,y=0,d=n.length;d>y;++y)e=n[y],r=e.source,u=e.target,f=u.x-r.x,c=u.y-r.y,(l=f*f+c*c)?(l=Math.sqrt(l),l=(l-o[y])/l):(l=Math.random()*M,f=Math.cos(l),c=Math.sin(l),l=o[y]),l*=t*i[y],f*=l,c*=l,u.vx-=f*(h=a[y]),u.vy-=c*h,r.vx+=f*(h=1-h),r.vy+=c*h}function e(){if(f&&n){var t,e,u=f.length,y=n.length,d=new Array(u),s=r.map(f,c);for(t=0;u>t;++t)d[t]=0;for(t=0,a=new Array(y);y>t;++t)e=n[t],e.index=t,"object"!=typeof e.source&&(e.source=s.get(e.source)),"object"!=typeof e.target&&(e.target=s.get(e.target)),++d[e.source.index],++d[e.target.index];for(t=0;y>t;++t)e=n[t],a[t]=d[e.source.index]/(d[e.source.index]+d[e.target.index]);if(!i)for(t=0,i=new Array(y);y>t;++t)i[t]=+l(n[t]);if(!o)for(t=0,o=new Array(y);y>t;++t)o[t]=+h(n[t])}}var i,o,f,a,c=y,l=u(.5),h=u(30);return null==n&&(n=[]),t.initialize=function(n){f=n,e()},t.links=function(r){return arguments.length?(n=r,i=o=null,e(),t):n},t.id=function(n){return arguments.length?(c=n,e(),t):c},t.strength=function(n){return arguments.length?(l="function"==typeof n?n:u(+n),i=null,e(),t):l},t.distance=function(n){return arguments.length?(h="function"==typeof n?n:u(+n),o=null,e(),t):h},t}function s(){function n(n){var e,u=o.length,h=t.quadtree(o,f,a).visitAfter(r);for(l=n,e=0;u>e;++e)c=o[e],h.visit(i)}function e(){if(o){var n,t=o.length;for(h=new Array(t),n=0;t>n;++n)h[n]=+y(o[n],n,o)}}function r(n){var t,e,r,i,o,u=0;if(n.length){for(r=i=o=0;4>o;++o)(t=n[o])&&(e=t.value)&&(u+=e,r+=e*t.x,i+=e*t.y);n.x=r/u,n.y=i/u}else{t=n,t.x=t.data.x,t.y=t.data.y;do u+=h[t.data.index];while(t=t.next)}n.value=u}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-c.x,o=n.y-c.y,u=r-t,f=i*i+o*o;if(f>u*u/g)return s>f&&(d>f&&(f=Math.sqrt(f/d),i/=f,o/=f,f=d),f=n.value*l/f,c.vx+=i*f,c.vy+=o*f),!0;if(!(n.length||f>=s)){d>f&&(f||(f=Math.random()*q,i=Math.cos(f),o=Math.sin(f),f=1),f=Math.sqrt(f/d),i/=f,o/=f,f=d);do n.data!==c&&(u=h[n.data.index]*l/f,c.vx+=i*u,c.vy+=o*u);while(n=n.next)}}var o,c,l,h,y=u(-100),d=1,s=1/0,g=.81;return n.initialize=function(n){o=n,e()},n.strength=function(t){return arguments.length?(y="function"==typeof t?t:u(+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?(s=t*t,n):Math.sqrt(s)},n.theta=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n}function g(n,t){function e(n){for(var t,e,r=0,u=i.length;u>r;++r)t=i[r],e=o[r]*n,t.vx+=(f[r]-t.x)*e,t.vy+=(a[r]-t.y)*e}function r(){if(i){var e,r=i.length;for(o=new Array(r),f=new Array(r),a=new Array(r),e=0;r>e;++e)o[e]=+c(i[e],e,i),f[e]=+n(i[e],e,i),a[e]=+t(i[e],e,i)}}var i,o,f,a,c=u(.1);return"function"!=typeof n&&(n=u(null==n?0:+n)),"function"!=typeof t&&(t=u(null==t?0:+t)),e.initialize=function(n){i=n,r()},e.strength=function(n){return arguments.length?(c="function"==typeof n?n:u(+n),r(),e):c},e.x=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),r(),e):n},e.y=function(n){return arguments.length?(t="function"==typeof n?n:u(+n),r(),e):t},e}var v="0.2.2",x=10,p=Math.PI*(3-Math.sqrt(5)),M=2*Math.PI,q=2*Math.PI;n.version=v,n.forceCenter=o,n.forceCollide=l,n.forceContain=h,n.forceLink=d,n.forceManyBody=s,n.forcePosition=g,n.forceSimulation=c}); |
export var name = "d3-force"; | ||
export var version = "0.2.1"; | ||
export var version = "0.2.2"; | ||
export var description = "Force-directed graph layout using velocity Verlet integration."; | ||
@@ -4,0 +4,0 @@ export var keywords = ["d3","layout","network","graphc","force","verlet","infovis"]; |
{ | ||
"name": "d3-force", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Force-directed graph layout using velocity Verlet integration.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -23,3 +23,3 @@ import {dispatch} from "d3-dispatch"; | ||
forces = map(), | ||
ticker = timer(tick), | ||
stepper = timer(step), | ||
event = dispatch("tick", "end"); | ||
@@ -31,3 +31,3 @@ | ||
iteration = 0; | ||
ticker.restart(tick); | ||
stepper.restart(step); | ||
return simulation; | ||
@@ -37,15 +37,18 @@ } | ||
function stop() { | ||
ticker.stop(); | ||
stepper.stop(); | ||
return simulation; | ||
} | ||
function step() { | ||
var stop = tick(); | ||
event.call("tick", simulation); | ||
if (stop) { | ||
stepper.stop(); | ||
event.call("end", simulation); | ||
} | ||
} | ||
function tick() { | ||
var alpha = Math.exp(++iteration * alphaDecay); | ||
if (!(alpha > alphaMin)) { | ||
ticker.stop(); | ||
event.call("end", simulation); | ||
return; | ||
} | ||
forces.each(function(force) { | ||
@@ -61,3 +64,3 @@ force(alpha); | ||
event.call("tick", simulation); | ||
return alpha < alphaMin; | ||
} | ||
@@ -64,0 +67,0 @@ |
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
48803
912