javascript - Finding score of node based on average of child node scores for d3 packed circle viz -
i'm trying build view based on zoomable packed circle visualization per http://bl.ocks.org/mbostock/7607535 , i'm trying have each container parent's color based on average of child nodes' scores.
in above, think ahve figured need change .style in:
var circle = svg.selectall("circle") .data(nodes) .enter().append("circle") .attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; }) .style("fill", function(d) { return d.children ? color(d.depth) : null; }) .on("click", function(d) { if (focus !== d) zoom(d), d3.event.stoppropagation(); });
my problem i'm not overly familiar whether such recursion might achieved in d3. i'd prefer in-line coding not best. suspect might need write separate function , call within block, akin to:
.style("fill", function(d) { return d.children ? color(calculatingfn(d)) : d.score; })
i guess question is: should calculatingfn(d) (or other more elegant solution)?
any appreciated.
Comments
Post a Comment