You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the normal case, say selection.attr, the this context is the DOM node. The arguments are the datum (d) and index (i), followed by the parent datum and index, and so forth.
But what about for selection.data?
The value function—that returns an array of data—is invoked once per group, not once per node. So the this context could conceivably be (1) the parent node of the group or (2) the group itself (an array of nodes). The latter is what D3 3.x and below do, which arguably has the nice property that you can compute some dynamic data from the nodes. But really in that case, wouldn’t it make more sense to use selection.datum and just bind the data directly?
The key function has a similar issue, except keys are necessarily computed after the data values, so there’s another option (3) the values array (which is what D3 3.x does). But I can’t think of any time where I’ve depended on this behavior, so it probably makes more sense to switch both of them to the group’s parent node.
The text was updated successfully, but these errors were encountered:
For the normal case, say selection.attr, the
this
context is the DOM node. The arguments are the datum (d) and index (i), followed by the parent datum and index, and so forth.But what about for selection.data?
The value function—that returns an array of data—is invoked once per group, not once per node. So the
this
context could conceivably be (1) the parent node of the group or (2) the group itself (an array of nodes). The latter is what D3 3.x and below do, which arguably has the nice property that you can compute some dynamic data from the nodes. But really in that case, wouldn’t it make more sense to use selection.datum and just bind the data directly?The key function has a similar issue, except keys are necessarily computed after the data values, so there’s another option (3) the values array (which is what D3 3.x does). But I can’t think of any time where I’ve depended on this behavior, so it probably makes more sense to switch both of them to the group’s parent node.
The text was updated successfully, but these errors were encountered: