d3 / d3-selection

Transform the DOM by selecting elements and joining to data.

Home Page:https://d3js.org/d3-selection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable the use of d3.join() without implicit d3.order() call

NeonMika opened this issue · comments

I switched one of my applications from the "old" enter()/merge() pattern to use the "new" join() method.
I really like how concise data binding becomes using this method.
Sadly, only after this move I found out that join() automatically performs order() after the merge of the enter and update selection.

Possible improvement: Since my application relies on preserving the document order, and data array reordering is not really feasable in my case, I would like to ask whether it is possible to add an additional (optional) parameter to the join() method that allows users to specify whether they want to automatically perform order() at the end of the join method. Probably somethink like an options parameter.

An example for this problem can be found here: https://stackoverflow.com/q/71179024/2938364

The problematic line is

return enter && update ? enter.merge(update).order() : update;

ordering is not an implicit byproduct of selection.join, but an explicit part of the feature as mentioned in the documentation and in the unit test: 146af5d

Have you considered applying selection.sort after the join()?

Yes, I read the documentation (after searching for quite some time why the z-ordering problem occurs - first I assumed some problem with my drag code), and yes, probably I used the word "implicit" wrong in this context.

But I do no think that ordering (in join), sorting, and then ordering (in sort) again is the way how this problem should be tackeled.

I think there are use cases where it is not desired that join calls order at the end, and I just think that it would be nice if it was possible to call join with this setting (either by adding a parameter to join or by providing another method similar to join that does not order the selection in the end).

Otherwise, methods such as raise and lower lose their applicability in data-joined visualization, since they will be "overridden" on the next join call.

selection.join is a convenience function. If you don’t want to order, you should call the underlying methods directly yourself. We shouldn’t add options to selection.join.