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

d3-force

Package Overview
Dependencies
Maintainers
1
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 0.7.1 to 1.0.0

img/phyllotaxis.png

37

build/d3-force.js

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

// https://d3js.org/d3-force/ Version 0.7.1. Copyright 2016 Mike Bostock.
// https://d3js.org/d3-force/ Version 1.0.0. Copyright 2016 Mike Bostock.
(function (global, factory) {

@@ -269,5 +269,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-collection'), require('d3-dispatch'), require('d3-timer')) :

alphaTarget = 0,
drag = 0.6,
velocityDecay = 0.6,
forces = d3Collection.map(),
fixes = {},
stepper = d3Timer.timer(step),

@@ -288,3 +287,3 @@ event = d3Dispatch.dispatch("tick", "end");

function tick() {
var i, n = nodes.length, node, fix;
var i, n = nodes.length, node;

@@ -299,13 +298,7 @@ alpha += (alphaTarget - alpha) * alphaDecay;

node = nodes[i];
node.x += node.vx *= drag;
node.y += node.vy *= drag;
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
}
for (i in fixes) {
fix = fixes[i], node = nodes[i];
node.x = fix.x;
node.y = fix.y;
node.vx =
node.vy = 0;
}
}

@@ -365,4 +358,4 @@

drag: function(_) {
return arguments.length ? (drag = 1 - _, simulation) : 1 - drag;
velocityDecay: function(_) {
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
},

@@ -374,14 +367,2 @@

fix: function(node, x, y) {
return fixes[node.index] = {x: x == null ? node.x : +x, y: y == null ? node.y : +y}, simulation;
},
unfix: function(node) {
return delete fixes[node.index], simulation;
},
unfixAll: function() {
return fixes = {}, simulation;
},
find: function(x, y, radius) {

@@ -388,0 +369,0 @@ var i = 0,

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

// https://d3js.org/d3-force/ Version 0.7.1. Copyright 2016 Mike Bostock.
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-collection"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-collection","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i){"use strict";function u(n,t){function e(){var e,i,u=r.length,o=0,f=0;for(e=0;u>e;++e)i=r[e],o+=i.x,f+=i.y;for(o=o/u-n,f=f/u-t,e=0;u>e;++e)i=r[e],i.x-=o,i.y-=f}var r;return null==n&&(n=0),null==t&&(t=0),e.initialize=function(n){r=n},e.x=function(t){return arguments.length?(n=+t,e):n},e.y=function(n){return arguments.length?(t=+n,e):t},e}function 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){function e(){function n(n,t,r,i,u){var o=n.data,a=n.r,c=x+a;{if(!o)return t>y+c||y-c>i||r>d+c||d-c>u;if(o.index>e){var h=y-o.x-o.vx,s=d-o.y-o.vy,p=h*h+s*s;c*c>p&&(0===h&&(h=f(),p+=h*h),0===s&&(s=f(),p+=s*s),p=(c-(p=Math.sqrt(p)))/p*l,v.vx+=(h*=p)*(c=(a*=a)/(g+a)),v.vy+=(s*=p)*c,o.vx-=h*(c=1-c),o.vy-=s*c)}}}for(var e,o,v,y,d,x,g,s=i.length,p=0;h>p;++p)for(o=t.quadtree(i,a,c).visitAfter(r),e=0;s>e;++e)v=i[e],x=u[e],g=x*x,y=v.x+v.vx,d=v.y+v.vy,o.visit(n)}function r(n){if(n.data)return n.r=u[n.data.index];for(var t=n.r=0;4>t;++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}var i,u,l=1,h=1;return"function"!=typeof n&&(n=o(null==n?1:+n)),e.initialize=function(t){var e,r=(i=t).length;for(u=new Array(r),e=0;r>e;++e)u[e]=+n(i[e],e,i)},e.iterations=function(n){return arguments.length?(h=+n,e):h},e.strength=function(n){return arguments.length?(l=+n,e):l},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),e):n},e}function h(n,t){return t}function v(n){function t(n){return 1/Math.min(y[n.source.index],y[n.target.index])}function r(t){for(var e=0,r=n.length;p>e;++e)for(var i,u,o,a,h,v,y,x=0;r>x;++x)i=n[x],u=i.source,o=i.target,a=o.x+o.vx-u.x-u.vx||f(),h=o.y+o.vy-u.y-u.vy||f(),v=Math.sqrt(a*a+h*h),v=(v-l[x])/v*t*c[x],a*=v,h*=v,o.vx-=a*(y=d[x]),o.vy-=h*y,u.vx+=a*(y=1-y),u.vy+=h*y}function i(){if(v){var t,r,i=v.length,o=n.length,f=e.map(v,x);for(t=0,y=new Array(i);i>t;++t)y[t]=0;for(t=0;o>t;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=f.get(r.source)),"object"!=typeof r.target&&(r.target=f.get(r.target)),++y[r.source.index],++y[r.target.index];for(t=0,d=new Array(o);o>t;++t)r=n[t],d[t]=y[r.source.index]/(y[r.source.index]+y[r.target.index]);c=new Array(o),u(),l=new Array(o),a()}}function u(){if(v)for(var t=0,e=n.length;e>t;++t)c[t]=+g(n[t],t,n)}function a(){if(v)for(var t=0,e=n.length;e>t;++t)l[t]=+s(n[t],t,n)}var c,l,v,y,d,x=h,g=t,s=o(30),p=1;return null==n&&(n=[]),r.initialize=function(n){v=n,i()},r.links=function(t){return arguments.length?(n=t,i(),r):n},r.id=function(n){return arguments.length?(x=n,r):x},r.iterations=function(n){return arguments.length?(p=+n,r):p},r.strength=function(n){return arguments.length?(g="function"==typeof n?n:o(+n),u(),r):g},r.distance=function(n){return arguments.length?(s="function"==typeof n?n:o(+n),a(),r):s},r}function y(n){return n.x}function d(n){return n.y}function x(n){function t(){u(),s.call("tick",a),l>c&&(g.stop(),s.call("end",a))}function u(){var t,e,r,i=n.length;for(c+=(v-c)*h,d.each(function(n){n(c)}),t=0;i>t;++t)e=n[t],e.x+=e.vx*=y,e.y+=e.vy*=y;for(t in x)r=x[t],e=n[t],e.x=r.x,e.y=r.y,e.vx=e.vy=0}function o(){for(var t,e=0,r=n.length;r>e;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=M*Math.sqrt(e),u=e*q;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function f(t){return t.initialize&&t.initialize(n),t}var a,c=1,l=.001,h=1-Math.pow(l,1/300),v=0,y=.6,d=e.map(),x={},g=i.timer(t),s=r.dispatch("tick","end");return null==n&&(n=[]),o(),a={tick:u,restart:function(){return g.restart(t),a},stop:function(){return g.stop(),a},nodes:function(t){return arguments.length?(n=t,o(),d.each(f),a):n},alpha:function(n){return arguments.length?(c=+n,a):c},alphaMin:function(n){return arguments.length?(l=+n,a):l},alphaDecay:function(n){return arguments.length?(h=+n,a):+h},alphaTarget:function(n){return arguments.length?(v=+n,a):v},drag:function(n){return arguments.length?(y=1-n,a):1-y},force:function(n,t){return arguments.length>1?(null==t?d.remove(n):d.set(n,f(t)),a):d.get(n)},fix:function(n,t,e){return x[n.index]={x:null==t?n.x:+t,y:null==e?n.y:+e},a},unfix:function(n){return delete x[n.index],a},unfixAll:function(){return x={},a},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;l>c;++c)f=n[c],i=t-f.x,u=e-f.y,o=i*i+u*u,r>o&&(a=f,r=o);return a},on:function(n,t){return arguments.length>1?(s.on(n,t),a):s.on(n)}}}function g(){function n(n){var e,o=u.length,f=t.quadtree(u,y,d).visitAfter(r);for(c=n,e=0;o>e;++e)a=u[e],f.visit(i)}function e(){if(u){var n,t=u.length;for(l=new Array(t),n=0;t>n;++n)l[n]=+h(u[n],n,u)}}function r(n){var t,e,r,i,u,o=0;if(n.length){for(r=i=u=0;4>u;++u)(t=n[u])&&(e=t.value)&&(o+=e,r+=e*t.x,i+=e*t.y);n.x=r/o,n.y=i/o}else{t=n,t.x=t.data.x,t.y=t.data.y;do o+=l[t.data.index];while(t=t.next)}n.value=o}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-a.x,u=n.y-a.y,o=r-t,h=i*i+u*u;if(h>o*o/g)return x>h&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),v>h&&(h=Math.sqrt(v*h)),a.vx+=i*n.value*c/h,a.vy+=u*n.value*c/h),!0;if(!(n.length||h>=x)){(n.data!==a||n.next)&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),v>h&&(h=Math.sqrt(v*h)));do n.data!==a&&(o=l[n.data.index]*c/h,a.vx+=i*o,a.vy+=u*o);while(n=n.next)}}var u,a,c,l,h=o(-30),v=1,x=1/0,g=.81;return n.initialize=function(n){u=n,e()},n.strength=function(t){return arguments.length?(h="function"==typeof t?t:o(+t),e(),n):h},n.distanceMin=function(t){return arguments.length?(v=t*t,n):Math.sqrt(v)},n.distanceMax=function(t){return arguments.length?(x=t*t,n):Math.sqrt(x)},n.theta=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n}function s(n){function t(n){for(var t,e=0,o=r.length;o>e;++e)t=r[e],t.vx+=(u[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;e>t;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.x=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}function p(n){function t(n){for(var t,e=0,o=r.length;o>e;++e)t=r[e],t.vy+=(u[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;e>t;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.y=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}var M=10,q=Math.PI*(3-Math.sqrt(5));n.forceCenter=u,n.forceCollide=l,n.forceLink=v,n.forceManyBody=g,n.forceSimulation=x,n.forceX=s,n.forceY=p,Object.defineProperty(n,"__esModule",{value:!0})});
// https://d3js.org/d3-force/ Version 1.0.0. Copyright 2016 Mike Bostock.
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-collection"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-collection","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i){"use strict";function u(n,t){function e(){var e,i,u=r.length,o=0,f=0;for(e=0;e<u;++e)i=r[e],o+=i.x,f+=i.y;for(o=o/u-n,f=f/u-t,e=0;e<u;++e)i=r[e],i.x-=o,i.y-=f}var r;return null==n&&(n=0),null==t&&(t=0),e.initialize=function(n){r=n},e.x=function(t){return arguments.length?(n=+t,e):n},e.y=function(n){return arguments.length?(t=+n,e):t},e}function 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){function e(){function n(n,t,r,i,u){var o=n.data,a=n.r,c=g+a;{if(!o)return t>y+c||i<y-c||r>d+c||u<d-c;if(o.index>e){var h=y-o.x-o.vx,s=d-o.y-o.vy,p=h*h+s*s;p<c*c&&(0===h&&(h=f(),p+=h*h),0===s&&(s=f(),p+=s*s),p=(c-(p=Math.sqrt(p)))/p*l,v.vx+=(h*=p)*(c=(a*=a)/(x+a)),v.vy+=(s*=p)*c,o.vx-=h*(c=1-c),o.vy-=s*c)}}}for(var e,o,v,y,d,g,x,s=i.length,p=0;p<h;++p)for(o=t.quadtree(i,a,c).visitAfter(r),e=0;e<s;++e)v=i[e],g=u[e],x=g*g,y=v.x+v.vx,d=v.y+v.vy,o.visit(n)}function r(n){if(n.data)return n.r=u[n.data.index];for(var t=n.r=0;t<4;++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}var i,u,l=1,h=1;return"function"!=typeof n&&(n=o(null==n?1:+n)),e.initialize=function(t){var e,r=(i=t).length;for(u=new Array(r),e=0;e<r;++e)u[e]=+n(i[e],e,i)},e.iterations=function(n){return arguments.length?(h=+n,e):h},e.strength=function(n){return arguments.length?(l=+n,e):l},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),e):n},e}function h(n,t){return t}function v(n){function t(n){return 1/Math.min(y[n.source.index],y[n.target.index])}function r(t){for(var e=0,r=n.length;e<p;++e)for(var i,u,o,a,h,v,y,g=0;g<r;++g)i=n[g],u=i.source,o=i.target,a=o.x+o.vx-u.x-u.vx||f(),h=o.y+o.vy-u.y-u.vy||f(),v=Math.sqrt(a*a+h*h),v=(v-l[g])/v*t*c[g],a*=v,h*=v,o.vx-=a*(y=d[g]),o.vy-=h*y,u.vx+=a*(y=1-y),u.vy+=h*y}function i(){if(v){var t,r,i=v.length,o=n.length,f=e.map(v,g);for(t=0,y=new Array(i);t<i;++t)y[t]=0;for(t=0;t<o;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=f.get(r.source)),"object"!=typeof r.target&&(r.target=f.get(r.target)),++y[r.source.index],++y[r.target.index];for(t=0,d=new Array(o);t<o;++t)r=n[t],d[t]=y[r.source.index]/(y[r.source.index]+y[r.target.index]);c=new Array(o),u(),l=new Array(o),a()}}function u(){if(v)for(var t=0,e=n.length;t<e;++t)c[t]=+x(n[t],t,n)}function a(){if(v)for(var t=0,e=n.length;t<e;++t)l[t]=+s(n[t],t,n)}var c,l,v,y,d,g=h,x=t,s=o(30),p=1;return null==n&&(n=[]),r.initialize=function(n){v=n,i()},r.links=function(t){return arguments.length?(n=t,i(),r):n},r.id=function(n){return arguments.length?(g=n,r):g},r.iterations=function(n){return arguments.length?(p=+n,r):p},r.strength=function(n){return arguments.length?(x="function"==typeof n?n:o(+n),u(),r):x},r.distance=function(n){return arguments.length?(s="function"==typeof n?n:o(+n),a(),r):s},r}function y(n){return n.x}function d(n){return n.y}function g(n){function t(){u(),x.call("tick",a),c<l&&(g.stop(),x.call("end",a))}function u(){var t,e,r=n.length;for(c+=(v-c)*h,d.each(function(n){n(c)}),t=0;t<r;++t)e=n[t],null==e.fx?e.x+=e.vx*=y:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=y:(e.y=e.fy,e.vy=0)}function o(){for(var t,e=0,r=n.length;e<r;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=M*Math.sqrt(e),u=e*q;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function f(t){return t.initialize&&t.initialize(n),t}var a,c=1,l=.001,h=1-Math.pow(l,1/300),v=0,y=.6,d=e.map(),g=i.timer(t),x=r.dispatch("tick","end");return null==n&&(n=[]),o(),a={tick:u,restart:function(){return g.restart(t),a},stop:function(){return g.stop(),a},nodes:function(t){return arguments.length?(n=t,o(),d.each(f),a):n},alpha:function(n){return arguments.length?(c=+n,a):c},alphaMin:function(n){return arguments.length?(l=+n,a):l},alphaDecay:function(n){return arguments.length?(h=+n,a):+h},alphaTarget:function(n){return arguments.length?(v=+n,a):v},velocityDecay:function(n){return arguments.length?(y=1-n,a):1-y},force:function(n,t){return arguments.length>1?(null==t?d.remove(n):d.set(n,f(t)),a):d.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)f=n[c],i=t-f.x,u=e-f.y,o=i*i+u*u,o<r&&(a=f,r=o);return a},on:function(n,t){return arguments.length>1?(x.on(n,t),a):x.on(n)}}}function x(){function n(n){var e,o=u.length,f=t.quadtree(u,y,d).visitAfter(r);for(c=n,e=0;e<o;++e)a=u[e],f.visit(i)}function e(){if(u){var n,t=u.length;for(l=new Array(t),n=0;n<t;++n)l[n]=+h(u[n],n,u)}}function r(n){var t,e,r,i,u,o=0;if(n.length){for(r=i=u=0;u<4;++u)(t=n[u])&&(e=t.value)&&(o+=e,r+=e*t.x,i+=e*t.y);n.x=r/o,n.y=i/o}else{t=n,t.x=t.data.x,t.y=t.data.y;do o+=l[t.data.index];while(t=t.next)}n.value=o}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-a.x,u=n.y-a.y,o=r-t,h=i*i+u*u;if(o*o/x<h)return h<g&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),h<v&&(h=Math.sqrt(v*h)),a.vx+=i*n.value*c/h,a.vy+=u*n.value*c/h),!0;if(!(n.length||h>=g)){(n.data!==a||n.next)&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),h<v&&(h=Math.sqrt(v*h)));do n.data!==a&&(o=l[n.data.index]*c/h,a.vx+=i*o,a.vy+=u*o);while(n=n.next)}}var u,a,c,l,h=o(-30),v=1,g=1/0,x=.81;return n.initialize=function(n){u=n,e()},n.strength=function(t){return arguments.length?(h="function"==typeof t?t:o(+t),e(),n):h},n.distanceMin=function(t){return arguments.length?(v=t*t,n):Math.sqrt(v)},n.distanceMax=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n.theta=function(t){return arguments.length?(x=t*t,n):Math.sqrt(x)},n}function s(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vx+=(u[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.x=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}function p(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vy+=(u[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.y=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}var M=10,q=Math.PI*(3-Math.sqrt(5));n.forceCenter=u,n.forceCollide=l,n.forceLink=v,n.forceManyBody=x,n.forceSimulation=g,n.forceX=s,n.forceY=p,Object.defineProperty(n,"__esModule",{value:!0})});
{
"name": "d3-force",
"version": "0.7.1",
"version": "1.0.0",
"description": "Force-directed graph layout using velocity Verlet integration.",

@@ -31,3 +31,3 @@ "keywords": [

"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-force.js -c -m -o build/d3-force.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v0.7.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v0.7.min.js && cd ../d3.github.com && git add d3-force.v0.7.js d3-force.v0.7.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js"
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-force.js ../d3.github.com/d3-force.v1.js && cp build/d3-force.min.js ../d3.github.com/d3-force.v1.min.js && cd ../d3.github.com && git add d3-force.v1.js d3-force.v1.min.js && git commit -m \"d3-force ${VERSION}\" && git push && cd - && zip -j build/d3-force.zip -- LICENSE README.md build/d3-force.js build/d3-force.min.js"
},

@@ -43,3 +43,3 @@ "dependencies": {

"package-preamble": "0.0",
"rollup": "0.31",
"rollup": "0.33",
"tape": "4",

@@ -46,0 +46,0 @@ "uglify-js": "2"

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

If you use NPM, `npm install d3-force`. Otherwise, download the [latest release](https://github.com/d3/d3-force/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-force.v0.7.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported:
If you use NPM, `npm install d3-force`. Otherwise, download the [latest release](https://github.com/d3/d3-force/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-force.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported:

@@ -29,3 +29,3 @@ ```html

<script src="https://d3js.org/d3-timer.v1.min.js"></script>
<script src="https://d3js.org/d3-force.v0.7.min.js"></script>
<script src="https://d3js.org/d3-force.v1.min.js"></script>
<script>

@@ -58,3 +58,3 @@

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* × [*drag*](#simulation_drag); lastly increments each node’s position by *velocity*.
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*.

@@ -77,2 +77,9 @@ 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.

To fix a node in a given position, you may specify two additional properties:
* `fx` - the node’s fixed *x*-position
* `fy` - the node’s fixed *y*-position
At the end of each [tick](#simulation_tick), after the application of any forces, a node with a defined *node*.fx has *node*.x reset to this value and *node*.vx set to zero; likewise, a node with a defined *node*.fy has *node*.y reset to this value and *node*.vy set to zero.
If the specified array of *nodes* is modified, such as when nodes are added to or removed from the simulation, this method must be called again with the new (or changed) array to notify the simulation and bound forces of the change; the simulation does not make a defensive copy of the specified array.

@@ -98,5 +105,5 @@

<a name="simulation_drag" href="#simulation_drag">#</a> <i>simulation</i>.<b>drag</b>([<i>drag</i>])
<a name="simulation_velocityDecay" href="#simulation_velocityDecay">#</a> <i>simulation</i>.<b>velocityDecay</b>([<i>decay</i>])
If *drag* is specified, sets the drag factor to the specified number in [0,1] and returns this simulation. If *drag* is not specified, returns the current drag factor, which defaults to 0.4. The drag factor affects how quickly nodes’ velocities decay; after the application of any forces during a [tick](#simulation_tick), each node’s velocity is multiplied by 1 - *drag*. As with lowering the [alpha decay rate](#simulation_alphaDecay), less drag may converge on a better solution, but it also risks numerical instabilities and oscillations.
If *decay* is specified, sets the velocity decay factor to the specified number in [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.

@@ -114,14 +121,2 @@ <a name="simulation_force" href="#simulation_force">#</a> <i>simulation</i>.<b>force</b>(<i>name</i>[, <i>force</i>])

<a name="simulation_fix" href="#simulation_fix">#</a> <i>simulation</i>.<b>fix</b>(<i>node</i>[, <i>x</i>, <i>y</i>])
Fixes the given *node*’s position to ⟨*x*,*y*⟩ and the velocity to zero, and returns this simulation. If *x* and *y* are not specified, the fixed position defaults to the node’s current position. When a node is fixed, its position is reset to ⟨*x*,*y*⟩ and its velocity is reset to zero at the end of each tick, after the application of any forces. This method is intended to temporarily freeze the position of one or more nodes during interaction, such as when dragging or hovering. After the interaction completes, use [*simulation*.unfix](#simulation_unfix) to release the node.
<a name="simulation_unfix" href="#simulation_unfix">#</a> <i>simulation</i>.<b>unfix</b>(<i>node</i>)
If the given *node* is currently [fixed](#simulation_fix), unfixes (frees) the *node*’s position and returns this simulation.
<a name="simulation_unfixAll" href="#simulation_unfixAll">#</a> <i>simulation</i>.<b>unfixAll</b>()
Unfixes (frees) the position of any [fixed](#simulation_fix) nodes and returns this simulation.
<a name="simulation_find" href="#simulation_find">#</a> <i>simulation</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>radius</i>])

@@ -364,3 +359,3 @@

The [*x*](#forceX)- and [*y*](#forceY)-positioning forces push nodes towards a desired position along the given dimension with a configurable strength. The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position. While these forces can be used to position individual nodes, they are intended primarily for global forces that apply to all (or most) nodes; see [*simulation*.fix](#simulation_fix).
The [*x*](#forceX)- and [*y*](#forceY)-positioning forces push nodes towards a desired position along the given dimension with a configurable strength. The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position. While these forces can be used to position individual nodes, they are intended primarily for global forces that apply to all (or most) nodes.

@@ -367,0 +362,0 @@ <a name="forceX" href="#forceX">#</a> d3.<b>forceX</b>([<i>x</i>])

@@ -22,5 +22,4 @@ import {dispatch} from "d3-dispatch";

alphaTarget = 0,
drag = 0.6,
velocityDecay = 0.6,
forces = map(),
fixes = {},
stepper = timer(step),

@@ -41,3 +40,3 @@ event = dispatch("tick", "end");

function tick() {
var i, n = nodes.length, node, fix;
var i, n = nodes.length, node;

@@ -52,13 +51,7 @@ alpha += (alphaTarget - alpha) * alphaDecay;

node = nodes[i];
node.x += node.vx *= drag;
node.y += node.vy *= drag;
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
}
for (i in fixes) {
fix = fixes[i], node = nodes[i];
node.x = fix.x;
node.y = fix.y;
node.vx =
node.vy = 0;
}
}

@@ -118,4 +111,4 @@

drag: function(_) {
return arguments.length ? (drag = 1 - _, simulation) : 1 - drag;
velocityDecay: function(_) {
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
},

@@ -127,14 +120,2 @@

fix: function(node, x, y) {
return fixes[node.index] = {x: x == null ? node.x : +x, y: y == null ? node.y : +y}, simulation;
},
unfix: function(node) {
return delete fixes[node.index], simulation;
},
unfixAll: function() {
return fixes = {}, simulation;
},
find: function(x, y, radius) {

@@ -141,0 +122,0 @@ var i = 0,

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