Skip to content

enable persistence of selection info to the layout #6167

@alexcjohnson

Description

@alexcjohnson

Part of #1851 - split out so we can discuss it separately

To make it possible to retain selections across redraws or create a new selection programmatically, the selection data should be part of the layout. This also means that when you finish a selection, in addition to the plotly_selected event you'll also get a plotly_relayout event. Probably no changes in the middle though (ie with plotly_selecting).

So what should these attributes look like? We need to describe the selection in data coordinates, including which axes / subplot we're selecting on; we need to support rectangular and lasso selections, as well as shift-select combinations of multiple regions and simultaneous selections on different subplots.

So I propose:

layout.selections = [{
    subplot: 'xy',
    type: 'rect',
    x: [5, 10],
    y: [-3, 6]
}, {
    subplot: 'x2y2',
    type: 'lasso',
    x: [5, 6, 5, 4, 2, 3],
    y: [9, 8, 7, 7, 8, 9]
}, {
    subplot: 'geo3',
    type: 'rect',
    geo: [[-113, 72], [-108, 22]]
}]

One tricky case here around geo subplots: for many projections when you pan or zoom, what was a rectangle is no longer a rectangle, what was a straight line is no longer straight. We may need to either (a) convert rect to lasso, and increase the density of points on the lassos when you pan/zoom after making the selection, or (b) keep track of the projection parameters in effect when the selection was made, so we can transform it to an accurate representation in the new projection. Option (a) will never be perfect, and will have occasional edge cases where it breaks down spectacularly, but (b) means adding a complicated bunch of logic to the drawing and point selection routines, and may have performance implications. mapbox may have some of this issue, as it supports rotating and tilting, though straight lines are still pretty close to straight when the map is tilted even if they are no longer x/y aligned. polar too, in the case where users set a nonzero inner radius.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions