I'm binding data to a bunch of nodes using d3, and I would like to arrange it so that all of the nodes change dynamically when one of them is clicked on (or some other event). Based on my understanding of d3, I think it should work like this:
var nodes = svg.selectAll(".node")
.data(someData)
.enter()
.append("circle")
.attr("r", 5)
.attr("class", ".node")
.style("fill", "blue")
.on("click", function(d, i) {
svg.selectAll(".node").style("fill", function(e, j) {
if(someCondition(i, j))
return "red";
else
return "green";
});
});
But nothing happens when I click. Even the simpler code:
var nodes = svg.selectAll(".node")
.data(someData)
.enter()
.append("circle")
.attr("r", 5)
.attr("class", ".node")
.style("fill", "blue")
.on("click", function(d, i) {
svg.selectAll(".node").style("fill", "red");
});
(which I expect would turn all of the nodes red when one of them is clicked on) does not work.