-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add doubleclick events #255
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
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bd6995e
wip emit double click eventData
etpinard 10cded2
emit 'plotly_doubleclick' events,
etpinard 8b6783f
flatten click test describe struc
etpinard e8ef663
add double click test
etpinard d46ae26
add select/lasso jasmine tests
etpinard 02eca97
revert Plots object in register,
etpinard 782f692
use toBeCloseTo to assert selection ranges,
etpinard 5b1e895
add comment about click events simulators
etpinard c41a756
make jasmine describe more explicit
etpinard 9c19406
try sending hoverdata on double click:
etpinard e7e0889
Merge branch 'master' into emit-doubleclick
etpinard 848f4a5
move destroyGraphDiv to suite level
etpinard 4c5103f
send null on plotly_doubleclick events:
etpinard d517c4f
make doubleclick in select/lasso mode emit its own event: plotly_dese…
etpinard 90edb18
update click and select tests
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add select/lasso jasmine tests
- Loading branch information
commit d46ae26f89ef53de6bccebe1e2c6422c88e80846
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
var Plotly = require('@lib/index'); | ||
var Lib = require('@src/lib'); | ||
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY; | ||
|
||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var mouseEvent = require('../assets/mouse_event'); | ||
|
||
|
||
describe('select box and lasso', function() { | ||
var mock = require('@mocks/14.json'); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
function drag(path) { | ||
var len = path.length; | ||
|
||
mouseEvent('mousemove', path[0][0], path[0][1]); | ||
mouseEvent('mousedown', path[0][0], path[0][1]); | ||
|
||
path.slice(1, len).forEach(function(pt) { | ||
mouseEvent('mousemove', pt[0], pt[1]); | ||
}); | ||
|
||
mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]); | ||
} | ||
|
||
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); | ||
} | ||
|
||
describe('select events', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
mockCopy.layout.dragmode = 'select'; | ||
|
||
var gd; | ||
beforeEach(function(done) { | ||
gd = createGraphDiv(); | ||
|
||
Plotly.plot(gd, mockCopy.data, mockCopy.layout) | ||
.then(done); | ||
}); | ||
|
||
it('should trigger events', function(done) { | ||
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 add some comments as to the specifics of the test. It's not immediately clear what's being tested. 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. sure |
||
var selectingCnt = 0, | ||
selectingData; | ||
gd.on('plotly_selecting', function(data) { | ||
selectingCnt++; | ||
selectingData = data; | ||
}); | ||
|
||
var selectedCnt = 0, | ||
selectedData; | ||
gd.on('plotly_selected', function(data) { | ||
selectedCnt++; | ||
selectedData = data; | ||
}); | ||
|
||
var doubleClickData; | ||
gd.on('plotly_doubleclick', function(data) { | ||
doubleClickData = data; | ||
}); | ||
|
||
drag([[100, 200], [150, 200]]); | ||
|
||
expect(selectingCnt).toEqual(1); | ||
expect(selectingData.points).toEqual([{ | ||
curveNumber: 0, | ||
pointNumber: 0, | ||
x: 0.002, | ||
y: 16.25 | ||
}, { | ||
curveNumber: 0, | ||
pointNumber: 1, | ||
x: 0.004, | ||
y: 12.5 | ||
}]); | ||
expect(selectingData.range).toEqual({ | ||
x: [0.0019667582669138295, 0.004546754982054625], | ||
y: [0.10209191961595454, 24.512223978291406] | ||
}); | ||
|
||
expect(selectedCnt).toEqual(1); | ||
expect(selectedData.points).toEqual([{ | ||
curveNumber: 0, | ||
pointNumber: 0, | ||
x: 0.002, | ||
y: 16.25 | ||
}, { | ||
curveNumber: 0, | ||
pointNumber: 1, | ||
x: 0.004, | ||
y: 12.5 | ||
}]); | ||
expect(selectedData.range).toEqual({ | ||
x: [0.0019667582669138295, 0.004546754982054625], | ||
y: [0.10209191961595454, 24.512223978291406] | ||
}); | ||
|
||
doubleClick(250, 200, function() { | ||
expect(doubleClickData).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('lasso events', function() { | ||
var mockCopy = Lib.extendDeep({}, mock); | ||
mockCopy.layout.dragmode = 'lasso'; | ||
|
||
var gd; | ||
beforeEach(function(done) { | ||
gd = createGraphDiv(); | ||
|
||
Plotly.plot(gd, mockCopy.data, mockCopy.layout) | ||
.then(done); | ||
}); | ||
|
||
it('should trigger events', function(done) { | ||
var selectingCnt = 0, | ||
selectingData; | ||
gd.on('plotly_selecting', function(data) { | ||
selectingCnt++; | ||
selectingData = data; | ||
}); | ||
|
||
var selectedCnt = 0, | ||
selectedData; | ||
gd.on('plotly_selected', function(data) { | ||
selectedCnt++; | ||
selectedData = data; | ||
}); | ||
|
||
var doubleClickData; | ||
gd.on('plotly_doubleclick', function(data) { | ||
doubleClickData = data; | ||
}); | ||
|
||
drag([[331, 178], [333, 246], [350, 250], [343, 176]]); | ||
|
||
expect(selectingCnt).toEqual(3); | ||
expect(selectingData.points).toEqual([{ | ||
curveNumber: 0, | ||
pointNumber: 10, | ||
x: 0.099, | ||
y: 2.75 | ||
}]); | ||
|
||
expect(selectedCnt).toEqual(1); | ||
expect(selectedData.points).toEqual([{ | ||
curveNumber: 0, | ||
pointNumber: 10, | ||
x: 0.099, | ||
y: 2.75 | ||
}]); | ||
|
||
doubleClick(250, 200, function() { | ||
expect(doubleClickData).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a reason for using
mousedown
andmouseup
over justclick
?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.
See #176 (comment)
But yeah, I should mention why in the code too.