- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Pass MouseEvent to the user #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
580d5fe
              fe4239b
              7a90972
              aea866e
              e809b23
              2e6fb16
              550a257
              d7e56cf
              40dc522
              85f72ff
              5f5bb9e
              8d5697b
              9cf50c2
              27eb8c3
              3584bba
              60ee153
              dcdda6f
              194243d
              20ff1a0
              3c41961
              00baba0
              5cdf009
              76e382e
              f679bbf
              91cc175
              499c393
              9e10119
              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 | 
|---|---|---|
|  | @@ -166,8 +166,8 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) { | |
| Fx.hover(gd, evt, self.id); | ||
| }); | ||
|  | ||
| map.on('click', function() { | ||
| Fx.click(gd, { target: true }); | ||
| map.on('click', function(evt) { | ||
| Fx.click(gd, evt.originalEvent); | ||
| 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. Very nice here. Thanks! | ||
| }); | ||
|  | ||
| function unhover() { | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| var mouseEvent = require('./mouse_event'); | ||
|  | ||
| module.exports = function click(x, y) { | ||
| mouseEvent('mousemove', x, y); | ||
| mouseEvent('mousedown', x, y); | ||
| mouseEvent('mouseup', x, y); | ||
| module.exports = function click(x, y, opts) { | ||
| mouseEvent('mousemove', x, y, opts); | ||
| mouseEvent('mousedown', x, y, opts); | ||
| mouseEvent('mouseup', x, y, opts); | ||
| mouseEvent('click', x, y, opts); | ||
| }; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,6 +9,18 @@ module.exports = function(type, x, y, opts) { | |
| if(opts && opts.buttons) { | ||
| fullOpts.buttons = opts.buttons; | ||
| } | ||
| if(opts && opts.altKey) { | ||
| 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. Nice. Thanks! | ||
| fullOpts.altKey = opts.altKey; | ||
| } | ||
| if(opts && opts.ctrlKey) { | ||
| fullOpts.ctrlKey = opts.ctrlKey; | ||
| } | ||
| if(opts && opts.metaKey) { | ||
| fullOpts.metaKey = opts.metaKey; | ||
| } | ||
| if(opts && opts.shiftKey) { | ||
| fullOpts.shiftKey = opts.shiftKey; | ||
| } | ||
|  | ||
| var el = (opts && opts.element) || document.elementFromPoint(x, y), | ||
| ev; | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -16,6 +16,30 @@ var customMatchers = require('../assets/custom_matchers'); | |
| var click = require('../assets/click'); | ||
| var doubleClickRaw = require('../assets/double_click'); | ||
|  | ||
| function move(fromX, fromY, toX, toY, delay) { | ||
| return new Promise(function(resolve) { | ||
| mouseEvent('mousemove', fromX, fromY); | ||
|  | ||
| setTimeout(function() { | ||
| mouseEvent('mousemove', toX, toY); | ||
| resolve(); | ||
| }, delay || DBLCLICKDELAY / 4); | ||
| }); | ||
| } | ||
|  | ||
| function drag(fromX, fromY, toX, toY, delay) { | ||
| return new Promise(function(resolve) { | ||
| mouseEvent('mousemove', fromX, fromY); | ||
| mouseEvent('mousedown', fromX, fromY); | ||
| mouseEvent('mousemove', toX, toY); | ||
|  | ||
| setTimeout(function() { | ||
| mouseEvent('mouseup', toX, toY); | ||
| resolve(); | ||
| }, delay || DBLCLICKDELAY / 4); | ||
| }); | ||
| } | ||
|  | ||
|  | ||
| describe('Test click interactions:', function() { | ||
| var mock = require('@mocks/14.json'); | ||
|  | @@ -39,19 +63,6 @@ describe('Test click interactions:', function() { | |
|  | ||
| afterEach(destroyGraphDiv); | ||
|  | ||
| function drag(fromX, fromY, toX, toY, delay) { | ||
| return new Promise(function(resolve) { | ||
| mouseEvent('mousemove', fromX, fromY); | ||
| mouseEvent('mousedown', fromX, fromY); | ||
| mouseEvent('mousemove', toX, toY); | ||
|  | ||
| setTimeout(function() { | ||
| mouseEvent('mouseup', toX, toY); | ||
| resolve(); | ||
| }, delay || DBLCLICKDELAY / 4); | ||
| }); | ||
| } | ||
|  | ||
| function doubleClick(x, y) { | ||
| return doubleClickRaw(x, y).then(function() { | ||
| return Plotly.Plots.previousPromises(gd); | ||
|  | @@ -87,6 +98,55 @@ describe('Test click interactions:', function() { | |
| expect(pt.pointNumber).toEqual(11); | ||
| expect(pt.x).toEqual(0.125); | ||
| expect(pt.y).toEqual(2.125); | ||
|  | ||
| var evt = futureData.event; | ||
| expect(evt.clientX).toEqual(pointPos[0]); | ||
| expect(evt.clientY).toEqual(pointPos[1]); | ||
| }); | ||
| }); | ||
|  | ||
| describe('modified click events', function() { | ||
| var clickOpts = { | ||
| altKey: true, | ||
| ctrlKey: true, | ||
| metaKey: true, | ||
| shiftKey: true | ||
| }, | ||
| futureData; | ||
|  | ||
| beforeEach(function(done) { | ||
| Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); | ||
|  | ||
| gd.on('plotly_click', function(data) { | ||
| futureData = data; | ||
| }); | ||
| }); | ||
|  | ||
| it('should not be trigged when not on data points', function() { | ||
| click(blankPos[0], blankPos[1], clickOpts); | ||
| expect(futureData).toBe(undefined); | ||
| }); | ||
|  | ||
| it('should contain the correct fields', function() { | ||
| click(pointPos[0], pointPos[1], clickOpts); | ||
| expect(futureData.points.length).toEqual(1); | ||
|  | ||
| var pt = futureData.points[0]; | ||
| expect(Object.keys(pt)).toEqual([ | ||
| 'data', 'fullData', 'curveNumber', 'pointNumber', | ||
| 'x', 'y', 'xaxis', 'yaxis' | ||
| ]); | ||
| expect(pt.curveNumber).toEqual(0); | ||
| expect(pt.pointNumber).toEqual(11); | ||
| expect(pt.x).toEqual(0.125); | ||
| expect(pt.y).toEqual(2.125); | ||
|  | ||
| var evt = futureData.event; | ||
| expect(evt.clientX).toEqual(pointPos[0]); | ||
| expect(evt.clientY).toEqual(pointPos[1]); | ||
| Object.getOwnPropertyNames(clickOpts).forEach(function(opt) { | ||
| expect(evt[opt]).toEqual(clickOpts[opt], opt); | ||
| 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. 🎉 | ||
| }); | ||
| }); | ||
| }); | ||
|  | ||
|  | @@ -191,6 +251,46 @@ describe('Test click interactions:', function() { | |
| expect(pt.pointNumber).toEqual(11); | ||
| expect(pt.x).toEqual(0.125); | ||
| expect(pt.y).toEqual(2.125); | ||
|  | ||
| var evt = futureData.event; | ||
| expect(evt.clientX).toEqual(pointPos[0]); | ||
| expect(evt.clientY).toEqual(pointPos[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. Maybe we could a test case that has a  | ||
| }); | ||
| }); | ||
|  | ||
| describe('plotly_unhover event with hoverinfo set to none', function() { | ||
| var futureData; | ||
|  | ||
| beforeEach(function(done) { | ||
|  | ||
| var modifiedMockCopy = Lib.extendDeep({}, mockCopy); | ||
| modifiedMockCopy.data[0].hoverinfo = 'none'; | ||
| Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout) | ||
| .then(done); | ||
|  | ||
| gd.on('plotly_unhover', function(data) { | ||
| futureData = data; | ||
| }); | ||
| }); | ||
|  | ||
| it('should contain the correct fields despite hoverinfo: "none"', function(done) { | ||
| move(pointPos[0], pointPos[1], blankPos[0], blankPos[1]).then(function() { | ||
| expect(futureData.points.length).toEqual(1); | ||
|  | ||
| var pt = futureData.points[0]; | ||
| expect(Object.keys(pt)).toEqual([ | ||
| 'data', 'fullData', 'curveNumber', 'pointNumber', | ||
| 'x', 'y', 'xaxis', 'yaxis' | ||
| ]); | ||
| expect(pt.curveNumber).toEqual(0); | ||
| expect(pt.pointNumber).toEqual(11); | ||
| expect(pt.x).toEqual(0.125); | ||
| expect(pt.y).toEqual(2.125); | ||
|  | ||
| var evt = futureData.event; | ||
| expect(evt.clientX).toEqual(blankPos[0]); | ||
| expect(evt.clientY).toEqual(blankPos[1]); | ||
| }).then(done); | ||
| }); | ||
| }); | ||
|  | ||
|  | @@ -817,6 +917,7 @@ describe('Test click interactions:', function() { | |
| }); | ||
| }); | ||
|  | ||
|  | ||
| describe('dragbox', function() { | ||
|  | ||
| afterEach(destroyGraphDiv); | ||
|  | ||
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.
Great. This will work for all subplots that call
Fx.hoverif I remember correctly that means: cartesian, ternary, geo and mapbox subplots. @n-riesco would you mind double checking?Now, at the very least, we should make sure
eventis passed in pie chart hover data. Pie hover is a little different but shouldn't make it too hard to implement.This leaves our gl2d, gl3d and
parcoords(and polar but who cares about polar?). I'll be ok leaving them out of the first iteration. We should instead spent some time down the road merging their hover logic withFx.hover.Uh oh!
There was an error while loading. Please reload this page.
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.
@etpinard It doesn't work for pie, ternary, geo or mapbox, because when they call to
Fx.click(gd, evt)they make up anevt.I reckon that to make it work for all these types of subplots, first I need to locate where they call
Fx.click,Fx.hoverandFx.unhoverand then see if it's possible to send the original event.For example, here: why do we need to set the event to
{target: true}? Is is OK if we just doFx.click(gd, d3.event);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.
That sounds ok to me, yes.