-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Hello,
I'm trying to wrap my head around the insert method. In the world of vanilla D3, we typically append elements within the enter selection:
d3.select("body").selectAll("p")
.data([4, 8, 15, 16, 23, 42])
.enter().append("p")
.text(function(d) { return "I’m number " + d + "!"; });In d3.chart, we'd do something like this:
d3.chart('PChart', g, {
...
insert: function() {
return this.append('p');
},
events: {
'enter': function() {
this.text(function(d) { return "I’m number " + d + "!"; });
}
}
});My question is, why not just append the elements in the enter lifecycle event? I may not be reading it right, but isn't this what the relevant code is essentially doing?
The only info I've been able to find about this was in Irene's blog post:
insertmethod - the method that creates the actual data-bound elements and sets any attributes that don’t have to do with the data. The reason we don’t do that here is because we want to account for our data potentially changing and thus want to delegate setting any data-driven attributes to the lifecycle events.
But isn't appending elements a data-driven operation, and therefore doesn't it belong in the enter lifecycle event?
I think I'm just missing something here - would love some clarification.
Thanks!