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

Stash the key used by the previous data-join #292

Open
mbostock opened this issue Oct 14, 2021 · 2 comments
Open

Stash the key used by the previous data-join #292

mbostock opened this issue Oct 14, 2021 · 2 comments

Comments

@mbostock
Copy link
Member

mbostock commented Oct 14, 2021

One of the surprising things about the data join is that you have to recompute a new key for the existing elements. It’d be nice if we stashed the key (if one exists) as node.__key__, similar to how we stash data as node.__data__. That way you’d only need to compute the key for the data, not for the existing elements. This key would only be stashed in the cases where you pass a key function to selection.data.

@mjmdavis
Copy link

mjmdavis commented Oct 21, 2021

On a similar topic, is there an intentional decision behind selection.data() not accepting an object as a key?

When I did:

var clocks = [{position: {x:0,y:0}, minutes: 0, hours:0},...]
selection.data(clocks, d=>d.position)...

I expected the data object to bind to the position object. It however did not. Instead I had to serialise position to a string manually.

https://observablehq.com/d/b0cbdcac16896daf

@mbostock
Copy link
Member Author

@mjmdavis Keys are required to be strings. https://github.com/d3/d3-selection#selection_data

A key function may be specified to control which datum is assigned to which element, replacing the default join-by-index, by computing a string identifier for each datum and element.

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

2 participants