Comparing version 0.4.1 to 0.5.0
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
var version = "0.4.1"; | ||
var version = "0.5.0"; | ||
@@ -53,2 +53,6 @@ function center(x, y) { | ||
function jiggle() { | ||
return (Math.random() - 0.5) * 1e-6; | ||
} | ||
function x(d) { | ||
@@ -99,8 +103,9 @@ return d.x + d.vx; | ||
if (quad.length) return; | ||
var x = nx - quad.data.x - quad.data.vx, | ||
y = ny - quad.data.y - quad.data.vy, | ||
var x = nx - quad.data.x - quad.data.vx || jiggle(), | ||
y = ny - quad.data.y - quad.data.vy || jiggle(), | ||
l = x * x + y * y, | ||
r = radii[i] + radii[quad.data.index]; | ||
if (l < r * r) { | ||
l = (r - (l = Math.sqrt(l))) / l; | ||
l = Math.sqrt(l); | ||
l = (r - l) / l; | ||
vx += x * l, vy += y * l; | ||
@@ -137,4 +142,2 @@ } | ||
var tau = 2 * Math.PI; | ||
function index(d, i) { | ||
@@ -160,7 +163,7 @@ return i; | ||
link = links[i], source = link.source, target = link.target; | ||
x = target.x + target.vx - source.x - source.vx; | ||
y = target.y + target.vy - source.y - source.vy; | ||
if (l = x * x + y * y) l = Math.sqrt(l), l = (l - distances[i]) / l; | ||
else l = Math.random() * tau, x = Math.cos(l), y = Math.sin(l), l = distances[i]; | ||
l *= alpha * strengths[i], x *= l, y *= l; | ||
x = target.x + target.vx - source.x - source.vx || jiggle(); | ||
y = target.y + target.vy - source.y - source.vy || jiggle(); | ||
l = Math.sqrt(x * x + y * y); | ||
l = (l - distances[i]) / l * alpha * strengths[i]; | ||
x *= l, y *= l; | ||
target.vx -= x * (b = bias[i]); | ||
@@ -357,4 +360,2 @@ target.vy -= y * b; | ||
var tau$1 = 2 * Math.PI; | ||
function manyBody() { | ||
@@ -417,9 +418,10 @@ var nodes, | ||
// Apply the Barnes-Hut approximation if possible. | ||
// Limit forces for very close nodes. | ||
// Limit forces for very close nodes; randomize direction if coincident. | ||
if (w * w / theta2 < l) { | ||
if (l < distanceMax2) { | ||
if (l < distanceMin2) l = Math.sqrt(l / distanceMin2), x /= l, y /= l, l = distanceMin2; | ||
l = quad.value * alpha / l; | ||
node.vx += x * l; | ||
node.vy += y * l; | ||
if (x === 0) x = jiggle(), l += x * x; | ||
if (y === 0) y = jiggle(), l += y * y; | ||
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
node.vx += x * quad.value * alpha / l; | ||
node.vy += y * quad.value * alpha / l; | ||
} | ||
@@ -432,7 +434,7 @@ return true; | ||
// Limit forces for very close nodes. | ||
// Randomize direction for exactly-coincident nodes. | ||
if (l < distanceMin2) { | ||
if (!l) l = Math.random() * tau$1, x = Math.cos(l), y = Math.sin(l), l = 1; | ||
l = Math.sqrt(l / distanceMin2), x /= l, y /= l, l = distanceMin2; | ||
// Limit forces for very close nodes; randomize direction if coincident. | ||
if (quad.data !== node || quad.next) { | ||
if (x === 0) x = jiggle(), l += x * x; | ||
if (y === 0) y = jiggle(), l += y * y; | ||
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
} | ||
@@ -471,18 +473,13 @@ | ||
function position(x, y) { | ||
function x$2(x) { | ||
var strength = constant(0.1), | ||
nodes, | ||
strengths, | ||
xz, | ||
yz; | ||
xz; | ||
if (typeof x !== "function") x = constant(x == null ? 0 : +x); | ||
if (typeof y !== "function") y = constant(y == null ? 0 : +y); | ||
function force(alpha) { | ||
for (var i = 0, n = nodes.length, node, k; i < n; ++i) { | ||
node = nodes[i]; | ||
k = strengths[i] * alpha; | ||
node.vx += (xz[i] - node.x) * k; | ||
node.vy += (yz[i] - node.y) * k; | ||
for (var i = 0, n = nodes.length, node; i < n; ++i) { | ||
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha; | ||
} | ||
@@ -496,7 +493,5 @@ } | ||
xz = new Array(n); | ||
yz = new Array(n); | ||
for (i = 0; i < n; ++i) { | ||
strengths[i] = +strength(nodes[i], i, nodes); | ||
xz[i] = +x(nodes[i], i, nodes); | ||
yz[i] = +y(nodes[i], i, nodes); | ||
} | ||
@@ -518,2 +513,39 @@ } | ||
return force; | ||
} | ||
function y$2(y) { | ||
var strength = constant(0.1), | ||
nodes, | ||
strengths, | ||
yz; | ||
if (typeof y !== "function") y = constant(y == null ? 0 : +y); | ||
function force(alpha) { | ||
for (var i = 0, n = nodes.length, node; i < n; ++i) { | ||
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha; | ||
} | ||
} | ||
function initialize() { | ||
if (!nodes) return; | ||
var i, n = nodes.length; | ||
strengths = new Array(n); | ||
yz = new Array(n); | ||
for (i = 0; i < n; ++i) { | ||
strengths[i] = +strength(nodes[i], i, nodes); | ||
yz[i] = +y(nodes[i], i, nodes); | ||
} | ||
} | ||
force.initialize = function(_) { | ||
nodes = _; | ||
initialize(); | ||
}; | ||
force.strength = function(_) { | ||
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength; | ||
}; | ||
force.y = function(_) { | ||
@@ -531,5 +563,6 @@ return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), initialize(), force) : y; | ||
exports.forceManyBody = manyBody; | ||
exports.forcePosition = position; | ||
exports.forceSimulation = simulation; | ||
exports.forceX = x$2; | ||
exports.forceY = y$2; | ||
})); |
@@ -1,1 +0,1 @@ | ||
!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_force=n.d3_force||{},n.d3_quadtree,n.d3_collection,n.d3_dispatch,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,a=0;for(e=0;o>e;++e)i=r[e],u+=i.x,a+=i.y;for(u=u/o-n,a=a/o-t,e=0;o>e;++e)i=r[e],i.x-=u,i.y-=a}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 a(n){return n.x+n.vx}function f(n){return n.y+n.vy}function c(n){function e(){function n(n,t,r,o,u){if(t>p||g>o||r>M||x>u)return!0;if(!n.length){var a=h-n.data.x-n.data.vx,f=d-n.data.y-n.data.vy,c=a*a+f*f,l=i[e]+i[n.data.index];l*l>c&&(c=(l-(c=Math.sqrt(c)))/c,y+=a*c,s+=f*c)}}for(var e,u,h,d,v,y,s,g,x,p,M,q=r.length,m=t.quadtree(r,a,f),w=0;l>w;++w)for(e=0;q>e;++e)u=r[e],v=i[e]+o,y=s=0,h=u.x+u.vx,g=h-v,p=h+v,d=u.y+u.vy,x=d-v,M=d+v,m.remove(u).visit(n),u.vx+=y*c,u.vy+=s*c,m.add(u)}var r,i,o,c=.7,l=1;return"function"!=typeof n&&(n=u(null==n?1:+n)),e.initialize=function(t){var e,u,a=(r=t).length;for(i=new Array(a),o=0,e=0;a>e;++e)(i[e]=u=+n(r[e],e,r))>o&&(o=u)},e.iterations=function(n){return arguments.length?(l=+n,e):l},e.strength=function(n){return arguments.length?(c=+n,e):c},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),e):n},e}function l(n,t){return t}function h(n){function t(t){for(var e=0,r=n.length;s>e;++e)for(var i,o,u,c,l,d,v,y=0;r>y;++y)i=n[y],o=i.source,u=i.target,c=u.x+u.vx-o.x-o.vx,l=u.y+u.vy-o.y-o.vy,(d=c*c+l*l)?(d=Math.sqrt(d),d=(d-f[y])/d):(d=Math.random()*p,c=Math.cos(d),l=Math.sin(d),d=f[y]),d*=t*a[y],c*=d,l*=d,u.vx-=c*(v=h[y]),u.vy-=l*v,o.vx+=c*(v=1-v),o.vy+=l*v}function r(){if(c){var t,r,u=c.length,l=n.length,v=new Array(u),y=e.map(c,d);for(t=0;u>t;++t)v[t]=0;for(t=0,h=new Array(l);l>t;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=y.get(r.source)),"object"!=typeof r.target&&(r.target=y.get(r.target)),++v[r.source.index],++v[r.target.index];for(t=0;l>t;++t)r=n[t],h[t]=v[r.source.index]/(v[r.source.index]+v[r.target.index]);a=new Array(l),i(),f=new Array(l),o()}}function i(){if(c)for(var t=0,e=n.length;e>t;++t)a[t]=+v(n[t])}function o(){if(c)for(var t=0,e=n.length;e>t;++t)f[t]=+y(n[t])}var a,f,c,h,d=l,v=u(.7),y=u(30),s=1;return null==n&&(n=[]),t.initialize=function(n){c=n,r()},t.links=function(e){return arguments.length?(n=e,r(),t):n},t.id=function(n){return arguments.length?(d=n,t):d},t.iterations=function(n){return arguments.length?(s=+n,t):s},t.strength=function(n){return arguments.length?(v="function"==typeof n?n:u(+n),i(),t):v},t.distance=function(n){return arguments.length?(y="function"==typeof n?n:u(+n),o(),t):y},t}function d(n){return n.x}function v(n){return n.y}function y(n){function t(){return h=0,g.restart(u),l}function o(){return g.stop(),l}function u(){var n=a();x.call("tick",l),n&&(g.stop(),x.call("end",l))}function a(){var t=Math.exp(++h*v);s.each(function(n){n(t)});for(var e,r=0,i=n.length;i>r;++r)e=n[r],e.x+=e.vx*=y,e.y+=e.vy*=y;return d>t}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=M*Math.sqrt(e),o=e*q;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,d=.001,v=-.02,y=.6,s=e.map(),g=i.timer(u),x=r.dispatch("tick","end");return null==n&&(n=[]),f(),l={restart:t,stop:o,tick:a,nodes:function(t){return arguments.length?(n=t,f(),s.each(c),l):n},alphaMin:function(n){return arguments.length?(d=n,l):d},alphaDecay:function(n){return arguments.length?(h=+n?Math.round(h*v/-n):0,v=-n,l):-v},drag:function(n){return arguments.length?(y=1-n,l):1-y},force:function(n,t){return arguments.length>1?(null==t?s.remove(n):s.set(n,c(t)),l):s.get(n)},on:function(n,t){return arguments.length>1?(x.on(n,t),l):x.on(n)}}}function s(){function n(n){var e,u=o.length,c=t.quadtree(o,d,v).visitAfter(r);for(f=n,e=0;u>e;++e)a=o[e],c.visit(i)}function e(){if(o){var n,t=o.length;for(c=new Array(t),n=0;t>n;++n)c[n]=+l(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+=c[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-a.x,o=n.y-a.y,u=r-t,l=i*i+o*o;if(l>u*u/s)return y>l&&(h>l&&(l=Math.sqrt(l/h),i/=l,o/=l,l=h),l=n.value*f/l,a.vx+=i*l,a.vy+=o*l),!0;if(!(n.length||l>=y)){h>l&&(l||(l=Math.random()*m,i=Math.cos(l),o=Math.sin(l),l=1),l=Math.sqrt(l/h),i/=l,o/=l,l=h);do n.data!==a&&(u=c[n.data.index]*f/l,a.vx+=i*u,a.vy+=o*u);while(n=n.next)}}var o,a,f,c,l=u(-100),h=1,y=1/0,s=.81;return n.initialize=function(n){o=n,e()},n.strength=function(t){return arguments.length?(l="function"==typeof t?t:u(+t),e(),n):l},n.distanceMin=function(t){return arguments.length?(h=t*t,n):Math.sqrt(h)},n.distanceMax=function(t){return arguments.length?(y=t*t,n):Math.sqrt(y)},n.theta=function(t){return arguments.length?(s=t*t,n):Math.sqrt(s)},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+=(a[r]-t.x)*e,t.vy+=(f[r]-t.y)*e}function r(){if(i){var e,r=i.length;for(o=new Array(r),a=new Array(r),f=new Array(r),e=0;r>e;++e)o[e]=+c(i[e],e,i),a[e]=+n(i[e],e,i),f[e]=+t(i[e],e,i)}}var i,o,a,f,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 x="0.4.1",p=2*Math.PI,M=10,q=Math.PI*(3-Math.sqrt(5)),m=2*Math.PI;n.version=x,n.forceCenter=o,n.forceCollide=c,n.forceLink=h,n.forceManyBody=s,n.forcePosition=g,n.forceSimulation=y}); | ||
!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_force=n.d3_force||{},n.d3_quadtree,n.d3_collection,n.d3_dispatch,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(){return 1e-6*(Math.random()-.5)}function a(n){return n.x+n.vx}function c(n){return n.y+n.vy}function l(n){function e(){function n(n,t,r,o,u){if(t>M||x>o||r>q||p>u)return!0;if(!n.length){var a=v-n.data.x-n.data.vx||f(),c=d-n.data.y-n.data.vy||f(),l=a*a+c*c,h=i[e]+i[n.data.index];h*h>l&&(l=Math.sqrt(l),l=(h-l)/l,g+=a*l,s+=c*l)}}for(var e,u,v,d,y,g,s,x,p,M,q,m=r.length,w=t.quadtree(r,a,c),A=0;h>A;++A)for(e=0;m>e;++e)u=r[e],y=i[e]+o,g=s=0,v=u.x+u.vx,x=v-y,M=v+y,d=u.y+u.vy,p=d-y,q=d+y,w.remove(u).visit(n),u.vx+=g*l,u.vy+=s*l,w.add(u)}var r,i,o,l=.7,h=1;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.iterations=function(n){return arguments.length?(h=+n,e):h},e.strength=function(n){return arguments.length?(l=+n,e):l},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:u(+t),e):n},e}function h(n,t){return t}function v(n){function t(t){for(var e=0,r=n.length;s>e;++e)for(var i,o,u,l,h,d,y,g=0;r>g;++g)i=n[g],o=i.source,u=i.target,l=u.x+u.vx-o.x-o.vx||f(),h=u.y+u.vy-o.y-o.vy||f(),d=Math.sqrt(l*l+h*h),d=(d-c[g])/d*t*a[g],l*=d,h*=d,u.vx-=l*(y=v[g]),u.vy-=h*y,o.vx+=l*(y=1-y),o.vy+=h*y}function r(){if(l){var t,r,u=l.length,f=n.length,h=new Array(u),y=e.map(l,d);for(t=0;u>t;++t)h[t]=0;for(t=0,v=new Array(f);f>t;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=y.get(r.source)),"object"!=typeof r.target&&(r.target=y.get(r.target)),++h[r.source.index],++h[r.target.index];for(t=0;f>t;++t)r=n[t],v[t]=h[r.source.index]/(h[r.source.index]+h[r.target.index]);a=new Array(f),i(),c=new Array(f),o()}}function i(){if(l)for(var t=0,e=n.length;e>t;++t)a[t]=+y(n[t])}function o(){if(l)for(var t=0,e=n.length;e>t;++t)c[t]=+g(n[t])}var a,c,l,v,d=h,y=u(.7),g=u(30),s=1;return null==n&&(n=[]),t.initialize=function(n){l=n,r()},t.links=function(e){return arguments.length?(n=e,r(),t):n},t.id=function(n){return arguments.length?(d=n,t):d},t.iterations=function(n){return arguments.length?(s=+n,t):s},t.strength=function(n){return arguments.length?(y="function"==typeof n?n:u(+n),i(),t):y},t.distance=function(n){return arguments.length?(g="function"==typeof n?n:u(+n),o(),t):g},t}function d(n){return n.x}function y(n){return n.y}function g(n){function t(){return h=0,s.restart(u),l}function o(){return s.stop(),l}function u(){var n=f();x.call("tick",l),n&&(s.stop(),x.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*=y,e.y+=e.vy*=y;return v>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=q*Math.sqrt(e),o=e*m;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,v=.001,d=-.02,y=.6,g=e.map(),s=i.timer(u),x=r.dispatch("tick","end");return null==n&&(n=[]),a(),l={restart: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?(v=n,l):v},alphaDecay:function(n){return arguments.length?(h=+n?Math.round(h*d/-n):0,d=-n,l):-d},drag:function(n){return arguments.length?(y=1-n,l):1-y},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?(x.on(n,t),l):x.on(n)}}}function s(){function n(n){var e,u=o.length,f=t.quadtree(o,d,y).visitAfter(r);for(c=n,e=0;u>e;++e)a=o[e],f.visit(i)}function e(){if(o){var n,t=o.length;for(l=new Array(t),n=0;t>n;++n)l[n]=+h(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+=l[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-a.x,o=n.y-a.y,u=r-t,h=i*i+o*o;if(h>u*u/s)return g>h&&(0===i&&(i=f(),h+=i*i),0===o&&(o=f(),h+=o*o),v>h&&(h=Math.sqrt(v*h)),a.vx+=i*n.value*c/h,a.vy+=o*n.value*c/h),!0;if(!(n.length||h>=g)){(n.data!==a||n.next)&&(0===i&&(i=f(),h+=i*i),0===o&&(o=f(),h+=o*o),v>h&&(h=Math.sqrt(v*h)));do n.data!==a&&(u=l[n.data.index]*c/h,a.vx+=i*u,a.vy+=o*u);while(n=n.next)}}var o,a,c,l,h=u(-100),v=1,g=1/0,s=.81;return n.initialize=function(n){o=n,e()},n.strength=function(t){return arguments.length?(h="function"==typeof t?t:u(+t),e(),n):h},n.distanceMin=function(t){return arguments.length?(v=t*t,n):Math.sqrt(v)},n.distanceMax=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n.theta=function(t){return arguments.length?(s=t*t,n):Math.sqrt(s)},n}function x(n){function t(n){for(var t,e=0,u=r.length;u>e;++e)t=r[e],t.vx+=(o[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),o=new Array(e),t=0;e>t;++t)i[t]=+f(r[t],t,r),o[t]=+n(r[t],t,r)}}var r,i,o,f=u(.1);return"function"!=typeof n&&(n=u(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:u(+n),e(),t):f},t.x=function(r){return arguments.length?(n="function"==typeof r?r:u(+r),e(),t):n},t}function p(n){function t(n){for(var t,e=0,u=r.length;u>e;++e)t=r[e],t.vy+=(o[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),o=new Array(e),t=0;e>t;++t)i[t]=+f(r[t],t,r),o[t]=+n(r[t],t,r)}}var r,i,o,f=u(.1);return"function"!=typeof n&&(n=u(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:u(+n),e(),t):f},t.y=function(r){return arguments.length?(n="function"==typeof r?r:u(+r),e(),t):n},t}var M="0.5.0",q=10,m=Math.PI*(3-Math.sqrt(5));n.version=M,n.forceCenter=o,n.forceCollide=l,n.forceLink=v,n.forceManyBody=s,n.forceSimulation=g,n.forceX=x,n.forceY=p}); |
export var name = "d3-force"; | ||
export var version = "0.4.1"; | ||
export var version = "0.5.0"; | ||
export var description = "Force-directed graph layout using velocity Verlet integration."; | ||
@@ -10,4 +10,4 @@ export var keywords = ["d3","layout","network","graphc","force","verlet","infovis"]; | ||
export var repository = {"type":"git","url":"https://github.com/d3/d3-force.git"}; | ||
export var scripts = {"pretest":"rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -g d3-collection:d3_collection,d3-dispatch:d3_dispatch,d3-quadtree:d3_quadtree,d3-timer:d3_timer -f umd -n d3_force -o build/d3-force.js -- index.js","test":"tape 'test/**/*-test.js' && eslint index.js src","prepublish":"npm run test && uglifyjs build/d3-force.js -c -m -o build/d3-force.min.js","postpublish":"VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v0.4.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v0.4.min.js && cd ../d3.github.com && git add d3-force.v0.4.js d3-force.v0.4.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js"}; | ||
export var scripts = {"pretest":"rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -g d3-collection:d3_collection,d3-dispatch:d3_dispatch,d3-quadtree:d3_quadtree,d3-timer:d3_timer -f umd -n d3_force -o build/d3-force.js -- index.js","test":"tape 'test/**/*-test.js' && eslint index.js src","prepublish":"npm run test && uglifyjs build/d3-force.js -c -m -o build/d3-force.min.js","postpublish":"VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v0.5.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v0.5.min.js && cd ../d3.github.com && git add d3-force.v0.5.js d3-force.v0.5.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js"}; | ||
export var dependencies = {"d3-collection":"0.1","d3-dispatch":"0.4","d3-quadtree":"0.7","d3-timer":"0.4"}; | ||
export var devDependencies = {"json2module":"0.0","rollup":"0.26","tape":"4","uglify-js":"2"}; |
@@ -6,3 +6,4 @@ export {version} from "./build/package"; | ||
export {default as forceManyBody} from "./src/manyBody"; | ||
export {default as forcePosition} from "./src/position"; | ||
export {default as forceSimulation} from "./src/simulation"; | ||
export {default as forceX} from "./src/x"; | ||
export {default as forceY} from "./src/y"; |
{ | ||
"name": "d3-force", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Force-directed graph layout using velocity Verlet integration.", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"prepublish": "npm run test && uglifyjs build/d3-force.js -c -m -o build/d3-force.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v0.4.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v0.4.min.js && cd ../d3.github.com && git add d3-force.v0.4.js d3-force.v0.4.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js" | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v0.5.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v0.5.min.js && cd ../d3.github.com && git add d3-force.v0.5.js d3-force.v0.5.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": { |
@@ -19,3 +19,3 @@ # 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.v0.4.min.js) or as part of [D3 4.0 alpha](https://github.com/mbostock/d3/tree/4). 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.v0.5.min.js) or as part of [D3 4.0 alpha](https://github.com/mbostock/d3/tree/4). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported: | ||
@@ -27,3 +27,3 @@ ```html | ||
<script src="https://d3js.org/d3-timer.v0.4.min.js"></script> | ||
<script src="https://d3js.org/d3-force.v0.4.min.js"></script> | ||
<script src="https://d3js.org/d3-force.v0.5.min.js"></script> | ||
<script> | ||
@@ -336,11 +336,11 @@ | ||
The positioning force pushes nodes towards a desired position ⟨[*x*](#position_x),[*y*](#position_y)⟩ with a configurable [strength](#position_strength). The strength of the force is proportional to the distance between the node’s position and the target position, similar to a spring force. | ||
The positioning forces pushes nodes towards a desired [*x*](#forceX)- or [*y*](#forceY)-position with a configurable strength. The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position. | ||
<a name="forcePosition" href="#forcePosition">#</a> d3.<b>forcePosition</b>([<i>x</i>, <i>y</i>]) | ||
<a name="forceX" href="#forceX">#</a> d3.<b>forceX</b>([<i>x</i>]) | ||
Creates a new positioning force towards the given position ⟨[*x*](#position_x),[*y*](#position_y)⟩. If *x* and *y* are not specified, the position defaults to ⟨0,0⟩. | ||
Creates a new positioning force along the *x*-axis towards the given position [*x*](#x_x). If *x* is not specified, it defaults to 0. | ||
<a name="position_strength" href="#position_strength">#</a> <i>position</i>.<b>strength</b>([<i>strength</i>]) | ||
<a name="x_strength" href="#x_strength">#</a> <i>x</i>.<b>strength</b>([<i>strength</i>]) | ||
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The *strength* corresponds to the proportion of the vector from the node’s position to the force’s target position that should be added to the node’s velocity: *velocity* += (*target* - *position*) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current position to the target position with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended. | ||
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The *strength* determines how to modify the node’s *x*-velocity according to the following formula: *node*.vx += ([*x*](#x_x) - *node*.x) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current *x*-position to the target *x*-position with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended. | ||
@@ -357,3 +357,3 @@ If *strength* is not specified, returns the current strength accessor, which defaults to: | ||
<a name="position_x" href="#position_x">#</a> <i>position</i>.<b>x</b>([<i>x</i>]) | ||
<a name="x_x" href="#x_x">#</a> <i>x</i>.<b>x</b>([<i>x</i>]) | ||
@@ -370,4 +370,22 @@ If *x* is specified, sets the *x*-coordinate accessor to the specified number or function, re-evaluates the *x*-accessor for each node, and returns this force. If *x* is not specified, returns the current *x*-accessor, which defaults to: | ||
<a name="position_y" href="#position_y">#</a> <i>position</i>.<b>y</b>([<i>y</i>]) | ||
<a name="forceY" href="#forceY">#</a> d3.<b>forceY</b>([<i>y</i>]) | ||
Creates a new positioning force along the *y*-axis towards the given position [*y*](#y_y). If *y* is not specified, it defaults to 0. | ||
<a name="y_strength" href="#y_strength">#</a> <i>y</i>.<b>strength</b>([<i>strength</i>]) | ||
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The *strength* determines how to modify the node’s *y*-velocity according to the following formula: *node*.vy += ([*y*](#y_y) - *node*.y) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current *y*-position to the target *y*-position with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended. | ||
If *strength* is not specified, returns the current strength accessor, which defaults to: | ||
```js | ||
function strength() { | ||
return 0.1; | ||
} | ||
``` | ||
The strength accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the strength of each node is only recomputed when the force is initialized or when this method is called, and not on every application of the force. | ||
<a name="y_y" href="#y_y">#</a> <i>y</i>.<b>y</b>([<i>y</i>]) | ||
If *y* is specified, sets the *y*-coordinate accessor to the specified number or function, re-evaluates the *y*-accessor for each node, and returns this force. If *y* is not specified, returns the current *y*-accessor, which defaults to: | ||
@@ -374,0 +392,0 @@ |
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {quadtree} from "d3-quadtree"; | ||
@@ -49,8 +50,9 @@ | ||
if (quad.length) return; | ||
var x = nx - quad.data.x - quad.data.vx, | ||
y = ny - quad.data.y - quad.data.vy, | ||
var x = nx - quad.data.x - quad.data.vx || jiggle(), | ||
y = ny - quad.data.y - quad.data.vy || jiggle(), | ||
l = x * x + y * y, | ||
r = radii[i] + radii[quad.data.index]; | ||
if (l < r * r) { | ||
l = (r - (l = Math.sqrt(l))) / l; | ||
l = Math.sqrt(l); | ||
l = (r - l) / l; | ||
vx += x * l, vy += y * l; | ||
@@ -57,0 +59,0 @@ } |
@@ -0,6 +1,5 @@ | ||
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {map} from "d3-collection"; | ||
import constant from "./constant"; | ||
var tau = 2 * Math.PI; | ||
function index(d, i) { | ||
@@ -26,7 +25,7 @@ return i; | ||
link = links[i], source = link.source, target = link.target; | ||
x = target.x + target.vx - source.x - source.vx; | ||
y = target.y + target.vy - source.y - source.vy; | ||
if (l = x * x + y * y) l = Math.sqrt(l), l = (l - distances[i]) / l; | ||
else l = Math.random() * tau, x = Math.cos(l), y = Math.sin(l), l = distances[i]; | ||
l *= alpha * strengths[i], x *= l, y *= l; | ||
x = target.x + target.vx - source.x - source.vx || jiggle(); | ||
y = target.y + target.vy - source.y - source.vy || jiggle(); | ||
l = Math.sqrt(x * x + y * y); | ||
l = (l - distances[i]) / l * alpha * strengths[i]; | ||
x *= l, y *= l; | ||
target.vx -= x * (b = bias[i]); | ||
@@ -33,0 +32,0 @@ target.vy -= y * b; |
import constant from "./constant"; | ||
import jiggle from "./jiggle"; | ||
import {quadtree} from "d3-quadtree"; | ||
import {x, y} from "./simulation"; | ||
var tau = 2 * Math.PI; | ||
export default function() { | ||
@@ -64,9 +63,10 @@ var nodes, | ||
// Apply the Barnes-Hut approximation if possible. | ||
// Limit forces for very close nodes. | ||
// Limit forces for very close nodes; randomize direction if coincident. | ||
if (w * w / theta2 < l) { | ||
if (l < distanceMax2) { | ||
if (l < distanceMin2) l = Math.sqrt(l / distanceMin2), x /= l, y /= l, l = distanceMin2; | ||
l = quad.value * alpha / l; | ||
node.vx += x * l; | ||
node.vy += y * l; | ||
if (x === 0) x = jiggle(), l += x * x; | ||
if (y === 0) y = jiggle(), l += y * y; | ||
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
node.vx += x * quad.value * alpha / l; | ||
node.vy += y * quad.value * alpha / l; | ||
} | ||
@@ -79,7 +79,7 @@ return true; | ||
// Limit forces for very close nodes. | ||
// Randomize direction for exactly-coincident nodes. | ||
if (l < distanceMin2) { | ||
if (!l) l = Math.random() * tau, x = Math.cos(l), y = Math.sin(l), l = 1; | ||
l = Math.sqrt(l / distanceMin2), x /= l, y /= l, l = distanceMin2; | ||
// Limit forces for very close nodes; randomize direction if coincident. | ||
if (quad.data !== node || quad.next) { | ||
if (x === 0) x = jiggle(), l += x * x; | ||
if (y === 0) y = jiggle(), l += y * y; | ||
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
} | ||
@@ -86,0 +86,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
341582
22
928
395