Skip to content

fix ternary hover after zoom/pan events #688

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 5 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 7 additions & 0 deletions test/jasmine/assets/click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var mouseEvent = require('./mouse_event');

module.exports = function click(x, y) {
mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
};
13 changes: 13 additions & 0 deletions test/jasmine/assets/double_click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var click = require('./click');
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;

module.exports = function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);

setTimeout(function() {
click(x, y);
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
}, DBLCLICKDELAY / 2);
});
};
26 changes: 6 additions & 20 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var mouseEvent = require('../assets/mouse_event');
var getRectCenter = require('../assets/get_rect_center');
var customMatchers = require('../assets/custom_matchers');

// cartesian click events events use the hover data
// from the mousemove events and then simulate
// a click event on mouseup
var click = require('../assets/click');
var doubleClick = require('../assets/double_click');
Copy link
Contributor

Choose a reason for hiding this comment

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

Fantastic. Thanks so much!



describe('Test click interactions:', function() {
var mock = require('@mocks/14.json');
Expand All @@ -31,26 +37,6 @@ describe('Test click interactions:', function() {

afterEach(destroyGraphDiv);

// cartesian click events events use the hover data
// from the mousemove events and then simulate
// a click event on mouseup
function click(x, y) {
mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);

setTimeout(function() {
click(x, y);
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
}, DBLCLICKDELAY / 2);
});
}

function drag(fromX, fromY, toX, toY, delay) {
return new Promise(function(resolve) {
mouseEvent('mousemove', fromX, fromY);
Expand Down
21 changes: 1 addition & 20 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Lib = require('@src/lib');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var mouseEvent = require('../assets/mouse_event');
var doubleClick = require('../assets/double_click');

describe('hover info', function() {
'use strict';
Expand Down Expand Up @@ -691,26 +692,6 @@ describe('hover on fill', function() {
}).then(done);
});

// click and doubleClick copied over from click_test
// TODO require from elsewhere
function click(x, y) {
mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);

setTimeout(function() {
click(x, y);
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
}, DBLCLICKDELAY / 2);
});
}
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;

it('should work for scatterternary too', function(done) {
var mock = Lib.extendDeep({}, require('@mocks/ternary_fill.json'));

Expand Down
27 changes: 6 additions & 21 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var d3 = require('d3');
var Plotly = require('@lib/index');
var Lib = require('@src/lib');
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
var click = require('../assets/click');
var doubleClick = require('../assets/double_click');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
Expand Down Expand Up @@ -35,23 +37,6 @@ describe('select box and lasso', function() {
mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]);
}

// cartesian click events events use the hover data
// from the mousemove events and then simulate
// a click event on mouseup
function click(x, y) {
mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y, cb) {
click(x, y);
setTimeout(function() {
click(x, y);
cb();
}, DBLCLICKDELAY / 2);
}

function assertRange(actual, expected) {
var PRECISION = 4;

Expand Down Expand Up @@ -104,7 +89,7 @@ describe('select box and lasso', function() {

drag([[x0, y0], [x1, y1]]);

doubleClick(x2, y2, done);
doubleClick(x2, y2).then(done);
});
});

Expand Down Expand Up @@ -153,7 +138,7 @@ describe('select box and lasso', function() {

drag([[x0, y0], [x1, y1]]);

doubleClick(x2, y2, done);
doubleClick(x2, y2).then(done);
Copy link
Contributor

Choose a reason for hiding this comment

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

much better. 🎉

});
});

Expand Down Expand Up @@ -225,7 +210,7 @@ describe('select box and lasso', function() {
y: [0.10209191961595454, 24.512223978291406]
}, 'with the correct selected range');

doubleClick(250, 200, function() {
doubleClick(250, 200).then(function() {
expect(doubleClickData).toBe(null, 'with the correct deselect data');
done();
});
Expand Down Expand Up @@ -283,7 +268,7 @@ describe('select box and lasso', function() {
y: 2.75
}], 'with the correct selected points');

doubleClick(250, 200, function() {
doubleClick(250, 200).then(function() {
expect(doubleClickData).toBe(null, 'with the correct deselect data');
done();
});
Expand Down
20 changes: 2 additions & 18 deletions test/jasmine/tests/ternary_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var Plotly = require('@lib');
var Lib = require('@src/lib');
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;

var supplyLayoutDefaults = require('@src/plots/ternary/layout/defaults');

var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var mouseEvent = require('../assets/mouse_event');
var click = require('../assets/click');
var doubleClick = require('../assets/double_click');
var customMatchers = require('../assets/custom_matchers');


Expand Down Expand Up @@ -238,23 +239,6 @@ describe('ternary plots', function() {
return d3.select('.hoverlayer').selectAll('g');
}

function click(x, y) {
mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);

setTimeout(function() {
click(x, y);
resolve();
}, DBLCLICKDELAY / 2);
});
}

function drag(path) {
var len = path.length;

Expand Down