mbostock/d3 — Issue #396: d3.layout.cluster() with one node will divide by zero
Author: cnojima-ra
Created: 2011-12-05 17:20:26+00:00
State: open

I'm writing a simulation where I'm dynamically adding nodes to cluster layout. If there is only one node in the cluster layout, the Y value will turn into NaN because of the code:

line 1394: d3.layout.js

d3_layout_treeVisitAfter(root, function(node) {
node.x = (node.x - x0) / (x1 - x0) * size[0];
node.y = (1 - node.y / root.y) * size[1];
});

in this case node == root, and root.y == 0. which makes node.y -> NaN. to recreate just edit the examples/cluster/cluster.js

d3.json("../data/flare.json", function(json) {
json = {name:"TEST"}; // new line
var nodes = cluster.nodes(json);