Skip to content

1852 persistent click via select points #2944

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

Merged
merged 56 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2fbaaaa
Tracer-bullet impl of fast click-to-select [1852]
rmoestl Aug 10, 2018
346bad9
Set correct blank outlines path in case of zero select polygons [1852]
rmoestl Aug 16, 2018
4f8dd92
Fix select_test.js Jasmine tests [1852]
rmoestl Aug 16, 2018
6a87769
Add click-to-select specific tests to select_test.js [1852]
rmoestl Aug 17, 2018
2d59365
Make click-to-select work in pan/zoom dragmodes [1852]
rmoestl Aug 21, 2018
5a13573
Introduce layout attribute 'clickmode' [1852]
rmoestl Aug 21, 2018
d3b4a0f
Simplify signature of selection testers' contains function [1852]
rmoestl Aug 21, 2018
36145df
Support click-to-select for histograms [1852]
rmoestl Aug 22, 2018
73e5085
Fix click-to-select bug when clearing selection with Shift [1852]
rmoestl Aug 22, 2018
1a89040
Enable click-to-select for scattergl in pan/zoom mode [1852]
rmoestl Aug 22, 2018
a6e49fd
Add click-to-select support to box plots [1852]
rmoestl Aug 22, 2018
bb44b6d
Fix bug when clearing selections and add/subtract mode on [1852]
rmoestl Aug 23, 2018
48a0a36
Test violin trace type's support for click-to-test [1852]
rmoestl Aug 23, 2018
4639718
Add click-to-select support to ohlc and candlestick [1852]
rmoestl Aug 23, 2018
497747b
Add click-to-select support to geo base plot [1852]
rmoestl Aug 23, 2018
744ab56
Add click-to-select support to mapbox and scattermapbox [1852]
rmoestl Aug 24, 2018
7da973b
Add @flaky flag to click-to-select tests [1852]
rmoestl Aug 24, 2018
ee5f990
Reactivate unhover on mouseout event in geo base plot [1852]
rmoestl Aug 24, 2018
6ac1a08
Add click-to-select support to scattergeo [1852]
rmoestl Aug 24, 2018
e11faf5
Add click-to-select support to ternary base plot [1852]
rmoestl Aug 24, 2018
bef47a3
Add test of scattercarpet's click-to-select support [1852]
rmoestl Aug 24, 2018
c394a8b
Add click-to-select support to polar base plot [1852]
rmoestl Aug 24, 2018
5b08a2c
Add testing scatterpolargl's click-to-select support [1852]
rmoestl Aug 24, 2018
e763964
Add click-to-select support to splom [1852]
rmoestl Aug 24, 2018
41e3ba5
Activate persistent selection for ternary plots [1852]
rmoestl Aug 27, 2018
6a2ae3b
Refine click-to-select TODO comments that'll be solved later [1852]
rmoestl Aug 27, 2018
e7c2240
Clean up box' custom eventData function [1852]
rmoestl Aug 27, 2018
23024b2
Call click-to-select's isPointOrBinSelected as late as possible [1852]
rmoestl Aug 27, 2018
cbd9f07
Refactor selection testing namings and structure [1852]
rmoestl Aug 27, 2018
7eba640
Add comment for multiTester's contains function [1852]
rmoestl Aug 27, 2018
92ee0fa
Remove two obsolete comments from cartesian/select.js [1852]
rmoestl Aug 27, 2018
3073f61
Merge branch 'master' into 1852-persistent-click-via-selectPoints
rmoestl Aug 27, 2018
3767ce2
Fix test-syntax linting errors in select_test.js [1852]
rmoestl Aug 27, 2018
8a4fc99
Fix further test-syntax linting errors in select_test.js [1852]
rmoestl Aug 27, 2018
db3e126
Fix for-loop bug in cartesian/select.js caught by ESLint [1852]
rmoestl Aug 27, 2018
b3984f7
Adapt description of of `clickmode` attribute [1852]
rmoestl Aug 29, 2018
2f7ad27
Simplify check if clicked point is the sole selected point [1852]
rmoestl Aug 30, 2018
d7c1434
Flag click-to-select tests of gl-based traces with @gl [1852]
rmoestl Aug 30, 2018
e895efd
Rename variable in `lib/select.js` [1852]
rmoestl Aug 30, 2018
60317b1
Adapt uninitialized var declarations in click-to-select code [1852]
rmoestl Aug 30, 2018
61b1a32
Add 'none' as an extra flag to clickmode [1852]
rmoestl Aug 30, 2018
e460e46
Simplify code for coercing selection cache state [1852]
rmoestl Aug 30, 2018
2ef3fce
Resolve TODO in cartesian/select.js regarding binned traces [1852]
rmoestl Aug 30, 2018
ac4b909
Remove lib/select.js and integrate code in cartesian/select.js [1852]
rmoestl Aug 30, 2018
05b50b9
Fix mapbox click-to-select bug caused by multiple click listeners [1852]
rmoestl Aug 30, 2018
88e9993
Fix testing click-to-select is inactive if clickmode is 'event' [1852]
rmoestl Sep 4, 2018
f247d93
Ensure 'plotly_click' is fired after 'plotly_selected' [1852]
rmoestl Sep 4, 2018
90ba209
Replace dynamic CI tags with static ones in select_test.js [1852]
rmoestl Sep 5, 2018
2bc582b
Apply @noCI tag to mapbox tests in select_test.js [1852]
rmoestl Sep 5, 2018
96fcdd7
Minor change: move helper method in select_test.s [1852]
rmoestl Sep 5, 2018
a5a90f9
Add a comment to select_test.js test [1852]
rmoestl Sep 6, 2018
87d0497
Default hovermode to closest if clickmode is select [1852]
rmoestl Sep 7, 2018
30789dd
Remove :hocho: obsolete polygon.multitester function [1852]
rmoestl Sep 7, 2018
cc2c9ba
Merge branch 'master' into 1852-persistent-click-via-selectPoints
rmoestl Sep 7, 2018
32aa219
Simplify clickmode / hovermode coercion code [1852]
rmoestl Sep 7, 2018
b6bd813
Not throw error for no longer valid polygon.tester argument [1852]
rmoestl Sep 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/plots/cartesian/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
}

