Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncertain this contexts. #24

Closed
mbostock opened this issue May 21, 2015 · 0 comments
Closed

Uncertain this contexts. #24

mbostock opened this issue May 21, 2015 · 0 comments

Comments

@mbostock
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant