In the d3js tree sample, I tried to move the call to update outside the d3.json function. When I did that, I get :
TypeError: d is undefined
Here is the code (the function here is slightly different from the link to the example). Notice that I moved the call to update outside the d3.json function. Note that root is a global variable.
d3.json("../data/flare.json", function(json) {
root = json;
root.x0 = height / 2;
root.y0 = 0;
function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
}
root.children.forEach(collapse);
// move this out
// update(root);
});
update(root);
function update(source) {.....