-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Pie-chart hover events #150
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d99634
Fixed promise return (Promise.resolve is not a constructor)
mdtusz ab2ebf4
Re-set autobins after supplying defaulys if initially set
mdtusz 8273bea
add condition for hover events on pie charts
mdtusz b512566
Add call to fx.hover onhover
mdtusz b89720b
Whoops. Undo changes from a different branch
mdtusz 6ade9de
Mouse simulation function for testing
mdtusz b8527bd
pie chart hover tests
mdtusz ac887f1
Removed unnecessary console.log
mdtusz 6bdfdbb
Fix test to work on ff and chrome
mdtusz 8e511fc
remove fdescribe test
mdtusz 66eade7
Changed hover event to check if subplot === pie
mdtusz 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
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
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
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,6 @@ | ||
module.exports = function (type, x, y, opts) { | ||
var el = document.elementFromPoint(x,y); | ||
var options = opts || { bubbles: true }; | ||
var ev = new window.MouseEvent(type, options); | ||
el.dispatchEvent(ev); | ||
}; |
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,78 @@ | ||
var Plotly = require('@src/index'); | ||
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'); | ||
|
||
describe('pie hovering', function () { | ||
var mock = require('@mocks/pie_simple.json'); | ||
|
||
describe('event data', function () { | ||
var mockCopy = Lib.extendDeep({}, mock), | ||
width = mockCopy.layout.width, | ||
height = mockCopy.layout.height, | ||
gd; | ||
|
||
beforeEach(function (done) { | ||
gd = createGraphDiv(); | ||
|
||
Plotly.plot(gd, mockCopy.data, mockCopy.layout) | ||
.then(done); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
it('should contain the correct fields', function () { | ||
|
||
var expected = [{ | ||
v: 4, | ||
label: '3', | ||
color: '#ff7f0e', | ||
i: 3, | ||
hidden: false, | ||
text: '26.7%', | ||
px1: [0,-60], | ||
pxmid: [-44.588689528643656,-40.14783638153149], | ||
midangle: -0.8377580409572781, | ||
px0: [-59.67131372209641,6.2717077960592], | ||
largeArc: 0, | ||
cxFinal: 200, | ||
cyFinal: 160 | ||
}], | ||
futureData; | ||
|
||
|
||
gd.on('plotly_hover', function (data) { | ||
futureData = data; | ||
}); | ||
|
||
mouseEvent('mouseover', width / 2, height / 2); | ||
expect(futureData.points.length).toEqual(1); | ||
expect(Object.keys(futureData.points[0])).toEqual([ | ||
'v', 'label', 'color', 'i', 'hidden', | ||
'text', 'px1', 'pxmid', 'midangle', | ||
'px0', 'largeArc', 'cxFinal', 'cyFinal' | ||
]); | ||
expect(futureData.points[0].i).toEqual(3); | ||
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. yep, that's all we need to test here. |
||
}); | ||
|
||
it('should fire when moving from one slice to another', function (done) { | ||
var count = 0 | ||
futureData = []; | ||
|
||
gd.on('plotly_hover', function (data) { | ||
count++; | ||
futureData.push(data); | ||
}); | ||
|
||
mouseEvent('mouseover', 180, 140); | ||
setTimeout(function () { | ||
mouseEvent('mouseover', 240, 200); | ||
expect(count).toEqual(2); | ||
expect(futureData[0]).not.toEqual(futureData[1]) | ||
done(); | ||
}, 100); | ||
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. Great test! |
||
}); | ||
}); | ||
}); |
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.
great. 🍻