Skip to content

Commit

Permalink
fix select/lasso click event + test
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Jan 17, 2018
1 parent 1075d87 commit ebaf705
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plots/cartesian/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var polygon = require('../../lib/polygon');
var throttle = require('../../lib/throttle');
var color = require('../../components/color');
var makeEventData = require('../../components/fx/helpers').makeEventData;
var Fx = require('../../components/fx');

var axes = require('./axes');
var constants = require('./constants');
Expand Down Expand Up @@ -258,7 +259,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
);
};

dragOptions.clickFn = function(numClicks) {
dragOptions.clickFn = function(numClicks, evt) {
corners.remove();

throttle.done(throttleID).then(function() {
Expand All @@ -279,6 +280,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
// but in case anyone depends on it we don't want to break it now.
gd.emit('plotly_selected', undefined);
}

Fx.click(gd, evt);
});
};

Expand Down
78 changes: 78 additions & 0 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,84 @@ describe('Test hover and click interactions', function() {
.then(done);
});

it('should output correct event data for scattergl in *select* dragmode', function(done) {
var _mock = Lib.extendDeep({}, mock1);

_mock.layout.dragmode = 'select';

_mock.layout.hoverlabel = {
font: {
size: 20,
color: 'yellow'
}
};
_mock.data[0].hoverinfo = _mock.data[0].x.map(function(_, i) { return i % 2 ? 'y' : 'x'; });

_mock.data[0].hoverlabel = {
bgcolor: 'blue',
bordercolor: _mock.data[0].x.map(function(_, i) { return i % 2 ? 'red' : 'green'; })
};

var run = makeRunner([634, 321], {
x: 15.772,
y: 0.387,
label: ['0.387', null],
curveNumber: 0,
pointNumber: 33,
bgcolor: 'rgb(0, 0, 255)',
bordercolor: 'rgb(255, 0, 0)',
fontSize: 20,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 0)'
}, {
msg: 'scattergl'
});

Plotly.plot(gd, _mock)
.then(run)
.catch(fail)
.then(done);
});

it('should output correct event data for scattergl in *lasso* dragmode', function(done) {
var _mock = Lib.extendDeep({}, mock1);

_mock.layout.dragmode = 'lasso';

_mock.layout.hoverlabel = {
font: {
size: 20,
color: 'yellow'
}
};
_mock.data[0].hoverinfo = _mock.data[0].x.map(function(_, i) { return i % 2 ? 'y' : 'x'; });

_mock.data[0].hoverlabel = {
bgcolor: 'blue',
bordercolor: _mock.data[0].x.map(function(_, i) { return i % 2 ? 'red' : 'green'; })
};

var run = makeRunner([634, 321], {
x: 15.772,
y: 0.387,
label: ['0.387', null],
curveNumber: 0,
pointNumber: 33,
bgcolor: 'rgb(0, 0, 255)',
bordercolor: 'rgb(255, 0, 0)',
fontSize: 20,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 0)'
}, {
msg: 'scattergl'
});

Plotly.plot(gd, _mock)
.then(run)
.catch(fail)
.then(done);
});

it('should output correct event data for scattergl with hoverinfo: \'none\'', function(done) {
var _mock = Lib.extendDeep({}, mock1);
_mock.data[0].hoverinfo = 'none';
Expand Down

0 comments on commit ebaf705

Please sign in to comment.