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

d3-force-3d

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-force-3d - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

src/lcg.js

85

dist/d3-force-3d.js

@@ -1,10 +0,10 @@

// https://github.com/vasturiano/d3-force-3d v2.1.0 Copyright 2020 Vasco Asturiano
// https://github.com/vasturiano/d3-force-3d v2.2.0 Copyright 2020 Vasco Asturiano
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-binarytree'), require('d3-quadtree'), require('d3-octree'), require('d3-dispatch'), require('d3-timer')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-binarytree', 'd3-quadtree', 'd3-octree', 'd3-dispatch', 'd3-timer'], factory) :
(global = global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3, global.d3, global.d3));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3, global.d3, global.d3));
}(this, (function (exports, d3Binarytree, d3Quadtree, d3Octree, d3Dispatch, d3Timer) { 'use strict';
function center(x, y, z) {
var nodes;
var nodes, strength = 1;

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

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

@@ -52,2 +52,6 @@ if (sx) { node.x -= sx; }

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

@@ -62,4 +66,4 @@ }

function jiggle() {
return (Math.random() - 0.5) * 1e-6;
function jiggle(random) {
return (random() - 0.5) * 1e-6;
}

@@ -83,2 +87,3 @@

radii,
random,
strength = 1,

@@ -134,5 +139,5 @@ iterations = 1;

if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
l = (r - (l = Math.sqrt(l))) / l * strength;

@@ -173,5 +178,6 @@

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -215,2 +221,3 @@ };

bias,
random,
iterations = 1;

@@ -228,5 +235,5 @@

link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle();
if (nDim > 1) { y = target.y + target.vy - source.y - source.vy || jiggle(); }
if (nDim > 2) { z = target.z + target.vz - source.z - source.vz || jiggle(); }
x = target.x + target.vx - source.x - source.vx || jiggle(random);
if (nDim > 1) { y = target.y + target.vy - source.y - source.vy || jiggle(random); }
if (nDim > 2) { z = target.z + target.vz - source.z - source.vz || jiggle(random); }
l = Math.sqrt(x * x + y * y + z * z);

@@ -288,5 +295,6 @@ l = (l - distances[i]) / l * alpha * strengths[i];

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -318,2 +326,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;
}
var MAX_DIMENSIONS = 3;

@@ -349,3 +367,4 @@

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

@@ -400,3 +419,3 @@ if (nodes == null) nodes = [];

if (isNaN(node.x) || (nDim > 1 && isNaN(node.y)) || (nDim > 2 && isNaN(node.z))) {
var radius = initialRadius * (nDim > 2 ? Math.cbrt(i) : (nDim > 1 ? Math.sqrt(i) : i)),
var radius = initialRadius * (nDim > 2 ? Math.cbrt(0.5 + i) : (nDim > 1 ? Math.sqrt(0.5 + i) : i)),
rollAngle = i * initialAngleRoll,

@@ -425,3 +444,3 @@ yawAngle = i * initialAngleYaw;

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

@@ -473,2 +492,6 @@ }

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

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

node,
random,
alpha,

@@ -591,5 +615,5 @@ strength = constant(-30),

if (l < distanceMax2) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -608,5 +632,5 @@ node.vx += x * treeNode.value * alpha / l;

if (treeNode.data !== node || treeNode.next) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -623,5 +647,6 @@ }

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -628,0 +653,0 @@ };

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

