Q:

Existing elements in D3 SVG chart aren't updated - all is regarded as exit() and enter() sets

I'm playing around with a graph charting 13 g-elements with a circle each. Then I execute the following in the console. Verification gives me that copy contains 13 elements, shorty 7 and longy 20. Nothing on the screen changes, just yet, of course.
var gees = d3.select("#graph2").selectAll("g");
var copy = gees.data();
var shorty = copy.slice(0,7)
var longy = shorty.concat(copy);

Now, that I execute the following, I expected a difference in the data set but not the way I see. If we start off with 13 elements and subtract 6 (as is the case with shorty), the enter() set should be 0 and the exit() set should be 6, the way I figure. However, my console proudly shows that it's 7 and 13. Equivalently, if we start off with 13 elements and add 7 (as is the case with longy), the enter() set should be 7 and the exit() set should be 0, as far I can understand. Yet again, my console surprises me claiming that it's 20 and 13.
gees.data(shorty).enter()
gees.data(shorty).exit()

[Array[7]]
  [Array[13]]

gees.data(longy).enter()
gees.data(longy).exit()

[Array[20]]
  [Array[13]]

The conclusion I'm drawing is that all the pre-exisint elements are discarded (hence put in the exit() set) and the added data is regarded as a brand new bunch (hence regarded as enter() set). I can live with that but all the articles I've read stated that every and each operation on sets should be relying on:

updating stuff in data()
appending stuff in enter()
removing stuff in exit()

A:

The sets are of correct sizes. You're just not looking at the sizes. You got tricked by the data presentation of your console. Running these commands should clear the confusion. I've done that on circles not gs but it the same logic.
mySet.data(shorterSet).exit().size()

6

mySet.data(shorterSet).enter().size()

0

mySet.data(longerSet).exit().size()

0

mySet.data(longerSet).enter().size()

7

