Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-force

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-force - npm Package Compare versions

Comparing version 2.1.0-rc.2 to 2.1.0

src/lcg.js

73

dist/d3-force.js

@@ -1,2 +0,2 @@

// https://d3js.org/d3-force/ v2.1.0-rc.2 Copyright 2020 Mike Bostock
// https://d3js.org/d3-force/ v2.1.0 Copyright 2020 Mike Bostock
(function (global, factory) {

@@ -9,3 +9,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-dispatch'), require('d3-timer')) :

function center(x, y) {
var nodes;
var nodes, strength = 1;

@@ -26,3 +26,3 @@ if (x == null) x = 0;

for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
node = nodes[i], node.x -= sx, node.y -= sy;

@@ -44,2 +44,6 @@ }

force.strength = function(_) {
return arguments.length ? (strength = +_, force) : strength;
};
return force;

@@ -54,10 +58,4 @@ }

// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
const a = 1664525,
c = 1013904223,
m = 4294967296;
let s = 1;
function jiggle(seed) {
if (seed) s = Math.abs(a * seed);
return ((s = (a * s + c) % m) / m - 0.5) * 1e-6;
function jiggle(random) {
return (random() - 0.5) * 1e-6;
}

@@ -76,2 +74,3 @@

radii,
random,
strength = 1,

@@ -110,4 +109,4 @@ iterations = 1;

if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
l = (r - (l = Math.sqrt(l))) / l * strength;

@@ -142,4 +141,5 @@ node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -182,2 +182,3 @@ };

bias,
random,
iterations = 1;

@@ -195,4 +196,4 @@

link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle();
y = target.y + target.vy - source.y - source.vy || jiggle();
x = target.x + target.vx - source.x - source.vx || jiggle(random);
y = target.y + target.vy - source.y - source.vy || jiggle(random);
l = Math.sqrt(x * x + y * y);

@@ -250,4 +251,5 @@ l = (l - distances[i]) / l * alpha * strengths[i];

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -279,2 +281,12 @@ };

// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
const a = 1664525;
const c = 1013904223;
const m = 4294967296; // 2^32
function lcg() {
let s = 1;
return () => (s = (a * s + c) % m) / m;
}
function x$1(d) {

@@ -300,3 +312,4 @@ return d.x;

stepper = d3Timer.timer(step),
event = d3Dispatch.dispatch("tick", "end");
event = d3Dispatch.dispatch("tick", "end"),
random = lcg();

@@ -355,3 +368,3 @@ if (nodes == null) nodes = [];

function initializeForce(force) {
if (force.initialize) force.initialize(nodes);
if (force.initialize) force.initialize(nodes, random);
return force;

@@ -397,2 +410,6 @@ }

randomSource: function(_) {
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
},
force: function(name, _) {

@@ -434,2 +451,3 @@ return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);

node,
random,
alpha,

@@ -492,4 +510,4 @@ strength = constant(-30),

if (l < distanceMax2) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -507,4 +525,4 @@ node.vx += x * quad.value * alpha / l;

if (quad.data !== node || quad.next) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -520,4 +538,5 @@ }

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -524,0 +543,0 @@ };

@@ -1,2 +0,2 @@

