Skip to content

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

Closed
@etpinard

Description

@etpinard

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions