d3-force-3d
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -1,2 +0,2 @@ | ||
// https://github.com/vasturiano/d3-force-3d Version 1.0.7. Copyright 2017 Vasco Asturiano. | ||
// https://github.com/vasturiano/d3-force-3d Version 1.1.0. Copyright 2018 Vasco Asturiano. | ||
(function (global, factory) { | ||
@@ -444,3 +444,3 @@ 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')) : | ||
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.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name); | ||
}, | ||
@@ -516,14 +516,14 @@ | ||
function accumulate(treeNode) { | ||
var strength = 0, q, c, x$$1, y$$1, z$$1, i; | ||
var strength = 0, q, c, weight = 0, x, y, z, i; | ||
// For internal nodes, accumulate forces from children. | ||
if (treeNode.length) { | ||
for (x$$1 = y$$1 = z$$1 = i = 0; i < 4; ++i) { | ||
if ((q = treeNode[i]) && (c = q.value)) { | ||
strength += c, x$$1 += c * (q.x || 0), y$$1 += c * (q.y || 0), z$$1 += c * (q.z || 0); | ||
for (x = y = z = i = 0; i < 4; ++i) { | ||
if ((q = treeNode[i]) && (c = Math.abs(q.value))) { | ||
strength += q.value, weight += c, x += c * (q.x || 0), y += c * (q.y || 0), z += c * (q.z || 0); | ||
} | ||
} | ||
treeNode.x = x$$1 / strength; | ||
if (nDim > 1) { treeNode.y = y$$1 / strength; } | ||
if (nDim > 2) { treeNode.z = z$$1 / strength; } | ||
treeNode.x = x / weight; | ||
if (nDim > 1) { treeNode.y = y / weight; } | ||
if (nDim > 2) { treeNode.z = z / weight; } | ||
} | ||
@@ -548,7 +548,7 @@ | ||
var x$$1 = treeNode.x - node.x, | ||
y$$1 = (nDim > 1 ? treeNode.y - node.y : 0), | ||
z$$1 = (nDim > 2 ? treeNode.z - node.z : 0), | ||
var x = treeNode.x - node.x, | ||
y = (nDim > 1 ? treeNode.y - node.y : 0), | ||
z = (nDim > 2 ? treeNode.z - node.z : 0), | ||
w = x2 - x1, | ||
l = x$$1 * x$$1 + y$$1 * y$$1 + z$$1 * z$$1; | ||
l = x * x + y * y + z * z; | ||
@@ -559,9 +559,9 @@ // Apply the Barnes-Hut approximation if possible. | ||
if (l < distanceMax2) { | ||
if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1; | ||
if (nDim > 1 && y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1; | ||
if (nDim > 2 && z$$1 === 0) z$$1 = jiggle(), l += z$$1 * z$$1; | ||
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 (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
node.vx += x$$1 * treeNode.value * alpha / l; | ||
if (nDim > 1) { node.vy += y$$1 * treeNode.value * alpha / l; } | ||
if (nDim > 2) { node.vz += z$$1 * treeNode.value * alpha / l; } | ||
node.vx += x * treeNode.value * alpha / l; | ||
if (nDim > 1) { node.vy += y * treeNode.value * alpha / l; } | ||
if (nDim > 2) { node.vz += z * treeNode.value * alpha / l; } | ||
} | ||
@@ -576,5 +576,5 @@ return true; | ||
if (treeNode.data !== node || treeNode.next) { | ||
if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1; | ||
if (nDim > 1 && y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1; | ||
if (nDim > 2 && z$$1 === 0) z$$1 = jiggle(), l += z$$1 * z$$1; | ||
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 (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); | ||
@@ -585,5 +585,5 @@ } | ||
w = strengths[treeNode.data.index] * alpha / l; | ||
node.vx += x$$1 * w; | ||
if (nDim > 1) { node.vy += y$$1 * w; } | ||
if (nDim > 2) { node.vz += z$$1 * w; } | ||
node.vx += x * w; | ||
if (nDim > 1) { node.vy += y * w; } | ||
if (nDim > 2) { node.vz += z * w; } | ||
} while (treeNode = treeNode.next); | ||
@@ -617,2 +617,68 @@ } | ||
var radial = function(radius, x, y, z) { | ||
var nodes, | ||
nDim, | ||
strength = constant(0.1), | ||
strengths, | ||
radiuses; | ||
if (typeof radius !== "function") radius = constant(+radius); | ||
if (x == null) x = 0; | ||
if (y == null) y = 0; | ||
if (z == null) z = 0; | ||
function force(alpha) { | ||
for (var i = 0, n = nodes.length; i < n; ++i) { | ||
var node = nodes[i], | ||
dx = node.x - x || 1e-6, | ||
dy = (node.y || 0) - y || 1e-6, | ||
dz = (node.z || 0) - z || 1e-6, | ||
r = Math.sqrt(dx * dx + dy * dy + dz * dz), | ||
k = (radiuses[i] - r) * strengths[i] * alpha / r; | ||
node.vx += dx * k; | ||
if (nDim>1) { node.vy += dy * k; } | ||
if (nDim>2) { node.vz += dz * k; } | ||
} | ||
} | ||
function initialize() { | ||
if (!nodes) return; | ||
var i, n = nodes.length; | ||
strengths = new Array(n); | ||
radiuses = new Array(n); | ||
for (i = 0; i < n; ++i) { | ||
radiuses[i] = +radius(nodes[i], i, nodes); | ||
strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes); | ||
} | ||
} | ||
force.initialize = function(initNodes, numDimensions) { | ||
nodes = initNodes; | ||
nDim = numDimensions; | ||
initialize(); | ||
}; | ||
force.strength = function(_) { | ||
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength; | ||
}; | ||
force.radius = function(_) { | ||
return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), initialize(), force) : radius; | ||
}; | ||
force.x = function(_) { | ||
return arguments.length ? (x = +_, force) : x; | ||
}; | ||
force.y = function(_) { | ||
return arguments.length ? (y = +_, force) : y; | ||
}; | ||
force.z = function(_) { | ||
return arguments.length ? (z = +_, force) : z; | ||
}; | ||
return force; | ||
}; | ||
var x$2 = function(x) { | ||
@@ -742,2 +808,3 @@ var strength = constant(0.1), | ||
exports.forceManyBody = manyBody; | ||
exports.forceRadial = radial; | ||
exports.forceSimulation = simulation; | ||
@@ -744,0 +811,0 @@ exports.forceX = x$2; |
@@ -1,2 +0,2 @@ | ||
// https://github.com/vasturiano/d3-force-3d Version 1.0.7. Copyright 2017 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 n.x+n.vx}function a(n){return n.y+n.vy}function c(n){return n.z+n.vz}function l(n){return n.index}function h(n,t){var e=n.get(t);if(!e)throw new Error("missing: "+t);return e}function v(n){return n.x}function y(n){return n.y}function d(n){return n.z}var s=function(n,t,e){function r(){var r,u,o=i.length,f=0,a=0,c=0;for(r=0;r<o;++r)u=i[r],f+=u.x||0,a+=u.y||0,c+=u.z||0;for(f=f/o-n,a=a/o-t,c=c/o-e,r=0;r<o;++r)u=i[r],f&&(u.x-=f),a&&(u.y-=a),c&&(u.z-=c)}var i;return null==n&&(n=0),null==t&&(t=0),null==e&&(e=0),r.initialize=function(n){i=n},r.x=function(t){return arguments.length?(n=+t,r):n},r.y=function(n){return arguments.length?(t=+n,r):t},r.z=function(n){return arguments.length?(e=+n,r):e},r},g=function(n){return function(){return n}},x=function(){return 1e-6*(Math.random()-.5)},z=function(n){function i(){function n(n,t,e,r,i,u,o){var f=[t,e,r,i,u,o],a=f[0],c=f[1],l=f[2],v=f[h],d=f[h+1],m=f[h+2],w=n.data,N=n.r,A=M+N;if(!w)return a>g+A||v<g-A||h>1&&(c>z+A||d<z-A)||h>2&&(l>p+A||m<p-A);if(w.index>s.index){var b=g-w.x-w.vx,k=h>1?z-w.y-w.vy:0,j=h>2?p-w.z-w.vz:0,D=b*b+k*k+j*j;D<A*A&&(0===b&&(b=x(),D+=b*b),h>1&&0===k&&(k=x(),D+=k*k),h>2&&0===j&&(j=x(),D+=j*j),D=(A-(D=Math.sqrt(D)))/D*y,s.vx+=(b*=D)*(A=(N*=N)/(q+N)),h>1&&(s.vy+=(k*=D)*A),h>2&&(s.vz+=(j*=D)*A),w.vx-=b*(A=1-A),h>1&&(w.vy-=k*A),h>2&&(w.vz-=j*A))}}for(var i,o,s,g,z,p,M,q,m=l.length,w=0;w<d;++w)for(o=(1===h?t.binarytree(l,f):2===h?e.quadtree(l,f,a):3===h?r.octree(l,f,a,c):null).visitAfter(u),i=0;i<m;++i)s=l[i],M=v[s.index],q=M*M,g=s.x+s.vx,h>1&&(z=s.y+s.vy),h>2&&(p=s.z+s.vz),o.visit(n)}function u(n){if(n.data)return n.r=v[n.data.index];for(var t=n.r=0;t<Math.pow(2,h);++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}function o(){if(l){var t,e,r=l.length;for(v=new Array(r),t=0;t<r;++t)e=l[t],v[e.index]=+n(e,t,l)}}var l,h,v,y=1,d=1;return"function"!=typeof n&&(n=g(null==n?1:+n)),i.initialize=function(n,t){l=n,h=t,o()},i.iterations=function(n){return arguments.length?(d=+n,i):d},i.strength=function(n){return arguments.length?(y=+n,i):y},i.radius=function(t){return arguments.length?(n="function"==typeof t?t:g(+t),o(),i):n},i},p=function(n){function t(n){return 1/Math.min(y[n.source.index],y[n.target.index])}function e(t){for(var e=0,r=n.length;e<M;++e)for(var i,u,o,c,l,h=0,y=0,s=0,g=0;h<r;++h)i=n[h],u=i.source,o=i.target,y=o.x+o.vx-u.x-u.vx||x(),v>1&&(s=o.y+o.vy-u.y-u.vy||x()),v>2&&(g=o.z+o.vz-u.z-u.vz||x()),c=Math.sqrt(y*y+s*s+g*g),c=(c-a[h])/c*t*f[h],y*=c,s*=c,g*=c,o.vx-=y*(l=d[h]),v>1&&(o.vy-=s*l),v>2&&(o.vz-=g*l),u.vx+=y*(l=1-l),v>1&&(u.vy+=s*l),v>2&&(u.vz+=g*l)}function r(){if(c){var t,e,r=c.length,l=n.length,v=i.map(c,s);for(t=0,y=new Array(r);t<l;++t)e=n[t],e.index=t,"object"!=typeof e.source&&(e.source=h(v,e.source)),"object"!=typeof e.target&&(e.target=h(v,e.target)),y[e.source.index]=(y[e.source.index]||0)+1,y[e.target.index]=(y[e.target.index]||0)+1;for(t=0,d=new Array(l);t<l;++t)e=n[t],d[t]=y[e.source.index]/(y[e.source.index]+y[e.target.index]);f=new Array(l),u(),a=new Array(l),o()}}function u(){if(c)for(var t=0,e=n.length;t<e;++t)f[t]=+z(n[t],t,n)}function o(){if(c)for(var t=0,e=n.length;t<e;++t)a[t]=+p(n[t],t,n)}var f,a,c,v,y,d,s=l,z=t,p=g(30),M=1;return null==n&&(n=[]),e.initialize=function(n,t){c=n,v=t,r()},e.links=function(t){return arguments.length?(n=t,r(),e):n},e.id=function(n){return arguments.length?(s=n,e):s},e.iterations=function(n){return arguments.length?(M=+n,e):M},e.strength=function(n){return arguments.length?(z="function"==typeof n?n:g(+n),u(),e):z},e.distance=function(n){return arguments.length?(p="function"==typeof n?n:g(+n),o(),e):p},e},M=10,q=Math.PI*(3-Math.sqrt(5)),m=Math.PI/24,w=function(n,t){function e(){r(),z.call("tick",c),h<v&&(x.stop(),z.call("end",c))}function r(){var t,e,r=n.length;for(h+=(d-h)*y,g.each(function(n){n(h)}),t=0;t<r;++t)e=n[t],null==e.fx?e.x+=e.vx*=s:(e.x=e.fx,e.vx=0),l>1&&(null==e.fy?e.y+=e.vy*=s:(e.y=e.fy,e.vy=0)),l>2&&(null==e.fz?e.z+=e.vz*=s:(e.z=e.fz,e.vz=0))}function f(){for(var t,e=0,r=n.length;e<r;++e){if(t=n[e],t.index=e,isNaN(t.x)||l>1&&isNaN(t.y)||l>2&&isNaN(t.z)){var i=M*(l>2?Math.cbrt(e):l>1?Math.sqrt(e):e),u=e*q,o=e*m;t.x=i*(l>1?Math.cos(u):1),l>1&&(t.y=i*Math.sin(u)),l>2&&(t.z=i*Math.sin(o))}(isNaN(t.vx)||l>1&&isNaN(t.vy)||l>2&&isNaN(t.vz))&&(t.vx=0,l>1&&(t.vy=0),l>2&&(t.vz=0))}}function a(t){return t.initialize&&t.initialize(n,l),t}t=t||2;var c,l=Math.min(3,Math.max(1,Math.round(t))),h=1,v=.001,y=1-Math.pow(v,1/300),d=0,s=.6,g=i.map(),x=o.timer(e),z=u.dispatch("tick","end");return null==n&&(n=[]),f(),c={tick:r,restart:function(){return x.restart(e),c},stop:function(){return x.stop(),c},numDimensions:function(n){return arguments.length?(l=Math.min(3,Math.max(1,Math.round(n))),g.each(a),c):l},nodes:function(t){return arguments.length?(n=t,f(),g.each(a),c):n},alpha:function(n){return arguments.length?(h=+n,c):h},alphaMin:function(n){return arguments.length?(v=+n,c):v},alphaDecay:function(n){return arguments.length?(y=+n,c):+y},alphaTarget:function(n){return arguments.length?(d=+n,c):d},velocityDecay:function(n){return arguments.length?(s=1-n,c):1-s},force:function(n,t){return arguments.length>1?(null==t?g.remove(n):g.set(n,a(t)),c):g.get(n)},find:function(){var t,e,r,i,u,o,f=Array.prototype.slice.call(arguments),a=f.shift()||0,c=(l>1?f.shift():null)||0,h=(l>2?f.shift():null)||0,v=f.shift()||1/0,y=0,d=n.length;for(v*=v,y=0;y<d;++y)u=n[y],t=a-u.x,e=c-(u.y||0),r=h-(u.z||0),(i=t*t+e*e+r*r)<v&&(o=u,v=i);return o},on:function(n,t){return arguments.length>1?(z.on(n,t),c):z.on(n)}}},N=function(){function n(n){var i,h=f.length,s=(1===a?t.binarytree(f,v):2===a?e.quadtree(f,v,y):3===a?r.octree(f,v,y,d):null).visitAfter(u);for(l=n,i=0;i<h;++i)c=f[i],s.visit(o)}function i(){if(f){var n,t,e=f.length;for(h=new Array(e),n=0;n<e;++n)t=f[n],h[t.index]=+s(t,n,f)}}function u(n){var t,e,r,i,u,o,f=0;if(n.length){for(r=i=u=o=0;o<4;++o)(t=n[o])&&(e=t.value)&&(f+=e,r+=e*(t.x||0),i+=e*(t.y||0),u+=e*(t.z||0));n.x=r/f,a>1&&(n.y=i/f),a>2&&(n.z=u/f)}else{t=n,t.x=t.data.x,a>1&&(t.y=t.data.y),a>2&&(t.z=t.data.z);do{f+=h[t.data.index]}while(t=t.next)}n.value=f}function o(n,t,e,r,i){if(!n.value)return!0;var u=[e,r,i][a-1],o=n.x-c.x,f=a>1?n.y-c.y:0,v=a>2?n.z-c.z:0,y=u-t,d=o*o+f*f+v*v;if(y*y/M<d)return d<p&&(0===o&&(o=x(),d+=o*o),a>1&&0===f&&(f=x(),d+=f*f),a>2&&0===v&&(v=x(),d+=v*v),d<z&&(d=Math.sqrt(z*d)),c.vx+=o*n.value*l/d,a>1&&(c.vy+=f*n.value*l/d),a>2&&(c.vz+=v*n.value*l/d)),!0;if(!(n.length||d>=p)){(n.data!==c||n.next)&&(0===o&&(o=x(),d+=o*o),a>1&&0===f&&(f=x(),d+=f*f),a>2&&0===v&&(v=x(),d+=v*v),d<z&&(d=Math.sqrt(z*d)));do{n.data!==c&&(y=h[n.data.index]*l/d,c.vx+=o*y,a>1&&(c.vy+=f*y),a>2&&(c.vz+=v*y))}while(n=n.next)}}var f,a,c,l,h,s=g(-30),z=1,p=1/0,M=.81;return n.initialize=function(n,t){f=n,a=t,i()},n.strength=function(t){return arguments.length?(s="function"==typeof t?t:g(+t),i(),n):s},n.distanceMin=function(t){return arguments.length?(z=t*t,n):Math.sqrt(z)},n.distanceMax=function(t){return arguments.length?(p=t*t,n):Math.sqrt(p)},n.theta=function(t){return arguments.length?(M=t*t,n):Math.sqrt(M)},n},A=function(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:+o(r[t],t,r)}}var r,i,u,o=g(.1);return"function"!=typeof n&&(n=g(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:g(+n),e(),t):o},t.x=function(r){return arguments.length?(n="function"==typeof r?r:g(+r),e(),t):n},t},b=function(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:+o(r[t],t,r)}}var r,i,u,o=g(.1);return"function"!=typeof n&&(n=g(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:g(+n),e(),t):o},t.y=function(r){return arguments.length?(n="function"==typeof r?r:g(+r),e(),t):n},t},k=function(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vz+=(u[e]-t.z)*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:+o(r[t],t,r)}}var r,i,u,o=g(.1);return"function"!=typeof n&&(n=g(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:g(+n),e(),t):o},t.z=function(r){return arguments.length?(n="function"==typeof r?r:g(+r),e(),t):n},t};n.forceCenter=s,n.forceCollide=z,n.forceLink=p,n.forceManyBody=N,n.forceSimulation=w,n.forceX=A,n.forceY=b,n.forceZ=k,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
// https://github.com/vasturiano/d3-force-3d Version 1.1.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-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";var f=function(n){return function(){return n}},a=function(){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}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,e){var r;null==n&&(n=0),null==t&&(t=0),null==e&&(e=0);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 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"!=typeof n&&(n=f(null==n?1:+n));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&&(b=a(),D+=b*b),u>1&&0===k&&(k=a(),D+=k*k),u>2&&0===j&&(j=a(),D+=j*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 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;null==n&&(n=[]);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 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 x(f){var a,c=n.length,l=(1===i?t.binarytree(n,d):2===i?e.quadtree(n,d,s):3===i?r.octree(n,d,s,g):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&&(d=a(),z+=d*d),i>1&&0===s&&(s=a(),z+=s*s),i>2&&0===g&&(g=a(),z+=g*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&&(d=a(),z+=d*d),i>1&&0===s&&(s=a(),z+=s*s),i>2&&0===g&&(g=a(),z+=g*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 x.initialize=function(t,e){n=t,i=e,z()},x.strength=function(n){return arguments.length?(l="function"==typeof n?n:f(+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,e,r){var i,u,o,a,c=f(.1);"function"!=typeof n&&(n=f(+n)),null==t&&(t=0),null==e&&(e=0),null==r&&(r=0);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 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(3,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(s),d=u.dispatch("tick","end");null==n&&(n=[]);function s(){g(),d.call("tick",e),f<a&&(y.stop(),d.call("end",e))}function g(){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 M(){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=x*(r>2?Math.cbrt(e):r>1?Math.sqrt(e):e),o=e*z,f=e*p;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 q(t){return t.initialize&&t.initialize(n,r),t}return M(),e={tick:g,restart:function(){return y.restart(s),e},stop:function(){return y.stop(),e},numDimensions:function(n){return arguments.length?(r=Math.min(3,Math.max(1,Math.round(n))),v.each(q),e):r},nodes:function(t){return arguments.length?(n=t,M(),v.each(q),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,q(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?(d.on(n,t),e):d.on(n)}}},n.forceX=function(n){var t,e,r,i=f(.1);"function"!=typeof n&&(n=f(null==n?0:+n));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 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"!=typeof n&&(n=f(null==n?0:+n));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 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"!=typeof n&&(n=f(null==n?0:+n));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 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})}); |
@@ -5,2 +5,3 @@ export {default as forceCenter} from "./src/center"; | ||
export {default as forceManyBody} from "./src/manyBody"; | ||
export {default as forceRadial} from "./src/radial"; | ||
export {default as forceSimulation} from "./src/simulation"; | ||
@@ -7,0 +8,0 @@ export {default as forceX} from "./src/x"; |
{ | ||
"name": "d3-force-3d", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Force-directed graph layout in 1D, 2D or 3D using velocity Verlet integration.", | ||
@@ -30,7 +30,5 @@ "keywords": [ | ||
"scripts": { | ||
"build": "rm -rf build && mkdir build && rollup -c --banner \"$(preamble)\" -g d3-collection:d3,d3-dispatch:d3,d3-binarytree:d3,d3-quadtree:d3,d3-octree:d3,d3-timer:d3 -f umd -n d3 -o build/d3-force-3d.js -- index.js", | ||
"bundle": "rollup -c --banner \"$(preamble)\" -f umd -n d3_force -o build/d3-force-3d.bundle.js -- index.js", | ||
"pretest": "npm run build", | ||
"pretest": "rm -rf build && mkdir build && rollup -c --banner \"$(preamble)\"", | ||
"test": "tape 'test/**/*-test.js' && eslint index.js src", | ||
"prepublish": "npm run test && npm run bundle && uglifyjs --preamble \"$(preamble)\" build/d3-force-3d.js -c -m -o build/d3-force-3d.min.js && uglifyjs --preamble \"$(preamble)\" build/d3-force-3d.bundle.js -c -m -o build/d3-force-3d.bundle.min.js" | ||
"prepare": "npm run test && uglifyjs -b beautify=false,preamble=\"'$(preamble)'\" build/d3-force-3d.js -c -m -o build/d3-force-3d.min.js" | ||
}, | ||
@@ -46,9 +44,9 @@ "dependencies": { | ||
"devDependencies": { | ||
"eslint": "3", | ||
"package-preamble": "0.0", | ||
"rollup": "0.41", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"eslint": "4", | ||
"package-preamble": "0.1", | ||
"rollup": "0.50", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"tape": "4", | ||
"uglify-js": "^2.8.11" | ||
"uglify-js": "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 version [1.0.6](https://github.com/d3/d3-force/tree/v1.0.6) of [d3-force](https://github.com/d3/d3-force), and should just work as a drop-in replacement d3 module. | ||
[![NPM](https://nodei.co/npm/d3-force-3d.png?compact=true)](https://nodei.co/npm/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.0](https://github.com/d3/d3-force/tree/v1.1.0)), 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. | ||
@@ -129,2 +131,8 @@ | ||
To remove the force with the given *name*, pass null as the *force*. For example, to remove the charge force: | ||
```js | ||
simulation.force("charge", null); | ||
``` | ||
<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#L143 "Source") | ||
@@ -185,3 +193,3 @@ | ||
<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>[, <i>y</i>[, <i>y</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>]]]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/center.js#L1 "Source") | ||
@@ -250,3 +258,3 @@ 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⟩. | ||
For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references; see [*link*.id](#link_id). | ||
For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references; see [*link*.id](#link_id). When the link force is [initialized](#force_initialize) (or re-initialized, as when the nodes or links change), any *link*.source or *link*.target property which is *not* an object is replaced by an object reference to the corresponding *node* with the given identifier. | ||
@@ -375,3 +383,3 @@ If the specified array of *links* is modified, such as when links are added to or removed from the simulation, this method must be called again with the new (or changed) array to notify the force of the change; the force does not make a defensive copy of the specified array. | ||
The [*x*](#forceX)-, [*y*](#forceY)- and [*z*](#forceZ)-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. | ||
The [*x*](#forceX)-, [*y*](#forceY)- and [*z*](#forceZ)-positioning forces push nodes towards a desired position along the given dimension with a configurable strength. The [*radial*](#forceRadial) force is similar, except it pushes nodes towards the closest point on a given circle/sphere. 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. | ||
@@ -438,3 +446,3 @@ <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="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>]) [<>](https://github.com/vasturiano/d3-force-3d/blob/master/src/z.js "Source") | ||
@@ -468,1 +476,39 @@ 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. | ||
The *z*-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 *z*-coordinate of each node is only recomputed when the force is initialized or when this method is called with a new *z*, and not on every application of the force. | ||
<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") | ||
[<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⟩. | ||
<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") | ||
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: | ||
```js | ||
function strength() { | ||
return 0.1; | ||
} | ||
``` | ||
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") | ||
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. | ||
<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") | ||
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") | ||
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") | ||
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. |
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
const definition = require("./package.json"); | ||
const dependencies = Object.keys(definition.dependencies); | ||
export default { | ||
plugins: [ | ||
nodeResolve({ jsnext: true }) | ||
] | ||
input: "index", | ||
external: dependencies, | ||
output: { | ||
extend: true, | ||
file: `build/${definition.name}.js`, | ||
format: "umd", | ||
globals: dependencies.reduce((p, v) => (p[v] = "d3", p), {}), | ||
name: "d3" | ||
}, | ||
plugins: [ | ||
nodeResolve({ jsnext: true }) | ||
] | ||
}; |
@@ -40,3 +40,3 @@ import constant from "./constant"; | ||
function accumulate(treeNode) { | ||
var strength = 0, q, c, x, y, z, i; | ||
var strength = 0, q, c, weight = 0, x, y, z, i; | ||
@@ -46,9 +46,9 @@ // For internal nodes, accumulate forces from children. | ||
for (x = y = z = i = 0; i < 4; ++i) { | ||
if ((q = treeNode[i]) && (c = q.value)) { | ||
strength += c, x += c * (q.x || 0), y += c * (q.y || 0), z += c * (q.z || 0); | ||
if ((q = treeNode[i]) && (c = Math.abs(q.value))) { | ||
strength += q.value, weight += c, x += c * (q.x || 0), y += c * (q.y || 0), z += c * (q.z || 0); | ||
} | ||
} | ||
treeNode.x = x / strength; | ||
if (nDim > 1) { treeNode.y = y / strength; } | ||
if (nDim > 2) { treeNode.z = z / strength; } | ||
treeNode.x = x / weight; | ||
if (nDim > 1) { treeNode.y = y / weight; } | ||
if (nDim > 2) { treeNode.z = z / weight; } | ||
} | ||
@@ -55,0 +55,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
896543
54254
509
1355