-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Trigger hover and click events on gl3d graphs #240
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
Changes from 9 commits
5d6ce26
75f243c
f059957
fdba7f1
a2f61b7
930b05a
f1c4b61
b87dbd0
2849724
bd960c9
2e63d1e
964a81d
f6f2e51
eebe7d0
97a4542
fa12603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
module.exports = function(type, x, y) { | ||
var options = { | ||
module.exports = function(type, x, y, opts) { | ||
var fullOpts = { | ||
bubbles: true, | ||
clientX: x, | ||
clientY: y | ||
}; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent | ||
if(opts && opts.buttons) { | ||
fullOpts.buttons = opts.buttons; | ||
} | ||
|
||
var el = document.elementFromPoint(x,y); | ||
var ev = new window.MouseEvent(type, options); | ||
var ev = new window.MouseEvent(type, fullOpts); | ||
el.dispatchEvent(ev); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,29 +4,106 @@ var Plotly = require('@lib/index'); | |
|
||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var mouseEvent = require('../assets/mouse_event'); | ||
|
||
/* | ||
* WebGL interaction test cases fail on the CircleCI | ||
* most likely due to a WebGL/driver issue | ||
* | ||
*/ | ||
|
||
var PLOT_DELAY = 100; | ||
var MOUSE_DELAY = 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it takes a little while for gl plots to be rendered properly even after the promise is returned. |
||
|
||
describe('Test plot structure', function() { | ||
|
||
describe('Test gl plot interactions', function() { | ||
'use strict'; | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
describe('gl3d plots', function() { | ||
var mock = require('@mocks/gl3d_marker-arrays.json'); | ||
var gd; | ||
|
||
function mouseEventScatter3d(type, opts) { | ||
mouseEvent(type, 605, 271, opts); | ||
} | ||
|
||
beforeEach(function(done) { | ||
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done); | ||
gd = createGraphDiv(); | ||
Plotly.plot(gd, mock.data, mock.layout).then(done); | ||
}); | ||
|
||
it('has one *canvas* node', function() { | ||
var nodes = d3.selectAll('canvas'); | ||
expect(nodes[0].length).toEqual(1); | ||
describe('scatter3d hover', function() { | ||
var node, ptData; | ||
|
||
beforeEach(function(done) { | ||
gd.on('plotly_hover', function(eventData) { | ||
ptData = eventData.points[0]; | ||
}); | ||
|
||
setTimeout(function() { | ||
mouseEventScatter3d('mouseover'); | ||
setTimeout(done, MOUSE_DELAY); | ||
}, PLOT_DELAY); | ||
}); | ||
|
||
it('should have', function() { | ||
node = d3.selectAll('canvas'); | ||
expect(node[0].length).toEqual(1, 'one canvas node'); | ||
|
||
node = d3.selectAll('g.hovertext'); | ||
expect(node.size()).toEqual(1, 'one hover text group'); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the least number of Unfortunately, there is no way to specify a single async Note that the second argument to all |
||
node = d3.selectAll('g.hovertext').selectAll('tspan')[0]; | ||
expect(node[0].innerHTML).toEqual('x: 140.72', 'x val on hover'); | ||
expect(node[1].innerHTML).toEqual('y: −96.97', 'y val on hover'); | ||
expect(node[2].innerHTML).toEqual('z: −96.97', 'z val on hover'); | ||
|
||
expect(Object.keys(ptData)).toEqual([ | ||
'x', 'y', 'z', | ||
'data', 'fullData', 'curveNumber', 'pointNumber' | ||
], 'correct hover data fields'); | ||
|
||
expect(ptData.x).toBe('140.72', 'x val hover data'); | ||
expect(ptData.y).toBe('−96.97', 'y val hover data'); | ||
expect(ptData.z).toEqual('−96.97', 'z val hover data'); | ||
expect(ptData.curveNumber).toEqual(0, 'curveNumber hover data'); | ||
expect(ptData.pointNumber).toEqual(2, 'pointNumber hover data'); | ||
}); | ||
|
||
}); | ||
|
||
describe('scatter3d click events', function() { | ||
var ptData; | ||
|
||
beforeEach(function(done) { | ||
gd.on('plotly_click', function(eventData) { | ||
ptData = eventData.points[0]; | ||
}); | ||
|
||
setTimeout(function() { | ||
|
||
// N.B. gl3d click events are 'mouseover' events | ||
// with button 1 pressed | ||
mouseEventScatter3d('mouseover', {buttons: 1}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. N.B. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should specify this in the |
||
setTimeout(done, MOUSE_DELAY); | ||
}, PLOT_DELAY); | ||
}); | ||
|
||
it('should have', function() { | ||
expect(Object.keys(ptData)).toEqual([ | ||
'x', 'y', 'z', | ||
'data', 'fullData', 'curveNumber', 'pointNumber' | ||
], 'correct hover data fields'); | ||
|
||
|
||
expect(ptData.x).toBe('140.72', 'x val click data'); | ||
expect(ptData.y).toBe('−96.97', 'y val click data'); | ||
expect(ptData.z).toEqual('−96.97', 'z val click data'); | ||
expect(ptData.curveNumber).toEqual(0, 'curveNumber click data'); | ||
expect(ptData.pointNumber).toEqual(2, 'pointNumber click data'); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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.
To note, click events are fired within the same distance as hover events. Specifically, click events can be fired in situations where the cursor isn't exactly on top of a given data point.
This behaviour is debatable. We might want to restrict click events to some
selection.distance
.