如何最简单地更新已经绘制的节点的样式?在这种情况下,布局已经创建完成,所有的链接、节点都是完美的。然后,将一个数组传递给指令,如果节点名称在该数组中,我想更改它的颜色。
例如:
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";
});