Peter Qiu
Peter Qiu

Reputation: 942

What does D3's "empty" selection do?

I'm fairly new at D3 and recently saw this piece of code while someone was creating a transition: d3.select({}) in d3.select({}).transition() etc. This seems to be doing the same thing as d3.select([]). In the console, it showed up as an array, but I'm still unsure what it does. Any help would be appreciated, thank you!

Upvotes: 4

Views: 1161

Answers (1)

Mark
Mark

Reputation: 108512

The only place I've seen this is here. Now usually you would d3.select the object you want to run the transition on. But in the linked example, Bostock is not operating on svg composed of different DOM objects to manipulate but instead on a canvas that has to be wiped and redrawn for each step in the transition. So, d3.select({}).transition(), simply becomes an easy way to fire up a generic transition he can work with. You should note that something has to be selected to create a transition, just doing d3.select().transition() won't work and an empty object (or an empty array) allows it to work.

Upvotes: 5

Related Questions