updateSelectedState(gd, searchTraces);

clearSelectionsCache(dragOptions);

gd.emit('plotly_deselect', null);
} else {
if(clickmode.indexOf('select') > -1) {
Expand Down Expand Up @@ -322,9 +325,7 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli

updateSelectedState(gd, searchTraces);

// Clear selection cache to ensure a possible next selection
// starts from a clean slate.
dragOptions.polygons = [];
clearSelectionsCache(dragOptions);

if(sendEvents) {
gd.emit('plotly_deselect', null);
Expand Down Expand Up @@ -387,10 +388,7 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
(!evt.shiftKey && !evt.altKey) ||
((evt.shiftKey || evt.altKey) && !plotinfo.selection)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 logic here is a bit tough to read (and I think could be simplified). If we start with:
var hasModifierKey = evt.shiftKey || evt.altKey;
then this is (?):
!hasModifierKey || (hasModifierKey && !plotinfo.selection)
and then it's clear it simplifies to:
!hasModifierKey || !plotinfo.selection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

) {
// create new polygons, if shift mode or selecting across different subplots
plotinfo.selection = {};
plotinfo.selection.polygons = dragOptions.polygons = [];
plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = [];
clearSelectionsCache(dragOptions);
}

// clear selection outline when selecting a different subplot
Expand All @@ -400,6 +398,14 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
}
}

function clearSelectionsCache(dragOptions) {
var plotinfo = dragOptions.plotinfo;

plotinfo.selection = {};
plotinfo.selection.polygons = dragOptions.polygons = [];
plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = [];
}

function determineSearchTraces(gd, xAxes, yAxes, subplot) {
var searchTraces = [];
var xAxisIds = xAxes.map(getAxId);
Expand Down
15 changes: 9 additions & 6 deletions test/jasmine/assets/double_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ var getNodeCoords = require('./get_node_coords');
var DBLCLICKDELAY = require('../../../src/constants/interactions').DBLCLICKDELAY;

/*
* double click on a point.
* you can either specify x,y as pixels, or
* Double click on a point.
* You can either specify x,y as pixels, or
* you can specify node and optionally an edge ('n', 'se', 'w' etc)
* to grab it by an edge or corner (otherwise the middle is used)
* to grab it by an edge or corner (otherwise the middle is used).
* You can also pass options for the underlying click, e.g.
* to specify modifier keys. See `click` function
* for more info.
*/
module.exports = function doubleClick(x, y) {
module.exports = function doubleClick(x, y, clickOpts) {
if(typeof x === 'object') {
var coords = getNodeCoords(x, y);
x = coords.x;
y = coords.y;
}
return new Promise(function(resolve) {
click(x, y);
click(x, y, clickOpts);

setTimeout(function() {
click(x, y);
click(x, y, clickOpts);
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
}, DBLCLICKDELAY / 2);
});
Expand Down
53 changes: 53 additions & 0 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ describe('Click-to-select', function() {
});
});

it('cleanly clears and starts selections although add/subtract mode on', function(done) {
plotMock14()
.then(function() {
return _immediateClickPt(mock14Pts[7]);
})
.then(function() {
assertSelectedPoints(7);
_clickPt(mock14Pts[7], { shiftKey: true });
return deselectPromise;
})
.then(function() {
assertSelectionCleared();
return _clickPt(mock14Pts[35], { shiftKey: true });
})
.then(function() {
assertSelectedPoints(35);
})
.catch(failTest)
.then(done);
});

it('supports adding to an existing selection', function(done) {
plotMock14()
.then(function() { return _immediateClickPt(mock14Pts[7]); })
Expand Down Expand Up @@ -1134,6 +1155,38 @@ describe('@flaky Test select box and lasso in general:', function() {
.then(done);
});

it('should cleanly clear and restart selections on double click when add/subtract mode on', function(done) {
var gd = createGraphDiv();
var fig = Lib.extendDeep({}, require('@mocks/0.json'));

fig.layout.dragmode = 'select';
Plotly.plot(gd, fig)
.then(function() {
return drag([[350, 100], [400, 400]]);
})
.then(function() {
_assertSelectedPoints([49, 50, 51, 52, 53, 54, 55, 56, 57]);
return doubleClick(500, 200, { shiftKey: true });
})
.then(function() {
_assertSelectedPoints(null);
return drag([[450, 100], [500, 400]], { shiftKey: true });
})
.then(function() {
_assertSelectedPoints([67, 68, 69, 70, 71, 72, 73, 74]);
})
.catch(failTest)
.then(done);

function _assertSelectedPoints(selPts) {
if(selPts) {
expect(gd.data[0].selectedpoints).toEqual(selPts);
} else {
expect('selectedpoints' in gd.data[0]).toBe(false);
}
}
});

it('should clear selected points on double click only on pan/lasso modes', function(done) {
var gd = createGraphDiv();
var fig = Lib.extendDeep({}, require('@mocks/0.json'));
Expand Down