// https://github.com/vasturiano/d3-force-3d v2.1.0 Copyright 2020 Vasco Asturiano
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-binarytree"),require("d3-quadtree"),require("d3-octree"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-binarytree","d3-quadtree","d3-octree","d3-dispatch","d3-timer"],t):t((n=n||self).d3=n.d3||{},n.d3,n.d3,n.d3,n.d3,n.d3)}(this,(function(n,t,r,e,i,u){"use strict";function o(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){return n.z+n.vz}function h(n){return n.index}function v(n,t){var r=n.get(t);if(!r)throw new Error("node not found: "+t);return r}function y(n){return n.x}function d(n){return n.y}function s(n){return n.z}var x=Math.PI*(3-Math.sqrt(5)),g=20*Math.PI/(9+Math.sqrt(221));n.forceCenter=function(n,t,r){var e;function i(){var i,u,o=e.length,f=0,a=0,c=0;for(i=0;i<o;++i)f+=(u=e[i]).x||0,a+=u.y||0,c+=u.z||0;for(f=f/o-n,a=a/o-t,c=c/o-r,i=0;i<o;++i)u=e[i],f&&(u.x-=f),a&&(u.y-=a),c&&(u.z-=c)}return null==n&&(n=0),null==t&&(t=0),null==r&&(r=0),i.initialize=function(n){e=n},i.x=function(t){return arguments.length?(n=+t,i):n},i.y=function(n){return arguments.length?(t=+n,i):t},i.z=function(n){return arguments.length?(r=+n,i):r},i},n.forceCollide=function(n){var i,u,h,v=1,y=1;function d(){for(var n,o,d,x,g,z,p,M,w=i.length,q=0;q<y;++q)for(o=(1===u?t.binarytree(i,a):2===u?r.quadtree(i,a,c):3===u?e.octree(i,a,c,l):null).visitAfter(s),n=0;n<w;++n)d=i[n],p=h[d.index],M=p*p,x=d.x+d.vx,u>1&&(g=d.y+d.vy),u>2&&(z=d.z+d.vz),o.visit(N);function N(n,t,r,e,i,o,a){var c=[t,r,e,i,o,a],l=c[0],h=c[1],y=c[2],s=c[u],w=c[u+1],q=c[u+2],N=n.data,A=n.r,m=p+A;if(!N)return l>x+m||s<x-m||u>1&&(h>g+m||w<g-m)||u>2&&(y>z+m||q<z-m);if(N.index>d.index){var b=x-N.x-N.vx,k=u>1?g-N.y-N.vy:0,j=u>2?z-N.z-N.vz:0,E=b*b+k*k+j*j;E<m*m&&(0===b&&(E+=(b=f())*b),u>1&&0===k&&(E+=(k=f())*k),u>2&&0===j&&(E+=(j=f())*j),E=(m-(E=Math.sqrt(E)))/E*v,d.vx+=(b*=E)*(m=(A*=A)/(M+A)),u>1&&(d.vy+=(k*=E)*m),u>2&&(d.vz+=(j*=E)*m),N.vx-=b*(m=1-m),u>1&&(N.vy-=k*m),u>2&&(N.vz-=j*m))}}}function s(n){if(n.data)return n.r=h[n.data.index];for(var t=n.r=0;t<Math.pow(2,u);++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}function x(){if(i){var t,r,e=i.length;for(h=new Array(e),t=0;t<e;++t)r=i[t],h[r.index]=+n(r,t,i)}}return"function"!=typeof n&&(n=o(null==n?1:+n)),d.initialize=function(n,t){i=n,u=t,x()},d.iterations=function(n){return arguments.length?(y=+n,d):y},d.strength=function(n){return arguments.length?(v=+n,d):v},d.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),x(),d):n},d},n.forceLink=function(n){var t,r,e,i,u,a,c=h,l=function(n){return 1/Math.min(u[n.source.index],u[n.target.index])},y=o(30),d=1;function s(e){for(var u=0,o=n.length;u<d;++u)for(var c,l,h,v,y,s=0,x=0,g=0,z=0;s<o;++s)l=(c=n[s]).source,x=(h=c.target).x+h.vx-l.x-l.vx||f(),i>1&&(g=h.y+h.vy-l.y-l.vy||f()),i>2&&(z=h.z+h.vz-l.z-l.vz||f()),x*=v=((v=Math.sqrt(x*x+g*g+z*z))-r[s])/v*e*t[s],g*=v,z*=v,h.vx-=x*(y=a[s]),i>1&&(h.vy-=g*y),i>2&&(h.vz-=z*y),l.vx+=x*(y=1-y),i>1&&(l.vy+=g*y),i>2&&(l.vz+=z*y)}function x(){if(e){var i,o,f=e.length,l=n.length,h=new Map(e.map((n,t)=>[c(n,t,e),n]));for(i=0,u=new Array(f);i<l;++i)(o=n[i]).index=i,"object"!=typeof o.source&&(o.source=v(h,o.source)),"object"!=typeof o.target&&(o.target=v(h,o.target)),u[o.source.index]=(u[o.source.index]||0)+1,u[o.target.index]=(u[o.target.index]||0)+1;for(i=0,a=new Array(l);i<l;++i)o=n[i],a[i]=u[o.source.index]/(u[o.source.index]+u[o.target.index]);t=new Array(l),g(),r=new Array(l),z()}}function g(){if(e)for(var r=0,i=n.length;r<i;++r)t[r]=+l(n[r],r,n)}function z(){if(e)for(var t=0,i=n.length;t<i;++t)r[t]=+y(n[t],t,n)}return null==n&&(n=[]),s.initialize=function(n,t){e=n,i=t,x()},s.links=function(t){return arguments.length?(n=t,x(),s):n},s.id=function(n){return arguments.length?(c=n,s):c},s.iterations=function(n){return arguments.length?(d=+n,s):d},s.strength=function(n){return arguments.length?(l="function"==typeof n?n:o(+n),g(),s):l},s.distance=function(n){return arguments.length?(y="function"==typeof n?n:o(+n),z(),s):y},s},n.forceManyBody=function(){var n,i,u,a,c,l=o(-30),h=1,v=1/0,x=.81;function g(o){var f,c=n.length,l=(1===i?t.binarytree(n,y):2===i?r.quadtree(n,y,d):3===i?e.octree(n,y,d,s):null).visitAfter(p);for(a=o,f=0;f<c;++f)u=n[f],l.visit(M)}function z(){if(n){var t,r,e=n.length;for(c=new Array(e),t=0;t<e;++t)r=n[t],c[r.index]=+l(r,t,n)}}function p(n){var t,r,e,u,o,f,a=0,l=0,h=n.length;if(h){for(e=u=o=f=0;f<h;++f)(t=n[f])&&(r=Math.abs(t.value))&&(a+=t.value,l+=r,e+=r*(t.x||0),u+=r*(t.y||0),o+=r*(t.z||0));a*=Math.sqrt(4/h),n.x=e/l,i>1&&(n.y=u/l),i>2&&(n.z=o/l)}else{(t=n).x=t.data.x,i>1&&(t.y=t.data.y),i>2&&(t.z=t.data.z);do{a+=c[t.data.index]}while(t=t.next)}n.value=a}function M(n,t,r,e,o){if(!n.value)return!0;var l=[r,e,o][i-1],y=n.x-u.x,d=i>1?n.y-u.y:0,s=i>2?n.z-u.z:0,g=l-t,z=y*y+d*d+s*s;if(g*g/x<z)return z<v&&(0===y&&(z+=(y=f())*y),i>1&&0===d&&(z+=(d=f())*d),i>2&&0===s&&(z+=(s=f())*s),z<h&&(z=Math.sqrt(h*z)),u.vx+=y*n.value*a/z,i>1&&(u.vy+=d*n.value*a/z),i>2&&(u.vz+=s*n.value*a/z)),!0;if(!(n.length||z>=v)){(n.data!==u||n.next)&&(0===y&&(z+=(y=f())*y),i>1&&0===d&&(z+=(d=f())*d),i>2&&0===s&&(z+=(s=f())*s),z<h&&(z=Math.sqrt(h*z)));do{n.data!==u&&(g=c[n.data.index]*a/z,u.vx+=y*g,i>1&&(u.vy+=d*g),i>2&&(u.vz+=s*g))}while(n=n.next)}}return g.initialize=function(t,r){n=t,i=r,z()},g.strength=function(n){return arguments.length?(l="function"==typeof n?n:o(+n),z(),g):l},g.distanceMin=function(n){return arguments.length?(h=n*n,g):Math.sqrt(h)},g.distanceMax=function(n){return arguments.length?(v=n*n,g):Math.sqrt(v)},g.theta=function(n){return arguments.length?(x=n*n,g):Math.sqrt(x)},g},n.forceRadial=function(n,t,r,e){var i,u,f,a,c=o(.1);function l(n){for(var o=0,c=i.length;o<c;++o){var l=i[o],h=l.x-t||1e-6,v=(l.y||0)-r||1e-6,y=(l.z||0)-e||1e-6,d=Math.sqrt(h*h+v*v+y*y),s=(a[o]-d)*f[o]*n/d;l.vx+=h*s,u>1&&(l.vy+=v*s),u>2&&(l.vz+=y*s)}}function h(){if(i){var t,r=i.length;for(f=new Array(r),a=new Array(r),t=0;t<r;++t)a[t]=+n(i[t],t,i),f[t]=isNaN(a[t])?0:+c(i[t],t,i)}}return"function"!=typeof n&&(n=o(+n)),null==t&&(t=0),null==r&&(r=0),null==e&&(e=0),l.initialize=function(n,t){i=n,u=t,h()},l.strength=function(n){return arguments.length?(c="function"==typeof n?n:o(+n),h(),l):c},l.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),h(),l):n},l.x=function(n){return arguments.length?(t=+n,l):t},l.y=function(n){return arguments.length?(r=+n,l):r},l.z=function(n){return arguments.length?(e=+n,l):e},l},n.forceSimulation=function(n,t){t=t||2;var r,e=Math.min(3,Math.max(1,Math.round(t))),o=1,f=.001,a=1-Math.pow(f,1/300),c=0,l=.6,h=new Map,v=u.timer(d),y=i.dispatch("tick","end");function d(){s(),y.call("tick",r),o<f&&(v.stop(),y.call("end",r))}function s(t){var i,u,f=n.length;void 0===t&&(t=1);for(var v=0;v<t;++v)for(o+=(c-o)*a,h.forEach((function(n){n(o)})),i=0;i<f;++i)null==(u=n[i]).fx?u.x+=u.vx*=l:(u.x=u.fx,u.vx=0),e>1&&(null==u.fy?u.y+=u.vy*=l:(u.y=u.fy,u.vy=0)),e>2&&(null==u.fz?u.z+=u.vz*=l:(u.z=u.fz,u.vz=0));return r}function z(){for(var t,r=0,i=n.length;r<i;++r){if((t=n[r]).index=r,null!=t.fx&&(t.x=t.fx),null!=t.fy&&(t.y=t.fy),null!=t.fz&&(t.z=t.fz),isNaN(t.x)||e>1&&isNaN(t.y)||e>2&&isNaN(t.z)){var u=10*(e>2?Math.cbrt(r):e>1?Math.sqrt(r):r),o=r*x,f=r*g;1===e?t.x=u:2===e?(t.x=u*Math.cos(o),t.y=u*Math.sin(o)):(t.x=u*Math.sin(o)*Math.cos(f),t.y=u*Math.cos(o),t.z=u*Math.sin(o)*Math.sin(f))}(isNaN(t.vx)||e>1&&isNaN(t.vy)||e>2&&isNaN(t.vz))&&(t.vx=0,e>1&&(t.vy=0),e>2&&(t.vz=0))}}function p(t){return t.initialize&&t.initialize(n,e),t}return null==n&&(n=[]),z(),r={tick:s,restart:function(){return v.restart(d),r},stop:function(){return v.stop(),r},numDimensions:function(n){return arguments.length?(e=Math.min(3,Math.max(1,Math.round(n))),h.forEach(p),r):e},nodes:function(t){return arguments.length?(n=t,z(),h.forEach(p),r):n},alpha:function(n){return arguments.length?(o=+n,r):o},alphaMin:function(n){return arguments.length?(f=+n,r):f},alphaDecay:function(n){return arguments.length?(a=+n,r):+a},alphaTarget:function(n){return arguments.length?(c=+n,r):c},velocityDecay:function(n){return arguments.length?(l=1-n,r):1-l},force:function(n,t){return arguments.length>1?(null==t?h.delete(n):h.set(n,p(t)),r):h.get(n)},find:function(){var t,r,i,u,o,f,a=Array.prototype.slice.call(arguments),c=a.shift()||0,l=(e>1?a.shift():null)||0,h=(e>2?a.shift():null)||0,v=a.shift()||1/0,y=0,d=n.length;for(v*=v,y=0;y<d;++y)(u=(t=c-(o=n[y]).x)*t+(r=l-(o.y||0))*r+(i=h-(o.z||0))*i)<v&&(f=o,v=u);return f},on:function(n,t){return arguments.length>1?(y.on(n,t),r):y.on(n)}}},n.forceX=function(n){var t,r,e,i=o(.1);function u(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 u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.x=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},n.forceY=function(n){var t,r,e,i=o(.1);function u(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 u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.y=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},n.forceZ=function(n){var t,r,e,i=o(.1);function u(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vz+=(e[u]-i.z)*r[u]*n}function f(){if(t){var u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.z=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},Object.defineProperty(n,"__esModule",{value:!0})}));
// https://github.com/vasturiano/d3-force-3d v2.2.0 Copyright 2020 Vasco Asturiano
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-binarytree"),require("d3-quadtree"),require("d3-octree"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-binarytree","d3-quadtree","d3-octree","d3-dispatch","d3-timer"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).d3=n.d3||{},n.d3,n.d3,n.d3,n.d3,n.d3)}(this,(function(n,t,r,e,i,u){"use strict";function o(n){return function(){return n}}function f(n){return 1e-6*(n()-.5)}function a(n){return n.x+n.vx}function c(n){return n.y+n.vy}function l(n){return n.z+n.vz}function h(n){return n.index}function v(n,t){var r=n.get(t);if(!r)throw new Error("node not found: "+t);return r}const y=4294967296;function s(n){return n.x}function d(n){return n.y}function g(n){return n.z}var x=Math.PI*(3-Math.sqrt(5)),z=20*Math.PI/(9+Math.sqrt(221));n.forceCenter=function(n,t,r){var e,i=1;function u(){var u,o,f=e.length,a=0,c=0,l=0;for(u=0;u<f;++u)a+=(o=e[u]).x||0,c+=o.y||0,l+=o.z||0;for(a=(a/f-n)*i,c=(c/f-t)*i,l=(l/f-r)*i,u=0;u<f;++u)o=e[u],a&&(o.x-=a),c&&(o.y-=c),l&&(o.z-=l)}return null==n&&(n=0),null==t&&(t=0),null==r&&(r=0),u.initialize=function(n){e=n},u.x=function(t){return arguments.length?(n=+t,u):n},u.y=function(n){return arguments.length?(t=+n,u):t},u.z=function(n){return arguments.length?(r=+n,u):r},u.strength=function(n){return arguments.length?(i=+n,u):i},u},n.forceCollide=function(n){var i,u,h,v,y=1,s=1;function d(){for(var n,o,d,x,z,p,M,w,q=i.length,N=0;N<s;++N)for(o=(1===u?t.binarytree(i,a):2===u?r.quadtree(i,a,c):3===u?e.octree(i,a,c,l):null).visitAfter(g),n=0;n<q;++n)d=i[n],M=h[d.index],w=M*M,x=d.x+d.vx,u>1&&(z=d.y+d.vy),u>2&&(p=d.z+d.vz),o.visit(A);function A(n,t,r,e,i,o,a){var c=[t,r,e,i,o,a],l=c[0],h=c[1],s=c[2],g=c[u],q=c[u+1],N=c[u+2],A=n.data,m=n.r,b=M+m;if(!A)return l>x+b||g<x-b||u>1&&(h>z+b||q<z-b)||u>2&&(s>p+b||N<p-b);if(A.index>d.index){var k=x-A.x-A.vx,E=u>1?z-A.y-A.vy:0,j=u>2?p-A.z-A.vz:0,D=k*k+E*E+j*j;D<b*b&&(0===k&&(D+=(k=f(v))*k),u>1&&0===E&&(D+=(E=f(v))*E),u>2&&0===j&&(D+=(j=f(v))*j),D=(b-(D=Math.sqrt(D)))/D*y,d.vx+=(k*=D)*(b=(m*=m)/(w+m)),u>1&&(d.vy+=(E*=D)*b),u>2&&(d.vz+=(j*=D)*b),A.vx-=k*(b=1-b),u>1&&(A.vy-=E*b),u>2&&(A.vz-=j*b))}}}function g(n){if(n.data)return n.r=h[n.data.index];for(var t=n.r=0;t<Math.pow(2,u);++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}function x(){if(i){var t,r,e=i.length;for(h=new Array(e),t=0;t<e;++t)r=i[t],h[r.index]=+n(r,t,i)}}return"function"!=typeof n&&(n=o(null==n?1:+n)),d.initialize=function(n,t,r){i=n,u=t,v=r,x()},d.iterations=function(n){return arguments.length?(s=+n,d):s},d.strength=function(n){return arguments.length?(y=+n,d):y},d.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),x(),d):n},d},n.forceLink=function(n){var t,r,e,i,u,a,c,l=h,y=function(n){return 1/Math.min(u[n.source.index],u[n.target.index])},s=o(30),d=1;function g(e){for(var u=0,o=n.length;u<d;++u)for(var l,h,v,y,s,g=0,x=0,z=0,p=0;g<o;++g)h=(l=n[g]).source,x=(v=l.target).x+v.vx-h.x-h.vx||f(c),i>1&&(z=v.y+v.vy-h.y-h.vy||f(c)),i>2&&(p=v.z+v.vz-h.z-h.vz||f(c)),x*=y=((y=Math.sqrt(x*x+z*z+p*p))-r[g])/y*e*t[g],z*=y,p*=y,v.vx-=x*(s=a[g]),i>1&&(v.vy-=z*s),i>2&&(v.vz-=p*s),h.vx+=x*(s=1-s),i>1&&(h.vy+=z*s),i>2&&(h.vz+=p*s)}function x(){if(e){var i,o,f=e.length,c=n.length,h=new Map(e.map(((n,t)=>[l(n,t,e),n])));for(i=0,u=new Array(f);i<c;++i)(o=n[i]).index=i,"object"!=typeof o.source&&(o.source=v(h,o.source)),"object"!=typeof o.target&&(o.target=v(h,o.target)),u[o.source.index]=(u[o.source.index]||0)+1,u[o.target.index]=(u[o.target.index]||0)+1;for(i=0,a=new Array(c);i<c;++i)o=n[i],a[i]=u[o.source.index]/(u[o.source.index]+u[o.target.index]);t=new Array(c),z(),r=new Array(c),p()}}function z(){if(e)for(var r=0,i=n.length;r<i;++r)t[r]=+y(n[r],r,n)}function p(){if(e)for(var t=0,i=n.length;t<i;++t)r[t]=+s(n[t],t,n)}return null==n&&(n=[]),g.initialize=function(n,t,r){e=n,i=t,c=r,x()},g.links=function(t){return arguments.length?(n=t,x(),g):n},g.id=function(n){return arguments.length?(l=n,g):l},g.iterations=function(n){return arguments.length?(d=+n,g):d},g.strength=function(n){return arguments.length?(y="function"==typeof n?n:o(+n),z(),g):y},g.distance=function(n){return arguments.length?(s="function"==typeof n?n:o(+n),p(),g):s},g},n.forceManyBody=function(){var n,i,u,a,c,l,h=o(-30),v=1,y=1/0,x=.81;function z(o){var f,a=n.length,l=(1===i?t.binarytree(n,s):2===i?r.quadtree(n,s,d):3===i?e.octree(n,s,d,g):null).visitAfter(M);for(c=o,f=0;f<a;++f)u=n[f],l.visit(w)}function p(){if(n){var t,r,e=n.length;for(l=new Array(e),t=0;t<e;++t)r=n[t],l[r.index]=+h(r,t,n)}}function M(n){var t,r,e,u,o,f,a=0,c=0,h=n.length;if(h){for(e=u=o=f=0;f<h;++f)(t=n[f])&&(r=Math.abs(t.value))&&(a+=t.value,c+=r,e+=r*(t.x||0),u+=r*(t.y||0),o+=r*(t.z||0));a*=Math.sqrt(4/h),n.x=e/c,i>1&&(n.y=u/c),i>2&&(n.z=o/c)}else{(t=n).x=t.data.x,i>1&&(t.y=t.data.y),i>2&&(t.z=t.data.z);do{a+=l[t.data.index]}while(t=t.next)}n.value=a}function w(n,t,r,e,o){if(!n.value)return!0;var h=[r,e,o][i-1],s=n.x-u.x,d=i>1?n.y-u.y:0,g=i>2?n.z-u.z:0,z=h-t,p=s*s+d*d+g*g;if(z*z/x<p)return p<y&&(0===s&&(p+=(s=f(a))*s),i>1&&0===d&&(p+=(d=f(a))*d),i>2&&0===g&&(p+=(g=f(a))*g),p<v&&(p=Math.sqrt(v*p)),u.vx+=s*n.value*c/p,i>1&&(u.vy+=d*n.value*c/p),i>2&&(u.vz+=g*n.value*c/p)),!0;if(!(n.length||p>=y)){(n.data!==u||n.next)&&(0===s&&(p+=(s=f(a))*s),i>1&&0===d&&(p+=(d=f(a))*d),i>2&&0===g&&(p+=(g=f(a))*g),p<v&&(p=Math.sqrt(v*p)));do{n.data!==u&&(z=l[n.data.index]*c/p,u.vx+=s*z,i>1&&(u.vy+=d*z),i>2&&(u.vz+=g*z))}while(n=n.next)}}return z.initialize=function(t,r,e){n=t,i=r,a=e,p()},z.strength=function(n){return arguments.length?(h="function"==typeof n?n:o(+n),p(),z):h},z.distanceMin=function(n){return arguments.length?(v=n*n,z):Math.sqrt(v)},z.distanceMax=function(n){return arguments.length?(y=n*n,z):Math.sqrt(y)},z.theta=function(n){return arguments.length?(x=n*n,z):Math.sqrt(x)},z},n.forceRadial=function(n,t,r,e){var i,u,f,a,c=o(.1);function l(n){for(var o=0,c=i.length;o<c;++o){var l=i[o],h=l.x-t||1e-6,v=(l.y||0)-r||1e-6,y=(l.z||0)-e||1e-6,s=Math.sqrt(h*h+v*v+y*y),d=(a[o]-s)*f[o]*n/s;l.vx+=h*d,u>1&&(l.vy+=v*d),u>2&&(l.vz+=y*d)}}function h(){if(i){var t,r=i.length;for(f=new Array(r),a=new Array(r),t=0;t<r;++t)a[t]=+n(i[t],t,i),f[t]=isNaN(a[t])?0:+c(i[t],t,i)}}return"function"!=typeof n&&(n=o(+n)),null==t&&(t=0),null==r&&(r=0),null==e&&(e=0),l.initialize=function(n,t){i=n,u=t,h()},l.strength=function(n){return arguments.length?(c="function"==typeof n?n:o(+n),h(),l):c},l.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),h(),l):n},l.x=function(n){return arguments.length?(t=+n,l):t},l.y=function(n){return arguments.length?(r=+n,l):r},l.z=function(n){return arguments.length?(e=+n,l):e},l},n.forceSimulation=function(n,t){t=t||2;var r,e=Math.min(3,Math.max(1,Math.round(t))),o=1,f=.001,a=1-Math.pow(f,1/300),c=0,l=.6,h=new Map,v=u.timer(g),s=i.dispatch("tick","end"),d=function(){let n=1;return()=>(n=(1664525*n+1013904223)%y)/y}();function g(){p(),s.call("tick",r),o<f&&(v.stop(),s.call("end",r))}function p(t){var i,u,f=n.length;void 0===t&&(t=1);for(var v=0;v<t;++v)for(o+=(c-o)*a,h.forEach((function(n){n(o)})),i=0;i<f;++i)null==(u=n[i]).fx?u.x+=u.vx*=l:(u.x=u.fx,u.vx=0),e>1&&(null==u.fy?u.y+=u.vy*=l:(u.y=u.fy,u.vy=0)),e>2&&(null==u.fz?u.z+=u.vz*=l:(u.z=u.fz,u.vz=0));return r}function M(){for(var t,r=0,i=n.length;r<i;++r){if((t=n[r]).index=r,null!=t.fx&&(t.x=t.fx),null!=t.fy&&(t.y=t.fy),null!=t.fz&&(t.z=t.fz),isNaN(t.x)||e>1&&isNaN(t.y)||e>2&&isNaN(t.z)){var u=10*(e>2?Math.cbrt(.5+r):e>1?Math.sqrt(.5+r):r),o=r*x,f=r*z;1===e?t.x=u:2===e?(t.x=u*Math.cos(o),t.y=u*Math.sin(o)):(t.x=u*Math.sin(o)*Math.cos(f),t.y=u*Math.cos(o),t.z=u*Math.sin(o)*Math.sin(f))}(isNaN(t.vx)||e>1&&isNaN(t.vy)||e>2&&isNaN(t.vz))&&(t.vx=0,e>1&&(t.vy=0),e>2&&(t.vz=0))}}function w(t){return t.initialize&&t.initialize(n,e,d),t}return null==n&&(n=[]),M(),r={tick:p,restart:function(){return v.restart(g),r},stop:function(){return v.stop(),r},numDimensions:function(n){return arguments.length?(e=Math.min(3,Math.max(1,Math.round(n))),h.forEach(w),r):e},nodes:function(t){return arguments.length?(n=t,M(),h.forEach(w),r):n},alpha:function(n){return arguments.length?(o=+n,r):o},alphaMin:function(n){return arguments.length?(f=+n,r):f},alphaDecay:function(n){return arguments.length?(a=+n,r):+a},alphaTarget:function(n){return arguments.length?(c=+n,r):c},velocityDecay:function(n){return arguments.length?(l=1-n,r):1-l},randomSource:function(n){return arguments.length?(d=n,h.forEach(w),r):d},force:function(n,t){return arguments.length>1?(null==t?h.delete(n):h.set(n,w(t)),r):h.get(n)},find:function(){var t,r,i,u,o,f,a=Array.prototype.slice.call(arguments),c=a.shift()||0,l=(e>1?a.shift():null)||0,h=(e>2?a.shift():null)||0,v=a.shift()||1/0,y=0,s=n.length;for(v*=v,y=0;y<s;++y)(u=(t=c-(o=n[y]).x)*t+(r=l-(o.y||0))*r+(i=h-(o.z||0))*i)<v&&(f=o,v=u);return f},on:function(n,t){return arguments.length>1?(s.on(n,t),r):s.on(n)}}},n.forceX=function(n){var t,r,e,i=o(.1);function u(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 u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.x=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},n.forceY=function(n){var t,r,e,i=o(.1);function u(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 u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.y=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},n.forceZ=function(n){var t,r,e,i=o(.1);function u(n){for(var i,u=0,o=t.length;u<o;++u)(i=t[u]).vz+=(e[u]-i.z)*r[u]*n}function f(){if(t){var u,o=t.length;for(r=new Array(o),e=new Array(o),u=0;u<o;++u)r[u]=isNaN(e[u]=+n(t[u],u,t))?0:+i(t[u],u,t)}}return"function"!=typeof n&&(n=o(null==n?0:+n)),u.initialize=function(n){t=n,f()},u.strength=function(n){return arguments.length?(i="function"==typeof n?n:o(+n),f(),u):i},u.z=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),f(),u):n},u},Object.defineProperty(n,"__esModule",{value:!0})}));
{
"name": "d3-force-3d",
"version": "2.1.0",
"version": "2.2.0",
"description": "Force-directed graph layout in 1D, 2D or 3D using velocity Verlet integration.",

@@ -41,14 +41,15 @@ "keywords": [

"d3-binarytree": "^0.1.8",
"d3-dispatch": "^1.0.6",
"d3-dispatch": "^2.0.0",
"d3-octree": "^0.1.8",
"d3-quadtree": "^1.0.7",
"d3-timer": "^1.0.10"
"d3-quadtree": "^2.0.0",
"d3-timer": "^2.0.0"
},
"sideEffects": false,
"devDependencies": {
"@rollup/plugin-node-resolve": "^7.1.1",
"eslint": "^6.8.0",
"rollup": "^2.0.6",
"rollup-plugin-terser": "^5.3.0",
"tape": "^4.13.2"
"@rollup/plugin-node-resolve": "^10.0.0",
"eslint": "^7.12.1",
"rollup": "^2.32.1",
"rollup-plugin-terser": "^7.0.2",
"tape": "^5.0.1"
}
}

