Reputation: 11
Creating a new selection, and supplying the data works:
var svg = d3.select("body").append("svg");
var _nodeSelection = svg.insert("g").selectAll(".node");
var _nodeData = _nodeSelection.data(_nodes);
_nodeData
.enter().append("text")
.attr("class", "node");
After some callback the attributes to all the existing elements change, This works!
_nodeData.attr("class", "update");
In another callback I supply new data to the selection, and try to update the existing selection before calling the Enter / Exit routine.
// No longer works after supplying new data
var _nodeData = _nodeSelection.data(_nodes);
// Does not work anymore:
_nodeData.attr("class", "update2");
This no longer works, as in the class does NOT get updated to update2. This is surprising to me as according to this example this should work.
Consequently, calling .Enter() on the new data selection creates a new set of elements in the sample place as the old elements, so that all the svg elements are duplicated.
What am I doing wrong?
Upvotes: 0
Views: 42
Reputation: 11
You always have to reselect explicitly using selectall
. D3 does an explicit internal binding on a selection when supplying the data, and this cannot be applied on the same selection twice.
Upvotes: 1