Open alexcjohnson opened 2 years ago
will this stay coordinates with selectedpoints
?
Great question - when the user is creating or modifying the selection via GUI we'll set them both, but when rendering or rerendering the graph it seems like you might want it either way:
trace.selectedpoints
without layout.selections
you pretty clearly want selectedpoints
to stay there.layout.selections
is empty and wipe out trace.selectedpoints
, but that could be cumbersome.layout.selections
and the data has changed, most likely you want selectedpoints
to update to the new set of points within the selection.So perhaps we need a boolean attribute that explicitly says "when replotting, do I recalculate selectedpoints
to match selections
?" Like layout.syncselectedpoints
or something? layout.syncselections
? layout.reselect
?
All good questions. Maybe they all roll up into "what to do if selectedpoints
and selections
don't match?" The options are, basically to trigger a relayout to force selectedpoints to match selections, or not, which could be controlled by a boolean.
Regarding selectedpoints
, this part of the code looks pretty strange to my eyes:
https://github.com/plotly/plotly.js/blob/13773569a94d80f61459fa5b4aaf2166cba3b3a5/src/plots/cartesian/select.js#L788-L835
Why both trace.selectedpoints
and trace._input.selectedpoints
are mutated?
Probably because we want the result to be as if we had called restyle
providing the new selectedpoints
, but we don't want the overhead of a full restyle
call.
This causes a large issue when trying to sync selected points between multiple plots (non-sub-plots). If the selections array even had an ids option that would be great
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 aplotly_relayout
event. Probably no changes in the middle though (ie withplotly_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:
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.