Giving non-leaf nodes data/values in protovis
My data looks similar to this:
var root = {
node1: {
node2: 4,
node3: 2
},
node4: {
node5: 3
}
};
Which is similar to how they sug开发者_如何转开发gest the data be laid out for tree structures in their examples. My question is this: how would I give values to node1 and node4?
Thanks.
Looks like an old question, but here's an answer anyway. Check out http://vis.stanford.edu/protovis/ex/indent.html Most notably,
var root = pv.dom(flare)
.root("flare")
.sort(function(a, b) pv.naturalOrder(a.nodeName, b.nodeName));
/* Recursively compute the package sizes. */
root.visitAfter(function(n) {
if (n.firstChild) {
n.nodeValue = pv.sum(n.childNodes, function(n) n.nodeValue);
}
});
They load in their input using pv.dom(obj), then just recursively compute sums. In more general terms, you could use that interface to assign whatever values you want within the function you pass to visitAfter
精彩评论