// https://d3js.org/d3-force/ v2.1.0-rc.2 Copyright 2020 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=n||self).d3=n.d3||{},n.d3,n.d3,n.d3)}(this,function(n,t,e,r){"use strict";function i(n){return function(){return n}}const u=1664525,o=1013904223,f=4294967296;let a=1;function c(n){return n&&(a=Math.abs(u*n)),1e-6*((a=(u*a+o)%f)/f-.5)}function l(n){return n.x+n.vx}function h(n){return n.y+n.vy}function v(n){return n.index}function y(n,t){var e=n.get(t);if(!e)throw new Error("node not found: "+t);return e}function d(n){return n.x}function x(n){return n.y}var g=10,s=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,u=1,o=1;function f(){for(var n,i,f,v,y,d,x,g=e.length,s=0;s<o;++s)for(i=t.quadtree(e,l,h).visitAfter(a),n=0;n<g;++n)f=e[n],d=r[f.index],x=d*d,v=f.x+f.vx,y=f.y+f.vy,i.visit(p);function p(n,t,e,r,i){var o=n.data,a=n.r,l=d+a;if(!o)return t>v+l||r<v-l||e>y+l||i<y-l;if(o.index>f.index){var h=v-o.x-o.vx,g=y-o.y-o.vy,s=h*h+g*g;s<l*l&&(0===h&&(s+=(h=c())*h),0===g&&(s+=(g=c())*g),s=(l-(s=Math.sqrt(s)))/s*u,f.vx+=(h*=s)*(l=(a*=a)/(x+a)),f.vy+=(g*=s)*l,o.vx-=h*(l=1-l),o.vy-=g*l)}}}function a(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=i(null==n?1:+n)),f.initialize=function(n){e=n,v()},f.iterations=function(n){return arguments.length?(o=+n,f):o},f.strength=function(n){return arguments.length?(u=+n,f):u},f.radius=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),v(),f):n},f},n.forceLink=function(n){var t,e,r,u,o,f=v,a=function(n){return 1/Math.min(u[n.source.index],u[n.target.index])},l=i(30),h=1;function d(r){for(var i=0,u=n.length;i<h;++i)for(var f,a,l,v,y,d,x,g=0;g<u;++g)a=(f=n[g]).source,v=(l=f.target).x+l.vx-a.x-a.vx||c(),y=l.y+l.vy-a.y-a.vy||c(),v*=d=((d=Math.sqrt(v*v+y*y))-e[g])/d*r*t[g],y*=d,l.vx-=v*(x=o[g]),l.vy-=y*x,a.vx+=v*(x=1-x),a.vy+=y*x}function x(){if(r){var i,a,c=r.length,l=n.length,h=new Map(r.map((n,t)=>[f(n,t,r),n]));for(i=0,u=new Array(c);i<l;++i)(a=n[i]).index=i,"object"!=typeof a.source&&(a.source=y(h,a.source)),"object"!=typeof a.target&&(a.target=y(h,a.target)),u[a.source.index]=(u[a.source.index]||0)+1,u[a.target.index]=(u[a.target.index]||0)+1;for(i=0,o=new Array(l);i<l;++i)a=n[i],o[i]=u[a.source.index]/(u[a.source.index]+u[a.target.index]);t=new Array(l),g(),e=new Array(l),s()}}function g(){if(r)for(var e=0,i=n.length;e<i;++e)t[e]=+a(n[e],e,n)}function s(){if(r)for(var t=0,i=n.length;t<i;++t)e[t]=+l(n[t],t,n)}return null==n&&(n=[]),d.initialize=function(n){r=n,x()},d.links=function(t){return arguments.length?(n=t,x(),d):n},d.id=function(n){return arguments.length?(f=n,d):f},d.iterations=function(n){return arguments.length?(h=+n,d):h},d.strength=function(n){return arguments.length?(a="function"==typeof n?n:i(+n),g(),d):a},d.distance=function(n){return arguments.length?(l="function"==typeof n?n:i(+n),s(),d):l},d},n.forceManyBody=function(){var n,e,r,u,o=i(-30),f=1,a=1/0,l=.81;function h(i){var u,o=n.length,f=t.quadtree(n,d,x).visitAfter(y);for(r=i,u=0;u<o;++u)e=n[u],f.visit(g)}function v(){if(n){var t,e,r=n.length;for(u=new Array(r),t=0;t<r;++t)e=n[t],u[e.index]=+o(e,t,n)}}function y(n){var t,e,r,i,o,f=0,a=0;if(n.length){for(r=i=o=0;o<4;++o)(t=n[o])&&(e=Math.abs(t.value))&&(f+=t.value,a+=e,r+=e*t.x,i+=e*t.y);n.x=r/a,n.y=i/a}else{(t=n).x=t.data.x,t.y=t.data.y;do{f+=u[t.data.index]}while(t=t.next)}n.value=f}function g(n,t,i,o){if(!n.value)return!0;var h=n.x-e.x,v=n.y-e.y,y=o-t,d=h*h+v*v;if(y*y/l<d)return d<a&&(0===h&&(d+=(h=c())*h),0===v&&(d+=(v=c())*v),d<f&&(d=Math.sqrt(f*d)),e.vx+=h*n.value*r/d,e.vy+=v*n.value*r/d),!0;if(!(n.length||d>=a)){(n.data!==e||n.next)&&(0===h&&(d+=(h=c())*h),0===v&&(d+=(v=c())*v),d<f&&(d=Math.sqrt(f*d)));do{n.data!==e&&(y=u[n.data.index]*r/d,e.vx+=h*y,e.vy+=v*y)}while(n=n.next)}}return h.initialize=function(t){n=t,v()},h.strength=function(n){return arguments.length?(o="function"==typeof n?n:i(+n),v(),h):o},h.distanceMin=function(n){return arguments.length?(f=n*n,h):Math.sqrt(f)},h.distanceMax=function(n){return arguments.length?(a=n*n,h):Math.sqrt(a)},h.theta=function(n){return arguments.length?(l=n*n,h):Math.sqrt(l)},h},n.forceRadial=function(n,t,e){var r,u,o,f=i(.1);function a(n){for(var i=0,f=r.length;i<f;++i){var a=r[i],c=a.x-t||1e-6,l=a.y-e||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(r){var t,e=r.length;for(u=new Array(e),o=new Array(e),t=0;t<e;++t)o[t]=+n(r[t],t,r),u[t]=isNaN(o[t])?0:+f(r[t],t,r)}}return"function"!=typeof n&&(n=i(+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: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?(e=+n,a):e},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=r.timer(v),h=e.dispatch("tick","end");function v(){y(),h.call("tick",t),i<u&&(l.stop(),h.call("end",t))}function y(e){var r,u,l=n.length;void 0===e&&(e=1);for(var h=0;h<e;++h)for(i+=(f-i)*o,c.forEach(function(n){n(i)}),r=0;r<l;++r)null==(u=n[r]).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 d(){for(var t,e=0,r=n.length;e<r;++e){if((t=n[e]).index=e,null!=t.fx&&(t.x=t.fx),null!=t.fy&&(t.y=t.fy),isNaN(t.x)||isNaN(t.y)){var i=g*Math.sqrt(.5+e),u=e*s;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function x(t){return t.initialize&&t.initialize(n),t}return null==n&&(n=[]),d(),t={tick:y,restart:function(){return l.restart(v),t},stop:function(){return l.stop(),t},nodes:function(e){return arguments.length?(n=e,d(),c.forEach(x),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,e){return arguments.length>1?(null==e?c.delete(n):c.set(n,x(e)),t):c.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?(h.on(n,e),t):h.on(n)}}},n.forceX=function(n){var t,e,r,u=i(.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 i,o=t.length;for(e=new Array(o),r=new Array(o),i=0;i<o;++i)e[i]=isNaN(r[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,e,r,u=i(.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 i,o=t.length;for(e=new Array(o),r=new Array(o),i=0;i<o;++i)e[i]=isNaN(r[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})});
// https://d3js.org/d3-force/ v2.1.0 Copyright 2020 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=n||self).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(n){return 1e-6*(n()-.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("node not found: "+t);return r}const l=1664525,h=1013904223,v=4294967296;function y(n){return n.x}function d(n){return n.y}var x=10,g=Math.PI*(3-Math.sqrt(5));n.forceCenter=function(n,t){var r,e=1;function i(){var i,u,o=r.length,f=0,a=0;for(i=0;i<o;++i)f+=(u=r[i]).x,a+=u.y;for(f=(f/o-n)*e,a=(a/o-t)*e,i=0;i<o;++i)(u=r[i]).x-=f,u.y-=a}return null==n&&(n=0),null==t&&(t=0),i.initialize=function(n){r=n},i.x=function(t){return arguments.length?(n=+t,i):n},i.y=function(n){return arguments.length?(t=+n,i):t},i.strength=function(n){return arguments.length?(e=+n,i):e},i},n.forceCollide=function(n){var r,e,a,c=1,l=1;function h(){for(var n,i,h,y,d,x,g,s=r.length,p=0;p<l;++p)for(i=t.quadtree(r,o,f).visitAfter(v),n=0;n<s;++n)h=r[n],x=e[h.index],g=x*x,y=h.x+h.vx,d=h.y+h.vy,i.visit(M);function M(n,t,r,e,i){var o=n.data,f=n.r,l=x+f;if(!o)return t>y+l||e<y-l||r>d+l||i<d-l;if(o.index>h.index){var v=y-o.x-o.vx,s=d-o.y-o.vy,p=v*v+s*s;p<l*l&&(0===v&&(p+=(v=u(a))*v),0===s&&(p+=(s=u(a))*s),p=(l-(p=Math.sqrt(p)))/p*c,h.vx+=(v*=p)*(l=(f*=f)/(g+f)),h.vy+=(s*=p)*l,o.vx-=v*(l=1-l),o.vy-=s*l)}}}function v(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 y(){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)),h.initialize=function(n,t){r=n,a=t,y()},h.iterations=function(n){return arguments.length?(l=+n,h):l},h.strength=function(n){return arguments.length?(c=+n,h):c},h.radius=function(t){return arguments.length?(n="function"==typeof t?t:i(+t),y(),h):n},h},n.forceLink=function(n){var t,r,e,o,f,l,h=a,v=function(n){return 1/Math.min(o[n.source.index],o[n.target.index])},y=i(30),d=1;function x(e){for(var i=0,o=n.length;i<d;++i)for(var a,c,h,v,y,x,g,s=0;s<o;++s)c=(a=n[s]).source,v=(h=a.target).x+h.vx-c.x-c.vx||u(l),y=h.y+h.vy-c.y-c.vy||u(l),v*=x=((x=Math.sqrt(v*v+y*y))-r[s])/x*e*t[s],y*=x,h.vx-=v*(g=f[s]),h.vy-=y*g,c.vx+=v*(g=1-g),c.vy+=y*g}function g(){if(e){var i,u,a=e.length,l=n.length,v=new Map(e.map((n,t)=>[h(n,t,e),n]));for(i=0,o=new Array(a);i<l;++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(l);i<l;++i)u=n[i],f[i]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);t=new Array(l),s(),r=new Array(l),p()}}function s(){if(e)for(var r=0,i=n.length;r<i;++r)t[r]=+v(n[r],r,n)}function p(){if(e)for(var t=0,i=n.length;t<i;++t)r[t]=+y(n[t],t,n)}return null==n&&(n=[]),x.initialize=function(n,t){e=n,l=t,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:i(+n),s(),x):v},x.distance=function(n){return arguments.length?(y="function"==typeof n?n:i(+n),p(),x):y},x},n.forceManyBody=function(){var n,r,e,o,f,a=i(-30),c=1,l=1/0,h=.81;function v(e){var i,u=n.length,f=t.quadtree(n,y,d).visitAfter(g);for(o=e,i=0;i<u;++i)r=n[i],f.visit(s)}function x(){if(n){var t,r,e=n.length;for(f=new Array(e),t=0;t<e;++t)r=n[t],f[r.index]=+a(r,t,n)}}function g(n){var t,r,e,i,u,o=0,a=0;if(n.length){for(e=i=u=0;u<4;++u)(t=n[u])&&(r=Math.abs(t.value))&&(o+=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{o+=f[t.data.index]}while(t=t.next)}n.value=o}function s(n,t,i,a){if(!n.value)return!0;var v=n.x-r.x,y=n.y-r.y,d=a-t,x=v*v+y*y;if(d*d/h<x)return x<l&&(0===v&&(x+=(v=u(e))*v),0===y&&(x+=(y=u(e))*y),x<c&&(x=Math.sqrt(c*x)),r.vx+=v*n.value*o/x,r.vy+=y*n.value*o/x),!0;if(!(n.length||x>=l)){(n.data!==r||n.next)&&(0===v&&(x+=(v=u(e))*v),0===y&&(x+=(y=u(e))*y),x<c&&(x=Math.sqrt(c*x)));do{n.data!==r&&(d=f[n.data.index]*o/x,r.vx+=v*d,r.vy+=y*d)}while(n=n.next)}}return v.initialize=function(t,r){n=t,e=r,x()},v.strength=function(n){return arguments.length?(a="function"==typeof n?n:i(+n),x(),v):a},v.distanceMin=function(n){return arguments.length?(c=n*n,v):Math.sqrt(c)},v.distanceMax=function(n){return arguments.length?(l=n*n,v):Math.sqrt(l)},v.theta=function(n){return arguments.length?(h=n*n,v):Math.sqrt(h)},v},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,y=e.timer(p),d=r.dispatch("tick","end"),s=function(){let n=1;return()=>(n=(l*n+h)%v)/v}();function p(){M(),d.call("tick",t),i<u&&(y.stop(),d.call("end",t))}function M(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 w(){for(var t,r=0,e=n.length;r<e;++r){if((t=n[r]).index=r,null!=t.fx&&(t.x=t.fx),null!=t.fy&&(t.y=t.fy),isNaN(t.x)||isNaN(t.y)){var i=x*Math.sqrt(.5+r),u=r*g;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function q(t){return t.initialize&&t.initialize(n,s),t}return null==n&&(n=[]),w(),t={tick:M,restart:function(){return y.restart(p),t},stop:function(){return y.stop(),t},nodes:function(r){return arguments.length?(n=r,w(),c.forEach(q),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},randomSource:function(n){return arguments.length?(s=n,c.forEach(q),t):s},force:function(n,r){return arguments.length>1?(null==r?c.delete(n):c.set(n,q(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?(d.on(n,r),t):d.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": "2.1.0-rc.2",
"publishConfig": {
"tag": "next"
},
"version": "2.1.0",
"description": "Force-directed graph layout using velocity Verlet integration.",

