score:1

Accepted answer

You can chain multiple style or attr calls together (like you have with fill and display in your example) so does this achieve what you're looking for?

path = group.append("svg:path")
  .attr("d", arc)
  .style("fill", function(d) {
    if (d.children)
      return color(d.name);
    else
      return "grey";
  })
  .attr("stroke", function(d) {
    if (d.children)
      return "red";
  })
  .attr("stroke-width", function(d) {
     if (d.children)
       return 2;
     else 
       return 0;
  })
  .attr("display", function(d) {
    return d.depth ? null : "none";
  })
  .each(stash);

Seems like it would be much cleaner to apply a class based on the outcome of d.children though.


Related Query