[英]Adding “triangle-up” in d3.js node
I have the following code: 我有以下代码:
var nodeEnter = node.enter().append("svg:g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
.on("click", function(d) { toggle(d); update(d); });
nodeEnter.append("svg:circle")
.attr("r", 1e-6)
.style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; });
nodeEnter.append("svg:text")
.attr("x", function(d) { return d.children || d._children ? -10 : 10; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.text(function(d) {
if (d.size != undefined) {
return d.name + " :: " + d.size + " :: " + d.diff_day;
} else {
return d.name;
}
})
.style("fill-opacity", 1e-6)
.style("font-size", "15px");
nodeEnter.append("svg:path").attr("d", d3.svg.symbol.type("triangle-up").style("fill", "black"));
Now, the problem is that the svg:circle and svg:text are coming fine. 现在,问题在于svg:circle和svg:text正常了。 But the "d3.svg.symbol.type("triangle-up").style("fill", "black"));"
但是“ d3.svg.symbol.type(” triangle-up“)。style(” fill“,” black“)));” doesn't seem to work.
似乎不起作用。 Any help would be appreciated...
任何帮助,将不胜感激...
You cannot set the attribute properties on the symbol you create itself like this: 您不能在自己创建的符号上设置属性属性,如下所示:
nodeEnter.append("svg:path") // Wrong.
.attr("d", d3.svg.symbol.type("triangle-up").style("fill", "black"));
You have to first set the d
attribute, and then set the style fill
on the path
: 您必须首先设置
d
属性, 然后在path
上设置样式fill
:
nodeEnter.append("svg:path") // Fixed.
.attr("d", d3.svg.symbol().type("triangle-up"))
.style("fill", "black");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.