Skip to content

Commit 6a2ae3b

Browse files
committed
Refine click-to-select TODO comments that'll be solved later [1852]
- Updates of TODO comments are based on discussions on Github and Slack.
1 parent 41e3ba5 commit 6a2ae3b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
189189
// triggers at least one interaction in pan/zoom mode. Otherwise, the
190190
// select/lasso outlines are deleted (in plots.js.cleanPlot) but the selection
191191
// cache isn't cleared. So when the user switches back to select/lasso and
192-
// 'add to a selection' with Shift, the "old", seemingly removed outlines
193-
// are redrawn again because the selection cache still holds their points.
192+
// 'adds to a selection' with Shift, the "old", seemingly removed outlines
193+
// are redrawn again because the selection cache still holds their coordinates.
194194
// However, this isn't easily solved, since plots.js would need
195-
// to have a reference to the dragOptions object.
195+
// to have a reference to the dragOptions object (which holds the
196+
// selection cache).
196197
clearAndResetSelect();
197198
}
198199

src/plots/cartesian/select.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
259259
if(clickmode === 'event') {
260260
// TODO: remove in v2 - this was probably never intended to work as it does,
261261
// but in case anyone depends on it we don't want to break it now.
262+
// Note that click-to-select introduced pre v2 also emitts proper
263+
// event data when clickmode is having 'select' in its flag list.
262264
gd.emit('plotly_selected', undefined);
263265
}
264266
}
@@ -528,24 +530,6 @@ function createPtNumTester(wantedPointNumber, wantedSearchInfo, subtract) {
528530
}
529531

530532
function isPointOrBinSelected(clickedPtInfo) {
531-
// TODO improve perf
532-
// Primarily we need this function to determine if a click adds or subtracts from a selection.
533-
//
534-
// IME best user experience would be
535-
// - that Shift+Click an unselected points adds to selection
536-
// - and Shift+Click a selected point subtracts from selection.
537-
//
538-
// Several options:
539-
// 1. Avoid problem at all by binding subtract-selection-by-click operation to Shift+Alt-Click.
540-
// Slightly less intuitive. A lot of programs deselect an already selected element when you
541-
// Shift+Click it.
542-
// 2. Delegate decision to the traces module through an additional
543-
// isSelected(searchInfo, pointNumber) function. Traces like scatter or bar have
544-
// a selected flag attached to each calcData element, thus access to that information
545-
// would be fast. However, scattergl only maintains selectBatch and unselectBatch arrays.
546-
// So simply searching through those arrays in scattegl would be slow. Just imagine
547-
// a user selecting all data points with one lasso polygon. So scattergl would require some
548-
// work.
549533
var trace = clickedPtInfo.searchInfo.cd[0].trace;
550534
var ptNum = clickedPtInfo.pointNumber;
551535
var ptNums = clickedPtInfo.pointNumbers;
@@ -556,6 +540,11 @@ function isPointOrBinSelected(clickedPtInfo) {
556540
// a bin is selected, all others are as well
557541
var ptNumToTest = ptNumsSet ? ptNums[0] : ptNum;
558542

543+
// TODO potential performance improvement
544+
// Primarily we need this function to determine if a click adds
545+
// or subtracts from a selection.
546+
// In cases `trace.selectedpoints` is a huge array, indexOf
547+
// might be slow. One remedy would be to introduce a hash somewhere.
559548
return trace.selectedpoints ? trace.selectedpoints.indexOf(ptNumToTest) > -1 : false;
560549
}
561550

0 commit comments

Comments
 (0)