Skip to content

Include info from all multi-selection polygons in plotly_selected event data #5504

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

Closed
etpinard opened this issue Feb 15, 2021 · 8 comments
Closed

Comments

@etpinard
Copy link
Contributor

etpinard commented Feb 15, 2021

Hi, I hope all of you are doing well! I'm glad to see @archmoj's leading the v2 push 🚀


I'm currently rewriting an internal app using Dash.jl and I came across a situation where (I think) common dash callback logic could be greatly simplified with a small plotly.js tweak.

From https://jsbin.com/piveyuniso/edit?html,js,output, we can see that in the plotly_selected event data after a multi-selection interaction, the range.x / range.y coordinates (only!) correspond to the most recent selection.

Peek 2021-02-15 11-54

In situations where we need to consider all the selected regions (i.e. not just the most recent one), we need to accumulate the coordinates from the individual plotly_selected events. This is of course very much doable in dash, but also a little annoying.

Probably the easiest and least-invasive solution would be to add a new plotly_selected event data field named e.g. rangeMulti (and lassoPointsMulti for dragmode: 'lasso') so that:

gd.on('plotly_selected, d => 
  d.rangeMulti.x // [[x00, x01], [x10, x11], ...]
  d.rangeMulti.y // [[y00, y01], [y10, y11], ...]
  // and for 'lasso'
  d.lassoPointsMulti.x // [[Xs of first lasso selection], [Xs of 2nd ...], ...]
  d.lassoPointsMulti.y // [[Ys of first lasso selection], [Ys of 2nd ...], ...]
)

Let me know if this solution makes sense! I can happily open a PR that implements it.

Cheers!

@nicolaskruchten
Copy link
Contributor

Nice to hear from you! This seems like a good solution :)

@archmoj
Copy link
Contributor

archmoj commented Feb 16, 2021

@etpinard thanks very much for the note and opening the issue to reach 1K-issue milestone : )

1K-issues

Hope you are doing well and we can't wait to have your PR up!

Whereas with selections I think one could add or remove point to/from selection; I was wondering how your multi suggestion could handle the case of removal? Can't we just call the current behaviour a bug instead?

@nicolaskruchten
Copy link
Contributor

@etpinard are you still planning on opening a PR for this?

@etpinard
Copy link
Contributor Author

When trying to implement this, I realised things were trickier than expected.

At first, I thought this ticket would "only" require us to write a version of this fillRangeItems statement

fillRangeItems(eventData, currentPolygon, filterPoly);

with mergedPolygons instead of currentPolygon. While making this work would be possible and not too difficult, there are a few issues:

  • mergedPolygons contains the merged polygons x/y coordinates, not the set of selected rectangles (or ranges). For example, after

Peek 2021-03-11 14-54

mergedPolygons contains the x/y coordinates of 8 vertices, not two [[x0,y0], [x1,x2]] sets corresponding to two selected rectangles.

So, if we choose to use mergePolygons data in the selection event data, we should probably not name the new event data key rangeMulti. Something like polygon.(x|y) would be better.

  • If we want to include the set of selected ranges in the event data, we'll need to a new to keep track of them separately in a new dragOptions field.

@archmoj
Copy link
Contributor

archmoj commented Mar 11, 2021

There might be cases to end up with multiple polygons too e.g. if one deselect areas from inside a selection.

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Mar 25, 2021

It seems to me that in cases of multiple selections, we should provide as much information as possible to downstream Dash devs:

  • range and lassoPoints should contain x2, y2 etc for additional box selections
  • range and lassoPoints should contain sign, sign2 etc to indicate inclusion/exclusion
  • a new selectionOrder key should contain a list of range, lasso to be able to reconstruct the selection order that the user used
  • a mergedPolygons key should contain a list of disjoint merged polygons if folks want to use that instead of reconstructing either shapes or intersection calculations from the above

@archmoj
Copy link
Contributor

archmoj commented Jul 14, 2022

Dear @etpinard,
Thanks very much for the note on #6243.
In the event data after v2.13.0, points include all the selected points on all subplots. The range value still includes the last selection. But all the selections inputs are also provided in the plotly_selected event data which can include multi-region path strings.
Do you think this is enough information to work with?

@gvwilson
Copy link
Contributor

gvwilson commented Jul 3, 2024

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

@gvwilson gvwilson closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants