I create a group with data values:
var group = svg.append("g");
group.data([{color : "green", opacity: 0.3 }]);
If I want to update these values, do I need to set a new data array?
group.data([{color : "blue", opacity: 0.3 }]);
Or can I somehow iterate and update the values inside the group, like:
group.data.foreach(d, function() { return d.color = "blue"; })
or
group.data.foreach(d, function() { return d.opacity += 0.5; })
My use case is that I have a group with a rectangle and a circle. And the group has data in it.
var group = svg.append("g");
group.data([{color : "green", opacity: 0.3 }]);
var line = group.append("rect");
line.attr("x", self.xWorldToGraph(xx) - self.lineWidth / 2)
.attr("y", self.yWorldToGraph(yy))
.attr("width", self.lineWidth)
.attr("height", height)
.style("stroke", function(d) { return d.color; })
.style('stroke-opacity', function(d) { return d.opacity; })
group.append("circle")
.attr("cx", self.xWorldToGraph(xx))
.attr("cy", self.yWorldToGraph(yy))
.attr("r", 50)
.style("stroke", function(d) { return d.color; })
.style('stroke-opacity', function(d) { return d.opacity; })
Now I want to update the group color so the circle and rectangle also change color.