@@ -43,5 +40,5 @@ "keywords": [

"dependencies": {
"d3-dispatch": ">=2.0.0-rc.1",
"d3-quadtree": ">=2.0.0-rc.1",
"d3-timer": ">=2.0.0-rc.1"
"d3-dispatch": "1",
"d3-quadtree": "1",
"d3-timer": "1"
},

@@ -48,0 +45,0 @@ "sideEffects": false,

@@ -131,2 +131,6 @@ # d3-force

<a name="simulation_randomSource" href="#simulation_randomSource">#</a> <i>simulation</i>.<b>randomSource</b>([<i>source</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js "Source"))
If *source* is specified, sets the function used to generate random numbers; this should be a function that returns a number between 0 (inclusive) and 1 (exclusive). If *source* is not specified, returns this simulation’s current random source which defaults to a fixed-seed [linear congruential generator](https://en.wikipedia.org/wiki/Linear_congruential_generator). See also [*random*.source](https://github.com/d3/d3-random/blob/master/README.md#random_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")

@@ -175,5 +179,5 @@

<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")
<a name="force_initialize" href="#force_initialize">#</a> <i>force</i>.<b>initialize</b>(<i>nodes</i>, <i>random</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L77 "Source")
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.
Supplies the array of *nodes* and *random* source 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.

@@ -184,14 +188,18 @@ #### Centering

<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>, <i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L1 "Source")
<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>, <i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js "Source")
Creates a new centering force with the specified [*x*-](#center_x) and [*y*-](#center_y) coordinates. If *x* and *y* are not specified, they default to ⟨0,0⟩.
<a name="center_x" href="#center_x">#</a> <i>center</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L27 "Source")
<a name="center_x" href="#center_x">#</a> <i>center</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js "Source")
If *x* is specified, sets the *x*-coordinate of the centering position to the specified number and returns this force. If *x* is not specified, returns the current *x*-coordinate, which defaults to zero.
<a name="center_y" href="#center_y">#</a> <i>center</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L31 "Source")
<a name="center_y" href="#center_y">#</a> <i>center</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js "Source")
If *y* is specified, sets the *y*-coordinate of the centering position to the specified number and returns this force. If *y* is not specified, returns the current *y*-coordinate, which defaults to zero.
<a name="center_strength" href="#center_strength">#</a> <i>center</i>.<b>strength</b>([<i>strength</i>]) · [<>](https://github.com/d3/d3-force/blob/master/src/center.js "Source")
If *strength* is specified, sets the centering force’s strength. A reduced strength of e.g. 0.05 softens the movements on interactive graphs in which new nodes enter or exit the graph. If *strength* is not specified, returns the force’s current strength, which defaults to 1.
#### Collision

@@ -198,0 +206,0 @@

export default function(x, y) {
var nodes;
var nodes, strength = 1;

@@ -18,3 +18,3 @@ if (x == null) x = 0;

for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
node = nodes[i], node.x -= sx, node.y -= sy;

@@ -36,3 +36,7 @@ }

force.strength = function(_) {
return arguments.length ? (strength = +_, force) : strength;
};
return force;
}

