Skip to content

Commit 286b000

Browse files
committed
check for charge or alpha to be zero before calculating
1 parent 8be42d5 commit 286b000

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/layout/force.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ d3.layout.force = function() {
1818
strengths,
1919
charges;
2020

21-
function repulse(node, kc) {
21+
function repulse(node) {
2222
return function(quad, x1, y1, x2, y2) {
2323
if (quad.point !== node) {
2424
var dx = quad.cx - node.x,
@@ -27,7 +27,7 @@ d3.layout.force = function() {
2727

2828
/* Barnes-Hut criterion. */
2929
if ((x2 - x1) * dn < theta) {
30-
var k = kc * quad.count * dn * dn;
30+
var k = alpha * quad.count * dn * dn;
3131
node.px -= dx * k;
3232
node.py -= dy * k;
3333
return true;
@@ -85,11 +85,11 @@ d3.layout.force = function() {
8585
}
8686

8787
// compute quadtree center of mass and apply charge forces
88-
if (k = alpha) {
88+
if (charge && alpha) {
8989
d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), charges);
9090
i = -1; while (++i < n) {
9191
if (!(o = nodes[i]).fixed) {
92-
q.visit(repulse(o, k));
92+
q.visit(repulse(o));
9393
}
9494
}
9595
}

0 commit comments

Comments
 (0)