Open mbostock opened 2 years ago
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.
@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.
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.