Reputation: 165
Is there a way to change color of a node or link directly, instead of iterating on all the nodes or links.
I know the id of the node or link.
node.select("circle").style("fill", function (o) {
if(o.id == source || o.id == target ) {
return PATH_COLOR;
}
return d3.select(this).style("fill");
});
Upvotes: 2
Views: 1878
Reputation: 14589
Apply the styles as shown below. The new fill color will be applied only for the nodes with id source
and id target
.
d3.select("#"+source).style("fill", PATH_COLOR);
d3.select("#"+target).style("fill", PATH_COLOR);
Upvotes: 4
Reputation: 4849
if you know the id of an svg element, then you can directly apply any css to it. Say you have a circle
with the id "one
"
<circle id="one" cx="10" cy="20" r="10"></circle>
Then you can simply do this,
d3.select('#one').style('fill','red');
Upvotes: 1