Permalink
Browse files

Better jittering for coincident nodes.

  • Loading branch information...
mbostock committed Apr 28, 2011
1 parent 51b8e02 commit 067959832875993b721a27a322c8944bf5dcd1a3
Showing with 22 additions and 12 deletions.
  1. +1 −1 d3.js
  2. +9 −4 d3.layout.js
  3. +1 −1 d3.layout.min.js
  4. +1 −1 d3.min.js
  5. +1 −1 src/core/core.js
  6. +9 −4 src/layout/force.js
View
2 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.13.3"}; // semver
+(function(){d3 = {version: "1.13.4"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
View
@@ -168,9 +168,9 @@ d3.layout.force = function() {
function repulse(node, kc) {
return function(quad, x1, y1, x2, y2) {
- if (quad.point != node) {
- var dx = (quad.cx - node.x) || Math.random(),
- dy = (quad.cy - node.y) || Math.random(),
+ if (quad.point !== node) {
+ var dx = quad.cx - node.x,
+ dy = quad.cy - node.y,
dn = 1 / Math.sqrt(dx * dx + dy * dy);
/* Barnes-Hut criterion. */
@@ -181,7 +181,7 @@ d3.layout.force = function() {
return true;
}
- if (quad.point) {
+ if (quad.point && isFinite(dn)) {
var k = kc * dn * dn;
node.x += dx * k;
node.y += dy * k;
@@ -476,6 +476,11 @@ function d3_layout_forceAccumulate(quad) {
});
}
if (quad.point) {
+ // jitter internal nodes that are coincident
+ if (!quad.leaf) {
+ quad.point.x += Math.random() - .5;
+ quad.point.y += Math.random() - .5;
+ }
quad.count++;
cx += quad.point.x;
cy += quad.point.y;
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1 +1 @@
-d3 = {version: "1.13.3"}; // semver
+d3 = {version: "1.13.4"}; // semver
View
@@ -16,9 +16,9 @@ d3.layout.force = function() {
function repulse(node, kc) {
return function(quad, x1, y1, x2, y2) {
- if (quad.point != node) {
- var dx = (quad.cx - node.x) || Math.random(),
- dy = (quad.cy - node.y) || Math.random(),
+ if (quad.point !== node) {
+ var dx = quad.cx - node.x,
+ dy = quad.cy - node.y,
dn = 1 / Math.sqrt(dx * dx + dy * dy);
/* Barnes-Hut criterion. */
@@ -29,7 +29,7 @@ d3.layout.force = function() {
return true;
}
- if (quad.point) {
+ if (quad.point && isFinite(dn)) {
var k = kc * dn * dn;
node.x += dx * k;
node.y += dy * k;
@@ -324,6 +324,11 @@ function d3_layout_forceAccumulate(quad) {
});
}
if (quad.point) {
+ // jitter internal nodes that are coincident
+ if (!quad.leaf) {
+ quad.point.x += Math.random() - .5;
+ quad.point.y += Math.random() - .5;
+ }
quad.count++;
cx += quad.point.x;
cy += quad.point.y;

0 comments on commit 0679598

Please sign in to comment.