New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 1.1.2 to 2.0.0

61

dist/d3-force-3d.js

@@ -1,7 +0,7 @@

// https://github.com/vasturiano/d3-force-3d v1.1.2 Copyright 2018 Vasco Asturiano
// https://github.com/vasturiano/d3-force-3d v2.0.0 Copyright 2018 Vasco Asturiano
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-binarytree'), require('d3-quadtree'), require('d3-octree'), require('d3-collection'), require('d3-dispatch'), require('d3-timer')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-binarytree', 'd3-quadtree', 'd3-octree', 'd3-collection', 'd3-dispatch', 'd3-timer'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3,global.d3,global.d3));
}(this, (function (exports,d3Binarytree,d3Quadtree,d3Octree,d3Collection,d3Dispatch,d3Timer) { 'use strict';
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) :
(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';

@@ -245,3 +245,3 @@ function center(x, y, z) {

m = links.length,
nodeById = d3Collection.map(nodes, id),
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
link;

@@ -338,3 +338,3 @@

velocityDecay = 0.6,
forces = d3Collection.map(),
forces = new Map(),
stepper = d3Timer.timer(step),

@@ -354,24 +354,30 @@ event = d3Dispatch.dispatch("tick", "end");

function tick() {
function tick(iterations) {
var i, n = nodes.length, node;
alpha += (alphaTarget - alpha) * alphaDecay;
if (iterations === undefined) iterations = 1;
forces.each(function(force) {
force(alpha);
});
for (var k = 0; k < iterations; ++k) {
alpha += (alphaTarget - alpha) * alphaDecay;
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (nDim > 1) {
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
forces.forEach(function (force) {
force(alpha);
});
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (nDim > 1) {
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
}
if (nDim > 2) {
if (node.fz == null) node.z += node.vz *= velocityDecay;
else node.z = node.fz, node.vz = 0;
}
}
if (nDim > 2) {
if (node.fz == null) node.z += node.vz *= velocityDecay;
else node.z = node.fz, node.vz = 0;
}
}
return simulation;
}

@@ -382,2 +388,5 @@

node = nodes[i], node.index = i;
if (!isNaN(node.fx)) node.x = node.fx;
if (!isNaN(node.fy)) node.y = node.fy;
if (!isNaN(node.fz)) node.z = node.fz;
if (isNaN(node.x) || (nDim > 1 && isNaN(node.y)) || (nDim > 2 && isNaN(node.z))) {

@@ -419,3 +428,3 @@ var radius = initialRadius * (nDim > 2 ? Math.cbrt(i) : (nDim > 1 ? Math.sqrt(i) : i)),

return arguments.length
? (nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(_))), forces.each(initializeForce), simulation)
? (nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(_))), forces.forEach(initializeForce), simulation)
: nDim;

@@ -425,3 +434,3 @@ },

nodes: function(_) {
return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
},

@@ -450,3 +459,3 @@

force: function(name, _) {
return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
},

@@ -453,0 +462,0 @@

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

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

@@ -35,5 +35,8 @@ "keywords": [

},
"files": [
"src/**/*.js",
"dist/**/*.js"
],
"dependencies": {
"d3-binarytree": "~0.1",
"d3-collection": "1",
"d3-dispatch": "1",

@@ -40,0 +43,0 @@ "d3-octree": "~0.1",

@@ -5,3 +5,3 @@ # 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 [1.1.2](https://github.com/d3/d3-force/tree/v1.1.2)), 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.0.0](https://github.com/d3/d3-force/tree/v2.0.0)), and should just work as a drop-in replacement d3 module.

@@ -33,3 +33,2 @@ 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.

```html
<script src="https://d3js.org/d3-collection.v1.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script>

@@ -48,3 +47,3 @@ <script src="https://d3js.org/d3-timer.v1.min.js"></script>

[Try d3-force-3d in your browser.](https://tonicdev.com/npm/d3-force-3d)
[Try d3-force-3d in your browser.](https://bl.ocks.org/vasturiano/f59675656258d3f490e9faa40828c0e7)

@@ -69,4 +68,6 @@ ## API Reference

Increments the current [*alpha*](#simulation_alpha) by ([*alphaTarget*](#simulation_alphaTarget) - *alpha*) × [*alphaDecay*](#simulation_alphaDecay); then invokes each registered [force](#simulation_force), passing the new *alpha*; then decrements each [node](#simulation_nodes)’s velocity by *velocity* × [*velocityDecay*](#simulation_velocityDecay); lastly increments each node’s position by *velocity*.
Manually steps the simulation by the specified number of *iterations*, and returns the simulation. If *iterations* is not specified, it defaults to 1 (single step).
For each iteration, it increments the current [*alpha*](#simulation_alpha) by ([*alphaTarget*](#simulation_alphaTarget) - *alpha*) × [*alphaDecay*](#simulation_alphaDecay); then invokes each registered [force](#simulation_force), passing the new *alpha*; then decrements each [node](#simulation_nodes)’s velocity by *velocity* × [*velocityDecay*](#simulation_velocityDecay); lastly increments each node’s position by *velocity*.
This method does not dispatch [events](#simulation_on); events are only dispatched by the internal timer when the simulation is started automatically upon [creation](#forceSimulation) or by calling [*simulation*.restart](#simulation_restart). The natural number of ticks when the simulation is started is ⌈*log*([*alphaMin*](#simulation_alphaMin)) / *log*(1 - [*alphaDecay*](#simulation_alphaDecay))⌉; by default, this is 300.

@@ -76,3 +77,3 @@

<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#L109 "Source")
<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L88 "Source")

@@ -79,0 +80,0 @@ 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.

@@ -1,6 +0,6 @@

import constant from "./constant";
import jiggle from "./jiggle";
import {binarytree} from "d3-binarytree";
import {quadtree} from "d3-quadtree";
import {octree} from "d3-octree";
import constant from "./constant.js";
import jiggle from "./jiggle.js";

@@ -7,0 +7,0 @@ function x(d) {

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

import constant from "./constant";
import jiggle from "./jiggle";
import {map} from "d3-collection";
import constant from "./constant.js";
import jiggle from "./jiggle.js";

@@ -61,3 +60,3 @@ function index(d) {

m = links.length,
nodeById = map(nodes, id),
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
link;

@@ -64,0 +63,0 @@

@@ -1,7 +0,7 @@

import constant from "./constant";
import jiggle from "./jiggle";
import {binarytree} from "d3-binarytree";
import {quadtree} from "d3-quadtree";
import {octree} from "d3-octree";
import {x, y, z} from "./simulation";
import constant from "./constant.js";
import jiggle from "./jiggle.js";
import {x, y, z} from "./simulation.js";

@@ -8,0 +8,0 @@ export default function() {

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

import constant from "./constant";
import constant from "./constant.js";

@@ -3,0 +3,0 @@ export default function(radius, x, y, z) {

import {dispatch} from "d3-dispatch";
import {map} from "d3-collection";
import {timer} from "d3-timer";

@@ -33,3 +32,3 @@

velocityDecay = 0.6,
forces = map(),
forces = new Map(),
stepper = timer(step),

@@ -49,24 +48,30 @@ event = dispatch("tick", "end");

function tick() {
function tick(iterations) {
var i, n = nodes.length, node;
alpha += (alphaTarget - alpha) * alphaDecay;
if (iterations === undefined) iterations = 1;
forces.each(function(force) {
force(alpha);
});
for (var k = 0; k < iterations; ++k) {
alpha += (alphaTarget - alpha) * alphaDecay;
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (nDim > 1) {
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
forces.forEach(function (force) {
force(alpha);
});
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (nDim > 1) {
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
}
if (nDim > 2) {
if (node.fz == null) node.z += node.vz *= velocityDecay;
else node.z = node.fz, node.vz = 0;
}
}
if (nDim > 2) {
if (node.fz == null) node.z += node.vz *= velocityDecay;
else node.z = node.fz, node.vz = 0;
}
}
return simulation;
}

@@ -77,2 +82,5 @@

node = nodes[i], node.index = i;
if (!isNaN(node.fx)) node.x = node.fx;
if (!isNaN(node.fy)) node.y = node.fy;
if (!isNaN(node.fz)) node.z = node.fz;
if (isNaN(node.x) || (nDim > 1 && isNaN(node.y)) || (nDim > 2 && isNaN(node.z))) {

@@ -114,3 +122,3 @@ var radius = initialRadius * (nDim > 2 ? Math.cbrt(i) : (nDim > 1 ? Math.sqrt(i) : i)),

return arguments.length
? (nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(_))), forces.each(initializeForce), simulation)
? (nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(_))), forces.forEach(initializeForce), simulation)
: nDim;

@@ -120,3 +128,3 @@ },

nodes: function(_) {
return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
},

@@ -145,3 +153,3 @@

force: function(name, _) {
return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
},

@@ -148,0 +156,0 @@

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

import constant from "./constant";
import constant from "./constant.js";

@@ -3,0 +3,0 @@ export default function(x) {

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

import constant from "./constant";
import constant from "./constant.js";

@@ -3,0 +3,0 @@ export default function(y) {

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