question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
etpinardcommented, Mar 11, 2021

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

https://github.com/plotly/plotly.js/blob/3f338292575425242bdd6f0e0b3548c80d039028/src/plots/cartesian/select.js#L309

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.
2reactions
nicolaskruchtencommented, Feb 15, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selections in Python - Plotly
To add multiple selections, select Shift when making new selections. To clear a selection, double-click it. On a subplot you can clear all...
Read more >
Selection events in Python/v3 - Plotly
Create a table FigureWidget that is updated by a selection event in another ... If a single string, the same string appears over...
Read more >
Shapes in Python - Plotly
As a general rule, there are two ways to add shapes (lines or polygons) to figures: Trace types in the scatter family (e.g....
Read more >
plotly.graph_objects.Figure — 5.11.0 documentation
The “select” flag enables selecting single data points via click. ... Selection events are sent accordingly as long as “event” flag is set...
Read more >
plotly.graph_objects package — 5.11.0 documentation
Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, “scatter” traces also appends...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found