我有这段代码:
path = group.append("svg:path")
.attr("d", arc)
.style("fill", function(d) {
if (d.children)
return color(d.name)
else
return "grey"
})
.attr("display", function(d) {
return d.depth ? null : "none";
})
.each(stash);
但是我想不仅要在样式中添加“填充”,还要添加一个笔画,特别是这段代码:
.style("fill", function(d) {
if (d.children)
return color(d.name)
else
return "grey"
})
有人可以告诉我如何为此添加笔画吗?我无法在CSS中执行此操作,因为它需要特定于此特定路径,并且它没有id或类。
答案 0 :(得分:1)
您可以将多个style
或attr
个电话组合在一起(就像您的示例中的fill
和display
一样)这样做可以达到您的目的寻找?
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);
似乎根据d.children
的结果应用类会更清晰。