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

Preserve order of elements when multiselect is enabled #1153

Open
tillias opened this issue Oct 30, 2020 · 2 comments
Open

Preserve order of elements when multiselect is enabled #1153

tillias opened this issue Oct 30, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@tillias
Copy link

tillias commented Oct 30, 2020

Hello folks,

At the moment if multiselect option is active, e.g.:

      interaction: {
        multiselect: true,
      },

then the selection order is not preserved. Selected nodes (ids) are always sorted. It would be nice to have possibility disabling sorting.

Example how it is now:

Use Case 1: Click nodes 1,2,3 -> selection: 1,2,3
Use Case 2: Click nodes 3,1,2 -> selection: 1,2,3

Selection order

Nice to have:

Use Case 1: Click nodes 1,2,3 -> selection: 1,2,3
Use Case 2: Click nodes 3,1,2 -> selection: 3,2,1

@Thomaash
Copy link
Member

Thomaash commented Nov 3, 2020

Hi @tillias,

the selection is in no order (the order is dependent on browsers, polyfills etc.). I see how this could be useful but I'm not really in favor of keeping the selection sorted. There are quite a few situations where there is no intuitive correct order or the correct order depends on specific use case; for example multiple nodes and/or edges can be selected at the same time (What order should it be then?), unselected and reselected (This is ignored now, should it change the order?) etc. It wouldn't really work well for anything other than these very simple cases.

However, for your specific and very simple usecase, it should be quite easy to just listen to the events and react only when there is one node already selected and one new node added to the selection.

Alternatively, and I consider this much better option, we could keep selection timestamp for each item or maybe keep incrementing sequential number for every selection and add it to each newly selected item. The big advantage here would be that it would be obvious what was selected together in one go and what was selected sequentially, providing better support for more advanced usecases.

@tillias
Copy link
Author

tillias commented Nov 3, 2020

Yes, timestamp would be very nice option 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants