-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
1852 persistent click #2824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
1852 persistent click #2824
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
25c56e4
Add click-to-select behavior for scatter [1852]
rmoestl 5602335
Support deselect on click for scatter [1852]
rmoestl f4243b4
Transition to no selection style after deselecting a data point [1852]
rmoestl b552ccf
Allow to retain current selection with pressing Shift key [1852]
rmoestl b9c893f
Take retention mode into acount on deselect [1852]
rmoestl c1925ea
Retain click-selected points in box or lasso select mode [1852]
rmoestl 0eddcbc
Introduce change of trace selection interface [1852]
rmoestl ca80c89
Implement polygon subtract mode in new approach [1852]
rmoestl 2fb35cf
Remove polygon outlines when select-on-click [1852]
rmoestl 436a746
Clean up click-on-select code [1852]
rmoestl 64705e1
Fix bug in deletion of polygon select outlines [1852]
rmoestl 3900d5c
Condense traces' selection interface surface [1852]
rmoestl 6a672ed
Fix typo scatter's select module [1852]
rmoestl 2bc81a2
Transition bar trace to new selection mechanism [1852]
rmoestl f51afcf
Support click-to-select in a multi-traces setting [1852]
rmoestl a1efe01
Extract 'finding selectable traces' in cartesian/select [1852]
rmoestl 722805e
Transition scattergl to new selection interface [1852]
rmoestl 4f0a05d
Adapt cartesian's selectOnClick to support histogram [1852]
rmoestl 5125981
Use clearEntireSelection flag in cartesian/select [1852]
rmoestl a79dea7
Fix bug when clearing entire selection [1852]
rmoestl 4d8b274
Implement new selection interface for box trace type [1852]
rmoestl 231fa6d
Consider first eventData element only as clicked point [1852]
rmoestl 6bd46bf
Clean up code in box/select.js [1852]
rmoestl 427b4b6
Not select a clicked box in box trace type [1852]
rmoestl 3d21856
Not change selection state when a box is clicked in box trace [1852]
rmoestl b0c32c1
Remove unused testPoly variable in cartesian select module [1852]
rmoestl a630ef8
Remove obsolete `selectPoints` from box trace's select module [1852]
rmoestl e07210c
Quick fix in dragbox module to satisfy ESLint [1852]
rmoestl e082e58
Remove obsolete `selectPoints` from scattergl's select module [1852]
rmoestl a97af32
Transition violin trace type to new selection interface [1852]
rmoestl aac89ce
Reactivate emitting 'plotly_click' events [1852]
rmoestl 4b41e24
Emit 'plotly_deselect' after outlines have been removed [1852]
rmoestl f0822d5
Fix testing if double-click cleans selection in box/lasso mode [1852]
rmoestl 8428bbc
Fix testing selection subtraction in box/lasso mode [1852]
rmoestl f4384de
Transition scattergeo trace type to new selection interface [1852]
rmoestl bbd63d4
Transition scattercarpet trace type to new selection interface [1852]
rmoestl d7087a6
speed up Lib.difference
etpinard df351c3
Introduce _module.selectable flag for trace modules [1852]
rmoestl 0840100
Merge branch 'master' into 1852-persistent-click
rmoestl b703a9c
Consider subplot when determining traces for click-to-select [1852]
rmoestl d7e64dd
Put back call to remove outlines back to original location [1852]
rmoestl c4012e1
Reintroduce selectMode guard in scattegl [1852]
rmoestl f9494b5
Fix modebar Jasmine tests involving selectable traces [1852]
rmoestl e7815e9
Transition scattermapbox trace type to new selection interface [1852]
rmoestl c88aee0
Prevent mapbox removing select outlines on every drag operation [1852]
rmoestl bd04fd8
Disable click-to-select in pan/zoom mode temporarily [1852]
rmoestl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
/** | ||
* Computes the set difference of two arrays. | ||
* | ||
* @param {array} a | ||
* @param {array} b | ||
* @returns out all elements of a that are not in b. | ||
* If a is not an array, an empty array is returned. | ||
* If b is not an array, a is returned. | ||
*/ | ||
function difference(a, b) { | ||
if(!Array.isArray(a)) return []; | ||
if(!Array.isArray(b)) return a; | ||
|
||
var hash = {}; | ||
var out = []; | ||
var i; | ||
|
||
for(i = 0; i < b.length; i++) { | ||
hash[b[i]] = 1; | ||
} | ||
|
||
for(i = 0; i < a.length; i++) { | ||
var ai = a[i]; | ||
if(!hash[ai]) out.push(ai); | ||
} | ||
|
||
return out; | ||
} | ||
|
||
module.exports = { | ||
difference: difference | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit makes selection of 1e5 scattergl markers work ok, but still about an order of magnitude too slow.
I'll have to dig deeper tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you dug deeper since then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had the time unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... I'll find some time to review it before the meeting on Thursday though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. There's no hurry at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok very briefly just to get a conversion started (and not break my promise):
Doing some order of operation analysis in the hot selection code path comparing:
plotly.js/src/plots/cartesian/select.js
Lines 283 to 286 in def6aa5
on master to this branch's
plotly.js/src/plots/cartesian/select.js
Lines 242 to 254 in bd04fd8
we can see why this branch is roughly an order of magnitude slower:
On master that block scales as O(n). To handle addition/subtraction/merge selections, we use an algo acting on the selections polygon with I believe is O(number-of-vertices^2) but results nonetheless in not that many computations in most use cases (e.g. rectangles with 4 vertices)
On this branch, we have
which when added all up gives a total of O(6n + p) where n is the number of points and p is number of selected points ~ roughly one order of magnitude.
So, we should try to combine all the
toggleSelected
loops into one. Don't get me wrong, I don't think splitting upselectedPoints
intotoggleSelected
andgetPointsIn
was a bad idea, but perhaps we could bring a version ofselectPoints
that reusesgetPointsIn
? We can talk more about this tomorrow during the meeting. Thanks for your hard work!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hindsight it seams the new approach of splitting up
selectedPoints
wasn't such a good idea :-( I'm not sure if it's possible to speed things up that much with that approach. To be honest, it feels like to be at square one again.Thinking back, the reason for splitting up
selectPoints
was to cover a couple of edge cases when users would use click-to-select and polygon-select interchangeably. Back then we discussed possible approaches here.Let me jot down some thoughts for the upcoming meeting:
Current approach on master
The approach to selections before tackling persistent select was as follows: each trace type module supporting selection exposes a
selectPoints
function that accepts asearchInfo
parameter describing the actual trace and apolygon
object that offers acontains
function.selectPoints
iterates through the data points of the passed trace (identified bysearchInfo
) and callspolygon.contains
for each data point to see if the data point is within the selection area. Adding/subtracting from an existing selection is supported by wrapping multiplepolygons
into one multiPolygon and passing that toselectPoints
.Possible new approach to support click-to-select
The whole polygon testing approach is covered in
lib/polygon.js
which exposestester
(for testing a single polygon) andmultiTester
(wrapper for multipletester
objects). What about having a thirdtester
type that tests by data point index? What would that mean for the client code?selectPoints
in trace type modulescontains
selectPoints
implementations do not only pass thex
andy
(orlan
,lat
etc.) of a data point when callingcontains
but also the data point indexmultiTester
to be able to wrap the new index-based testerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your new approach sounds very promising! I'd say give it a shot with
scatter
andscattergl
and ping me so that I can quickly review and perf-test it. 👌There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etpinard proof-of-concept is ready to review. It was easier to start from scratch. So the new approach can be found at https://github.com/plotly/plotly.js/tree/1852-persistent-click-via-selectPoints. (Although it would make reviewing easier, I figured code is not quite ready for a new PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few comments on 2fbaaaa . Your solution is looking great! 💎
I'd say go ahead and try to implement it for all selectable trace modules. 🚀