@@ -16,2 +16,3 @@ import {quadtree} from "d3-quadtree";

radii,
random,
strength = 1,

@@ -50,4 +51,4 @@ iterations = 1;

if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
l = (r - (l = Math.sqrt(l))) / l * strength;

@@ -82,4 +83,5 @@ node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -86,0 +88,0 @@ };

@@ -1,9 +0,3 @@

// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
const a = 1664525,
c = 1013904223,
m = 4294967296;
let s = 1;
export default function(seed) {
if (seed) s = Math.abs(a * seed);
return ((s = (a * s + c) % m) / m - 0.5) * 1e-6;
export default function(random) {
return (random() - 0.5) * 1e-6;
}

@@ -23,2 +23,3 @@ import constant from "./constant.js";

bias,
random,
iterations = 1;

@@ -36,4 +37,4 @@

link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle();
y = target.y + target.vy - source.y - source.vy || jiggle();
x = target.x + target.vx - source.x - source.vx || jiggle(random);
y = target.y + target.vy - source.y - source.vy || jiggle(random);
l = Math.sqrt(x * x + y * y);

@@ -91,4 +92,5 @@ l = (l - distances[i]) / l * alpha * strengths[i];

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -95,0 +97,0 @@ };

@@ -9,2 +9,3 @@ import {quadtree} from "d3-quadtree";

node,
random,
alpha,

@@ -67,4 +68,4 @@ strength = constant(-30),

if (l < distanceMax2) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -82,4 +83,4 @@ node.vx += x * quad.value * alpha / l;

if (quad.data !== node || quad.next) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -95,4 +96,5 @@ }

force.initialize = function(_) {
nodes = _;
force.initialize = function(_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();

@@ -99,0 +101,0 @@ };

import {dispatch} from "d3-dispatch";
import {timer} from "d3-timer";
import lcg from "./lcg.js";

@@ -24,3 +25,4 @@ export function x(d) {

stepper = timer(step),
event = dispatch("tick", "end");
event = dispatch("tick", "end"),
random = lcg();

@@ -79,3 +81,3 @@ if (nodes == null) nodes = [];

function initializeForce(force) {
if (force.initialize) force.initialize(nodes);
if (force.initialize) force.initialize(nodes, random);
return force;

@@ -121,2 +123,6 @@ }

randomSource: function(_) {
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
},
force: function(name, _) {

@@ -123,0 +129,0 @@ return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc