更新已经绘制的节点样式的最简单方法是什么?在这种情况下,将创建具有所有链接,节点的布局-完美。然后将数组传递给指令,如果节点名称在该数组中,我想更改其颜色。
例:
var names = ["tom","john"]; // this data comes in...
d3.select("node").select("circle").style("fill", function (d) {
// I check if the node name is in array, if so change its colour to green.
if (names.indexOf(d.name) > -1) {
return "green";
} else
return "red";
});
尝试使用选择 filter
d3.selectAll("node").selectAll("circle")
.filter(function(d){
return names.indexOf(d.name) < 0;
})
.style("fill", "red");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句