Include info from all multi-selection polygons in `plotly_selected` event data
See original GitHub issueHi, 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.

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:
- Created 3 years ago
- Reactions:2
- Comments:7 (7 by maintainers)

Top Related StackOverflow Question
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
fillRangeItemsstatementhttps://github.com/plotly/plotly.js/blob/3f338292575425242bdd6f0e0b3548c80d039028/src/plots/cartesian/select.js#L309
with
mergedPolygonsinstead ofcurrentPolygon. While making this work would be possible and not too difficult, there are a few issues:mergedPolygonscontains the merged polygons x/y coordinates, not the set of selected rectangles (or ranges). For example, aftermergedPolygonscontains 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
mergePolygonsdata in the selection event data, we should probably not name the new event data keyrangeMulti. Something likepolygon.(x|y)would be better.dragOptionsfield.Nice to hear from you! This seems like a good solution 😃