@@ -8,17 +8,17 @@ d3-force-3d

Extended version of [d3-force](https://github.com/d3/d3-force) to support other dimensions besides 2D, via the method [*numDimensions*](#simulation_numDimensions), supporting the values 1, 2 or 3 (default to 2). Fully backwards compatible with [d3-force](https://github.com/d3/d3-force) (version [2.0.0](https://github.com/d3/d3-force/tree/v2.0.0)), and should just work as a drop-in replacement d3 module.
Extended version of [d3-force](https://github.com/d3/d3-force) to support other dimensions besides 2D, via the method [*numDimensions*](#simulation_numDimensions), supporting the values 1, 2 or 3 (default to 2). Fully backwards compatible with [d3-force](https://github.com/d3/d3-force) (version [2.1.1](https://github.com/d3/d3-force/tree/v2.1.1)), and should just work as a drop-in replacement d3 module.
This module implements a [velocity Verlet](https://en.wikipedia.org/wiki/Verlet_integration) numerical integrator for simulating physical forces on particles. The simulation is simplified: it assumes a constant unit time step Δ*t* = 1 for each step, and a constant unit mass *m* = 1 for all particles. As a result, a force *F* acting on a particle is equivalent to a constant acceleration *a* over the time interval Δ*t*, and can be simulated simply by adding to the particle’s velocity, which is then added to the particle’s position.
In the domain of information visualization, physical simulations are useful for studying [networks](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048) and [hierarchies](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)!
In the domain of information visualization, physical simulations are useful for studying [networks](https://observablehq.com/@d3/force-directed-graph) and [hierarchies](https://observablehq.com/@d3/force-directed-tree)!
[<img alt="Force Dragging III" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/graph.png" width="420" height="219">](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048)[<img alt="Force-Directed Tree" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/tree.png" width="420" height="219">](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)
[<img alt="Force-Directed Graph" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/graph.png" width="420" height="219">](https://observablehq.com/@d3/force-directed-graph)[<img alt="Force-Directed Tree" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/tree.png" width="420" height="219">](https://observablehq.com/@d3/force-directed-tree)
You can also simulate circles (disks) with collision, such as for [bubble charts](http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html) or [beeswarm plots](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320):
You can also simulate circles (disks) with collision, such as for [bubble charts](http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html) or [beeswarm plots](https://observablehq.com/@d3/beeswarm):
[<img alt="Collision Detection" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/collide.png" width="420" height="219">](http://bl.ocks.org/mbostock/31ce330646fa8bcb7289ff3b97aab3f5)[<img alt="Beeswarm" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/beeswarm.png" width="420" height="219">](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320)
[<img alt="Collision Detection" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/collide.png" width="420" height="219">](https://observablehq.com/@d3/collision-detection)[<img alt="Beeswarm" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/beeswarm.png" width="420" height="219">](https://observablehq.com/@d3/beeswarm)
You can even use it as a rudimentary physics engine, say to simulate cloth:
[<img alt="Force-Directed Lattice" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/lattice.png" width="480" height="250">](http://bl.ocks.org/mbostock/1b64ec067fcfc51e7471d944f51f1611)
[<img alt="Force-Directed Lattice" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/lattice.png" width="480" height="250">](https://observablehq.com/@d3/force-directed-lattice)

@@ -36,5 +36,5 @@ With this module update, you can also run the simulation in one, two or three dimensions:

```html
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script>
<script src="https://d3js.org/d3-timer.v1.min.js"></script>
<script src="https://d3js.org/d3-quadtree.v1.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v2.min.js"></script>
<script src="https://d3js.org/d3-timer.v2.min.js"></script>
<script src="https://d3js.org/d3-quadtree.v2.min.js"></script>
<script src="https://unpkg.com/d3-binarytree"></script>

@@ -56,15 +56,15 @@ <script src="https://unpkg.com/d3-octree"></script>

<a name="forceSimulation" href="#forceSimulation">#</a> d3.<b>forceSimulation</b>([<i>nodes</i>], [<i>numDimensions</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js "Source")
<a name="forceSimulation" href="#forceSimulation">#</a> d3.<b>forceSimulation</b>([<i>nodes</i>], [<i>numDimensions</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
Creates a new simulation with the specified array of [*nodes*](#simulation_nodes), the number of [dimensions](#simulation_numDimensions) and no [forces](#simulation_force). If *nodes* is not specified, it defaults to the empty array. If *numDimensions* is not specified, it defaults to `2`. The simulator [starts](#simulation_restart) automatically; use [*simulation*.on](#simulation_on) to listen for tick events as the simulation runs. If you wish to run the simulation manually instead, call [*simulation*.stop](#simulation_stop), and then call [*simulation*.tick](#simulation_tick) as desired.
<a name="simulation_restart" href="#simulation_restart">#</a> <i>simulation</i>.<b>restart</b>() [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L109 "Source")
<a name="simulation_restart" href="#simulation_restart">#</a> <i>simulation</i>.<b>restart</b>() · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L113 "Source")
<a name="simulation_stop" href="#simulation_stop">#</a> <i>simulation</i>.<b>stop</b>() · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L48 "Source")
<a name="simulation_tick" href="#simulation_tick">#</a> <i>simulation</i>.<b>tick</b>([<i>iterations</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)

@@ -79,3 +79,3 @@ 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).

<a name="simulation_numDimensions" href="#simulation_numDimensions">#</a> <i>simulation</i>.<b>numDimensions</b>([<i>numDimensions</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L117 "Source")
<a name="simulation_numDimensions" href="#simulation_numDimensions">#</a> <i>simulation</i>.<b>numDimensions</b>([<i>numDimensions</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)

@@ -86,3 +86,3 @@ If *numDimensions* is specified, sets the simulation’s number of dimensions to use (1, 2 or 3), [re-initializes](#force_initialize) any bound [forces](#simulation_force) and returns the simulation. If *numSimulations* is not specified, returns the current simulation’s number of dimensions, which defaults to 2.

<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L123 "Source")
<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)

@@ -101,3 +101,3 @@ 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).

The position ⟨*x*[,*y*[,*z*]]⟩ and velocity ⟨*vx*[,*vy*[,*vz*]]⟩ may be subsequently modified by [forces](#forces) and by the simulation. If either applicable *vx*, *vy* or *vz* is NaN, the velocity is initialized to ⟨0,0,0⟩. If either applicable *x*, *y* or *z* is NaN, the 2D position is initialized in a [phyllotaxis arrangement](http://bl.ocks.org/mbostock/11478058), so chosen to ensure a deterministic, uniform distribution around the origin.
The position ⟨*x*[,*y*[,*z*]]⟩ and velocity ⟨*vx*[,*vy*[,*vz*]]⟩ may be subsequently modified by [forces](#forces) and by the simulation. If either applicable *vx*, *vy* or *vz* is NaN, the velocity is initialized to ⟨0,0,0⟩. If either applicable *x*, *y* or *z* is NaN, the 2D position is initialized in a [phyllotaxis arrangement](https://observablehq.com/@d3/force-layout-phyllotaxis), so chosen to ensure a deterministic, uniform distribution around the origin.

@@ -114,11 +114,13 @@ To fix a node in a given position, you may specify three additional properties:

<a name="simulation_alpha" href="#simulation_alpha">#</a> <i>simulation</i>.<b>alpha</b>([<i>alpha</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L127 "Source")
<a name="simulation_alpha" href="#simulation_alpha">#</a> <i>simulation</i>.<b>alpha</b>([<i>alpha</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
*alpha* is roughly analogous to temperature in [simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing#Overview). It decreases over time as the simulation “cools down”. When *alpha* reaches *alphaMin*, the simulation stops; see [*simulation*.restart](#simulation_restart).
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L131 "Source")
<a name="simulation_alphaMin" href="#simulation_alphaMin">#</a> <i>simulation</i>.<b>alphaMin</b>([<i>min</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L135 "Source")
<a name="simulation_alphaDecay" href="#simulation_alphaDecay">#</a> <i>simulation</i>.<b>alphaDecay</b>([<i>decay</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)

@@ -129,11 +131,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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L139 "Source")
<a name="simulation_alphaTarget" href="#simulation_alphaTarget">#</a> <i>simulation</i>.<b>alphaTarget</b>([<i>target</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L143 "Source")
<a name="simulation_velocityDecay" href="#simulation_velocityDecay">#</a> <i>simulation</i>.<b>velocityDecay</b>([<i>decay</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L147 "Source")
<a name="simulation_force" href="#simulation_force">#</a> <i>simulation</i>.<b>force</b>(<i>name</i>[, <i>force</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)

@@ -155,8 +157,12 @@ 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>z</i>]][, <i>radius</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L151 "Source")
<a name="simulation_find" href="#simulation_find">#</a> <i>simulation</i>.<b>find</b>(<i>x</i>[, <i>y</i>[, <i>z</i>]][, <i>radius</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
Returns the node closest to the position ⟨*x*,*y*,*z*⟩ 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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L181 "Source")
<a name="simulation_randomSource" href="#simulation_randomSource">#</a> <i>simulation</i>.<b>randomSource</b>([<i>source</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js))
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>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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.

@@ -199,9 +205,9 @@

<a name="_force" href="#_force">#</a> <i>force</i>(<i>alpha</i>) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js#L54 "Source")
<a name="_force" href="#_force">#</a> <i>force</i>(<i>alpha</i>) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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/vasturiano/d3-force-3d/blob/master/src/simulation.js#L92 "Source")
<a name="force_initialize" href="#force_initialize">#</a> <i>force</i>.<b>initialize</b>(<i>nodes</i>, <i>numDimensions</i>, <i>random</i>) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/simulation.js)
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*, *numDimensions* 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.

@@ -212,18 +218,22 @@ #### Centering

<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>[, <i>y</i>[, <i>z</i>]]]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js#L1 "Source")
<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>[, <i>y</i>[, <i>z</i>]]]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js)
Creates a new centering force with the specified [*x*-](#center_x), [*y*-](#center_y) and [*z*-](#center_z) coordinates. If *x*, *y* and *z* are not specified, they default to ⟨0,0,0⟩.
<a name="center_x" href="#center_x">#</a> <i>center</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js#L32 "Source")
<a name="center_x" href="#center_x">#</a> <i>center</i>.<b>x</b>([<i>x</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js)
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/vasturiano/d3-force-3d/blob/master/src/center.js#L36 "Source")
<a name="center_y" href="#center_y">#</a> <i>center</i>.<b>y</b>([<i>y</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js)
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_z" href="#center_z">#</a> <i>center</i>.<b>z</b>([<i>z</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js#L40 "Source")
<a name="center_z" href="#center_z">#</a> <i>center</i>.<b>z</b>([<i>z</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js)
If *z* is specified, sets the *z*-coordinate of the centering position to the specified number and returns this force. If *z* is not specified, returns the current *z*-coordinate, which defaults to zero.
<a name="center_strength" href="#center_strength">#</a> <i>center</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js), [Examples](https://observablehq.com/@d3/forcecenter-strength)
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

@@ -233,7 +243,7 @@

<a name="forceCollide" href="#forceCollide">#</a> d3.<b>forceCollide</b>([<i>radius</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js "Source")
<a name="forceCollide" href="#forceCollide">#</a> d3.<b>forceCollide</b>([<i>radius</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js)
Creates a new circle collision force with the specified [*radius*](#collide_radius). If *radius* is not specified, it defaults to the constant one for all nodes.
<a name="collide_radius" href="#collide_radius">#</a> <i>collide</i>.<b>radius</b>([<i>radius</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js#L126 "Source")
<a name="collide_radius" href="#collide_radius">#</a> <i>collide</i>.<b>radius</b>([<i>radius</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js)

@@ -250,9 +260,9 @@ If *radius* is specified, sets the radius accessor to the specified number or function, re-evaluates the radius accessor for each node, and returns this force. If *radius* is not specified, returns the current radius accessor, which defaults to:

<a name="collide_strength" href="#collide_strength">#</a> <i>collide</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js#L122 "Source")
<a name="collide_strength" href="#collide_strength">#</a> <i>collide</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js)
If *strength* is specified, sets the force strength to the specified number in the range [0,1] and returns this force. If *strength* is not specified, returns the current strength which defaults to 0.7.
If *strength* is specified, sets the force strength to the specified number in the range [0,1] and returns this force. If *strength* is not specified, returns the current strength which defaults to 1.
Overlapping nodes are resolved through iterative relaxation. For each node, the other nodes that are anticipated to overlap at the next tick (using the anticipated positions ⟨*x* + *vx*,*y* + *vy*,*z* + *vz*⟩) are determined; the node’s velocity is then modified to push the node out of each overlapping node. The change in velocity is dampened by the force’s strength such that the resolution of simultaneous overlaps can be blended together to find a stable solution.
<a name="collide_iterations" href="#collide_iterations">#</a> <i>collide</i>.<b>iterations</b>([<i>iterations</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js#L118 "Source")
<a name="collide_iterations" href="#collide_iterations">#</a> <i>collide</i>.<b>iterations</b>([<i>iterations</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/collide.js)

@@ -265,7 +275,7 @@ If *iterations* is specified, sets the number of iterations per application to the specified number and returns this force. If *iterations* is not specified, returns the current iteration count which defaults to 1. Increasing the number of iterations greatly increases the rigidity of the constraint and avoids partial overlap of nodes, but also increases the runtime cost to evaluate the force.

<a name="forceLink" href="#forceLink">#</a> d3.<b>forceLink</b>([<i>links</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js "Source")
<a name="forceLink" href="#forceLink">#</a> d3.<b>forceLink</b>([<i>links</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)
Creates a new link force with the specified *links* and default parameters. If *links* is not specified, it defaults to the empty array.
<a name="link_links" href="#link_links">#</a> <i>link</i>.<b>links</b>([<i>links</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js#L103 "Source")
<a name="link_links" href="#link_links">#</a> <i>link</i>.<b>links</b>([<i>links</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)

@@ -284,3 +294,3 @@ If *links* is specified, sets the array of links associated with this force, recomputes the [distance](#link_distance) and [strength](#link_strength) parameters for each link, and returns this force. If *links* is not specified, returns the current array of links, which defaults to the empty array.

<a name="link_id" href="#link_id">#</a> <i>link</i>.<b>id</b>([<i>id</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js#L107 "Source")
<a name="link_id" href="#link_id">#</a> <i>link</i>.<b>id</b>([<i>id</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)

@@ -333,7 +343,7 @@ If *id* is specified, sets the node id accessor to the specified function and returns this force. If *id* is not specified, returns the current node id accessor, which defaults to the numeric *node*.index:

This is particularly useful when representing graphs in JSON, as JSON does not allow references. See [this example](http://bl.ocks.org/mbostock/f584aa36df54c451c94a9d0798caed35).
This is particularly useful when representing graphs in JSON, as JSON does not allow references. See [this example](https://bl.ocks.org/mbostock/f584aa36df54c451c94a9d0798caed35).
The id accessor is invoked for each node whenever the force is initialized, as when the [nodes](#simulation_nodes) or [links](#link_links) change, being passed the node and its zero-based index.
<a name="link_distance" href="#link_distance">#</a> <i>link</i>.<b>distance</b>([<i>distance</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js#L119 "Source")
<a name="link_distance" href="#link_distance">#</a> <i>link</i>.<b>distance</b>([<i>distance</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)

@@ -350,3 +360,3 @@ If *distance* is specified, sets the distance accessor to the specified number or function, re-evaluates the distance accessor for each link, and returns this force. If *distance* is not specified, returns the current distance accessor, which defaults to:

<a name="link_strength" href="#link_strength">#</a> <i>link</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js#L115 "Source")
<a name="link_strength" href="#link_strength">#</a> <i>link</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)

@@ -365,5 +375,5 @@ If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each link, and returns this force. If *strength* is not specified, returns the current strength accessor, which defaults to:

<a name="link_iterations" href="#link_iterations">#</a> <i>link</i>.<b>iterations</b>([<i>iterations</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js#L111 "Source")
<a name="link_iterations" href="#link_iterations">#</a> <i>link</i>.<b>iterations</b>([<i>iterations</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/link.js)
If *iterations* is specified, sets the number of iterations per application to the specified number and returns this force. If *iterations* is not specified, returns the current iteration count which defaults to 1. Increasing the number of iterations greatly increases the rigidity of the constraint and is useful for [complex structures such as lattices](http://bl.ocks.org/mbostock/1b64ec067fcfc51e7471d944f51f1611), but also increases the runtime cost to evaluate the force.
If *iterations* is specified, sets the number of iterations per application to the specified number and returns this force. If *iterations* is not specified, returns the current iteration count which defaults to 1. Increasing the number of iterations greatly increases the rigidity of the constraint and is useful for [complex structures such as lattices](https://observablehq.com/@d3/force-directed-lattice), but also increases the runtime cost to evaluate the force.

@@ -376,7 +386,7 @@ #### Many-Body

<a name="forceManyBody" href="#forceManyBody">#</a> d3.<b>forceManyBody</b>() [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js "Source")
<a name="forceManyBody" href="#forceManyBody">#</a> d3.<b>forceManyBody</b>() · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js)
Creates a new many-body force with the default parameters.
<a name="manyBody_strength" href="#manyBody_strength">#</a> <i>manyBody</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js#L118 "Source")
<a name="manyBody_strength" href="#manyBody_strength">#</a> <i>manyBody</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js)

@@ -393,3 +403,3 @@ 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. A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge. If *strength* is not specified, returns the current strength accessor, which defaults to:

<a name="manyBody_theta" href="#manyBody_theta">#</a> <i>manyBody</i>.<b>theta</b>([<i>theta</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js#L130 "Source")
<a name="manyBody_theta" href="#manyBody_theta">#</a> <i>manyBody</i>.<b>theta</b>([<i>theta</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js)

@@ -400,7 +410,7 @@ If *theta* is specified, sets the Barnes–Hut approximation criterion to the specified number and returns this force. If *theta* is not specified, returns the current value, which defaults to 0.9.

<a name="manyBody_distanceMin" href="#manyBody_distanceMin">#</a> <i>manyBody</i>.<b>distanceMin</b>([<i>distance</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js#L122 "Source")
<a name="manyBody_distanceMin" href="#manyBody_distanceMin">#</a> <i>manyBody</i>.<b>distanceMin</b>([<i>distance</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js)
If *distance* is specified, sets the minimum distance between nodes over which this force is considered. If *distance* is not specified, returns the current minimum distance, which defaults to 1. A minimum distance establishes an upper bound on the strength of the force between two nearby nodes, avoiding instability. In particular, it avoids an infinitely-strong force if two nodes are exactly coincident; in this case, the direction of the force is random.
<a name="manyBody_distanceMax" href="#manyBody_distanceMax">#</a> <i>manyBody</i>.<b>distanceMax</b>([<i>distance</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js#L126 "Source")
<a name="manyBody_distanceMax" href="#manyBody_distanceMax">#</a> <i>manyBody</i>.<b>distanceMax</b>([<i>distance</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/manyBody.js)

@@ -413,7 +423,7 @@ If *distance* is specified, sets the maximum distance between nodes over which this force is considered. If *distance* is not specified, returns the current maximum distance, which defaults to infinity. Specifying a finite maximum distance improves performance and produces a more localized layout.

<a name="forceX" href="#forceX">#</a> d3.<b>forceX</b>([<i>x</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js "Source")
<a name="forceX" href="#forceX">#</a> d3.<b>forceX</b>([<i>x</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js)
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="x_strength" href="#x_strength">#</a> <i>x</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js#L32 "Source")
<a name="x_strength" href="#x_strength">#</a> <i>x</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js)

@@ -432,3 +442,3 @@ 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 much to increment the node’s *x*-velocity: ([*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.

<a name="x_x" href="#x_x">#</a> <i>x</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js#L36 "Source")
<a name="x_x" href="#x_x">#</a> <i>x</i>.<b>x</b>([<i>x</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/x.js)

@@ -445,7 +455,7 @@ 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="forceY" href="#forceY">#</a> d3.<b>forceY</b>([<i>y</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js "Source")
<a name="forceY" href="#forceY">#</a> d3.<b>forceY</b>([<i>y</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js)
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>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js#L32 "Source")
<a name="y_strength" href="#y_strength">#</a> <i>y</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js)

@@ -464,3 +474,3 @@ 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 much to increment the node’s *y*-velocity: ([*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.

<a name="y_y" href="#y_y">#</a> <i>y</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js#L36 "Source")
<a name="y_y" href="#y_y">#</a> <i>y</i>.<b>y</b>([<i>y</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/y.js)

@@ -477,7 +487,7 @@ 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:

<a name="forceZ" href="#forceZ">#</a> d3.<b>forceZ</b>([<i>z</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js "Source")
<a name="forceZ" href="#forceZ">#</a> d3.<b>forceZ</b>([<i>z</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js)
Creates a new positioning force along the *z*-axis towards the given position [*z*](#z_z). If *z* is not specified, it defaults to 0.
<a name="z_strength" href="#z_strength">#</a> <i>z</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js#L32 "Source")
<a name="z_strength" href="#z_strength">#</a> <i>z</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js)

@@ -496,3 +506,3 @@ 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 much to increment the node’s *z*-velocity: ([*z*](#z_z) - *node*.z) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current *z*-position to the target *z*-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.

<a name="z_z" href="#z_z">#</a> <i>z</i>.<b>z</b>([<i>z</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js#L36 "Source")
<a name="z_z" href="#z_z">#</a> <i>z</i>.<b>z</b>([<i>z</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js)

@@ -509,13 +519,13 @@ If *z* is specified, sets the *z*-coordinate accessor to the specified number or function, re-evaluates the *z*-accessor for each node, and returns this force. If *z* is not specified, returns the current *z*-accessor, which defaults to:


<a name="forceRadial" href="#forceRadial">#</a> d3.<b>forceRadial</b>(<i>radius</i>[, <i>x</i>][, <i>y</i>][, <i>z</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")
<a name="forceRadial" href="#forceRadial">#</a> d3.<b>forceRadial</b>(<i>radius</i>[, <i>x</i>][, <i>y</i>][, <i>z</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)


[<img alt="Radial Force" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/radial.png" width="420" height="219">](https://bl.ocks.org/mbostock/cd98bf52e9067e26945edd95e8cf6ef9)[<img alt="Radial Force 3D" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/radial3d.png" height="219">](https://bl.ocks.org/vasturiano/bcfc5baa9e7998fb97b3091d2499fe16)
[<img alt="Radial Force" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/radial.png" width="420" height="219">](https://bl.ocks.org/mbostock/cd98bf52e9067e26945edd95e8cf6ef9)[<img alt="Radial Force 3D" src="https://raw.githubusercontent.com/vasturiano/d3-force-3d/master/img/radial3d.png" height="219">](https://bl.ocks.org/vasturiano/bcfc5baa9e7998fb97b3091d2499fe16)


Creates a new positioning force towards a circle or sphere of the specified [*radius*](#radial_radius) centered at ⟨[*x*](#radial_x),[*y*](#radial_y),[*z*](#radial_z)⟩. If *x*, *y* and *z* are not specified, they default to ⟨0,0,0⟩.
Creates a new positioning force towards a circle or sphere of the specified [*radius*](#radial_radius) centered at ⟨[*x*](#radial_x),[*y*](#radial_y),[*z*](#radial_z)⟩. If *x*, *y* and *z* are not specified, they default to ⟨0,0,0⟩.


<a name="radial_strength" href="#radial_strength">#</a> <i>radial</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")
<a name="radial_strength" href="#radial_strength">#</a> <i>radial</i>.<b>strength</b>([<i>strength</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)


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 much to increment the node’s *x*-, *y* and *z*-velocity. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current position to the closest point on the sphere perimeter 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 much to increment the node’s *x*-, *y* and *z*-velocity. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current position to the closest point on the sphere perimeter 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:


If *strength* is not specified, returns the current strength accessor, which defaults to:



@@ -528,19 +538,19 @@ ```js



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 with a new *strength*, and not on every application of the force.


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 with a new *strength*, and not on every application of the force.


<a name="radial_radius" href="#radial_radius">#</a> <i>radial</i>.<b>radius</b>([<i>radius</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")


<a name="radial_radius" href="#radial_radius">#</a> <i>radial</i>.<b>radius</b>([<i>radius</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)


If *radius* is specified, sets the circle *radius* to the specified number or function, re-evaluates the *radius* accessor for each node, and returns this force. If *radius* is not specified, returns the current *radius* accessor.


The *radius* 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 target radius of each node is only recomputed when the force is initialized or when this method is called with a new *radius*, and not on every application of the force.
The *radius* 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 target radius of each node is only recomputed when the force is initialized or when this method is called with a new *radius*, and not on every application of the force.


<a name="radial_x" href="#radial_x">#</a> <i>radial</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")
<a name="radial_x" href="#radial_x">#</a> <i>radial</i>.<b>x</b>([<i>x</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)


If *x* is specified, sets the *x*-coordinate of the sphere center to the specified number and returns this force. If *x* is not specified, returns the current *x*-coordinate of the center, which defaults to zero.
If *x* is specified, sets the *x*-coordinate of the sphere center to the specified number and returns this force. If *x* is not specified, returns the current *x*-coordinate of the center, which defaults to zero.


<a name="radial_y" href="#radial_y">#</a> <i>radial</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")
<a name="radial_y" href="#radial_y">#</a> <i>radial</i>.<b>y</b>([<i>y</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)


If *y* is specified, sets the *y*-coordinate of the sphere center to the specified number and returns this force. If *y* is not specified, returns the current *y*-coordinate of the center, which defaults to zero.
If *y* is specified, sets the *y*-coordinate of the sphere center to the specified number and returns this force. If *y* is not specified, returns the current *y*-coordinate of the center, which defaults to zero.


<a name="radial_z" href="#radial_z">#</a> <i>radial</i>.<b>z</b>([<i>z</i>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js "Source")


<a name="radial_z" href="#radial_z">#</a> <i>radial</i>.<b>z</b>([<i>z</i>]) · [Source](https://github.com/vasturiano/d3-force-3d/blob/master/src/radial.js)



@@ -547,0 +557,0 @@ If *z* is specified, sets the *z*-coordinate of the sphere center to the specified number and returns this force. If *z* is not specified, returns the current *z*-coordinate of the center, which defaults to zero.

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

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

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

@@ -45,3 +45,7 @@ if (sx) { node.x -= sx }

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

@@ -23,2 +23,3 @@ import {binarytree} from "d3-binarytree";

radii,
random,
strength = 1,

@@ -74,5 +75,5 @@ iterations = 1;

if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
l = (r - (l = Math.sqrt(l))) / l * strength;

@@ -113,5 +114,6 @@

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -118,0 +120,0 @@ };

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

export {default as forceCenter} from "./center";
export {default as forceCollide} from "./collide";
export {default as forceLink} from "./link";
export {default as forceManyBody} from "./manyBody";
export {default as forceRadial} from "./radial";
export {default as forceSimulation} from "./simulation";
export {default as forceX} from "./x";
export {default as forceY} from "./y";
export {default as forceZ} from "./z";
export {default as forceCenter} from "./center.js";
export {default as forceCollide} from "./collide.js";
export {default as forceLink} from "./link.js";
export {default as forceManyBody} from "./manyBody.js";
export {default as forceRadial} from "./radial.js";
export {default as forceSimulation} from "./simulation.js";
export {default as forceX} from "./x.js";
export {default as forceY} from "./y.js";
export {default as forceZ} from "./z.js";

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

export default function() {
return (Math.random() - 0.5) * 1e-6;
export default function(random) {
return (random() - 0.5) * 1e-6;
}

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

bias,
random,
iterations = 1;

@@ -37,5 +38,5 @@

link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle();
if (nDim > 1) { y = target.y + target.vy - source.y - source.vy || jiggle(); }
if (nDim > 2) { z = target.z + target.vz - source.z - source.vz || jiggle(); }
x = target.x + target.vx - source.x - source.vx || jiggle(random);
if (nDim > 1) { y = target.y + target.vy - source.y - source.vy || jiggle(random); }
if (nDim > 2) { z = target.z + target.vz - source.z - source.vz || jiggle(random); }
l = Math.sqrt(x * x + y * y + z * z);

@@ -97,5 +98,6 @@ l = (l - distances[i]) / l * alpha * strengths[i];

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -102,0 +104,0 @@ };

@@ -12,2 +12,3 @@ import {binarytree} from "d3-binarytree";

node,
random,
alpha,

@@ -85,5 +86,5 @@ strength = constant(-30),

if (l < distanceMax2) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -102,5 +103,5 @@ node.vx += x * treeNode.value * alpha / l;

if (treeNode.data !== node || treeNode.next) {
if (x === 0) x = jiggle(), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(), l += z * z;
if (x === 0) x = jiggle(random), l += x * x;
if (nDim > 1 && y === 0) y = jiggle(random), l += y * y;
if (nDim > 2 && z === 0) z = jiggle(random), l += z * z;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);

@@ -117,5 +118,6 @@ }

force.initialize = function(initNodes, numDimensions) {
nodes = initNodes;
nDim = numDimensions;
force.initialize = function(_nodes, _numDimensions, _random) {
nodes = _nodes;
nDim = _numDimensions;
random = _random;
initialize();

@@ -122,0 +124,0 @@ };

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

@@ -34,3 +35,4 @@ var MAX_DIMENSIONS = 3;

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

@@ -85,3 +87,3 @@ if (nodes == null) nodes = [];

if (isNaN(node.x) || (nDim > 1 && isNaN(node.y)) || (nDim > 2 && isNaN(node.z))) {
var radius = initialRadius * (nDim > 2 ? Math.cbrt(i) : (nDim > 1 ? Math.sqrt(i) : i)),
var radius = initialRadius * (nDim > 2 ? Math.cbrt(0.5 + i) : (nDim > 1 ? Math.sqrt(0.5 + i) : i)),
rollAngle = i * initialAngleRoll,

@@ -110,3 +112,3 @@ yawAngle = i * initialAngleYaw;

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

@@ -158,2 +160,6 @@ }

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

@@ -160,0 +166,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