Socket
Socket
Sign inDemoInstall

d3-force

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-force - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0-rc.1

37

dist/d3-force.js

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

// https://d3js.org/d3-force/ v2.0.1 Copyright 2019 Mike Bostock
// https://d3js.org/d3-force/ v2.1.0-rc.1 Copyright 2020 Mike Bostock
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-dispatch'), require('d3-timer')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-dispatch', 'd3-timer'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3));
}(this, (function (exports,d3Quadtree,d3Dispatch,d3Timer) { 'use strict';
(global = global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3));
}(this, function (exports, d3Quadtree, d3Dispatch, d3Timer) { 'use strict';
function center(x, y) {
var nodes;
var nodes, strength = 0.05;

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

function force() {
function force(alpha) {
var i,

@@ -26,4 +26,6 @@ n = nodes.length,

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

@@ -53,4 +55,10 @@ }

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

@@ -159,3 +167,3 @@

var node = nodeById.get(nodeId);
if (!node) throw new Error("missing: " + nodeId);
if (!node) throw new Error("node not found: " + nodeId);
return node;

@@ -287,2 +295,3 @@ }

stepper = d3Timer.timer(step),
started = stepper.stop() || 0,
event = d3Dispatch.dispatch("tick", "end");

@@ -331,3 +340,3 @@

if (isNaN(node.x) || isNaN(node.y)) {
var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
node.x = radius * Math.cos(angle);

@@ -412,3 +421,5 @@ node.y = radius * Math.sin(angle);

on: function(name, _) {
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
return arguments.length > 1
? (event.on(name, _), started++ || stepper.restart(step), simulation)
: event.on(name);
}

@@ -675,2 +686,2 @@ };

})));
}));

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

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

@@ -40,12 +43,13 @@ "keywords": [

"dependencies": {
"d3-dispatch": "1",
"d3-quadtree": "1",
"d3-timer": "1"
"d3-dispatch": ">=2.0.0-rc.1",
"d3-quadtree": ">=2.0.0-rc.1",
"d3-timer": ">=2.0.0-rc.1"
},
"sideEffects": false,
"devDependencies": {
"eslint": "5",
"rollup": "0.64",
"rollup-plugin-terser": "1",
"eslint": "6",
"rollup": "1",
"rollup-plugin-terser": "5",
"tape": "4"
}
}

@@ -35,3 +35,3 @@ # d3-force

[Try d3-force in your browser.](https://beta.observablehq.com/@mbostock/d3-force-directed-graph)
[Try d3-force in your browser.](https://observablehq.com/collection/@d3/d3-force)

@@ -76,3 +76,3 @@ ## API Reference

The position ⟨*x*,*y*⟩ and velocity ⟨*vx*,*vy*⟩ may be subsequently modified by [forces](#forces) and by the simulation. If either *vx* or *vy* is NaN, the velocity is initialized to ⟨0,0⟩. If either *x* or *y* is NaN, the 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*⟩ and velocity ⟨*vx*,*vy*⟩ may be subsequently modified by [forces](#forces) and by the simulation. If either *vx* or *vy* is NaN, the velocity is initialized to ⟨0,0⟩. If either *x* or *y* is NaN, the position is initialized in a [phyllotaxis arrangement](https://observablehq.com/@d3/force-layout-phyllotaxis), so chosen to ensure a deterministic, uniform distribution.

@@ -90,2 +90,4 @@ To fix a node in a given position, you may specify two additional properties:

*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.

@@ -217,3 +219,3 @@

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.

@@ -220,0 +222,0 @@ 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*⟩) 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.

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

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

function force() {
function force(alpha) {
var i,

@@ -19,4 +19,6 @@ n = nodes.length,

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

@@ -23,0 +25,0 @@ }

@@ -1,8 +0,8 @@

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 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";

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

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

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

var node = nodeById.get(nodeId);
if (!node) throw new Error("missing: " + nodeId);
if (!node) throw new Error("node not found: " + nodeId);
return node;

@@ -13,0 +13,0 @@ }

@@ -24,2 +24,3 @@ import {dispatch} from "d3-dispatch";

stepper = timer(step),
started = stepper.stop() || 0,
event = dispatch("tick", "end");

@@ -68,3 +69,3 @@

if (isNaN(node.x) || isNaN(node.y)) {
var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
node.x = radius * Math.cos(angle);

@@ -149,5 +150,7 @@ node.y = radius * Math.sin(angle);

on: function(name, _) {
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
return arguments.length > 1
? (event.on(name, _), started++ || stepper.restart(step), simulation)
: event.on(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