-
-
Notifications
You must be signed in to change notification settings - Fork 2k
disable hover for sankey traces when hovermode is false #2949
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 all commits
edc20b0
45f06c4
98c18f8
aafa886
3d32b6f
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 |
|---|---|---|
|
|
@@ -388,16 +388,16 @@ describe('sankey tests', function() { | |
| describe('Test hover/click interactions:', function() { | ||
| afterEach(destroyGraphDiv); | ||
|
|
||
| function _hover(px, py) { | ||
| mouseEvent('mousemove', px, py); | ||
| mouseEvent('mouseover', px, py); | ||
| Lib.clearThrottle(); | ||
| } | ||
|
|
||
| it('should show the correct hover labels', function(done) { | ||
| var gd = createGraphDiv(); | ||
| var mockCopy = Lib.extendDeep({}, mock); | ||
|
|
||
| function _hover(px, py) { | ||
| mouseEvent('mousemove', px, py); | ||
| mouseEvent('mouseover', px, py); | ||
| Lib.clearThrottle(); | ||
| } | ||
|
|
||
| Plotly.plot(gd, mockCopy).then(function() { | ||
| _hover(404, 302); | ||
|
|
||
|
|
@@ -464,12 +464,6 @@ describe('sankey tests', function() { | |
| var mockCopy = Lib.extendDeep({}, mock); | ||
| delete mockCopy.data[0].link.label; | ||
|
|
||
| function _hover(px, py) { | ||
| mouseEvent('mousemove', px, py); | ||
| mouseEvent('mouseover', px, py); | ||
| Lib.clearThrottle(); | ||
| } | ||
|
|
||
| Plotly.plot(gd, mockCopy) | ||
| .then(function() { | ||
| _hover(450, 300); | ||
|
|
@@ -482,6 +476,22 @@ describe('sankey tests', function() { | |
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
|
|
||
| it('should not show labels if hovermode is false', function(done) { | ||
| var gd = createGraphDiv(); | ||
| var mockCopy = Lib.extendDeep({}, mock); | ||
|
|
||
| Plotly.plot(gd, mockCopy).then(function() { | ||
| return Plotly.relayout(gd, 'hovermode', false); | ||
| }) | ||
| .then(function() { | ||
| _hover(404, 302); | ||
|
|
||
| assertNoLabel(); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Test hover/click event data:', function() { | ||
|
|
@@ -527,44 +537,52 @@ describe('sankey tests', function() { | |
| mouseEvent('mouseout', pos[0], pos[1]); | ||
| }); | ||
|
|
||
| it('should output correct hover/click/unhover event data', function(done) { | ||
| var fig = Lib.extendDeep({}, mock); | ||
| function _assert(d, expectedPtData) { | ||
| expect(d.event).toBeDefined('original event reference'); | ||
|
|
||
| function _assert(d, expectedPtData) { | ||
| expect(d.event).toBeDefined('original event reference'); | ||
| var ptData = d.points[0]; | ||
| Object.keys(expectedPtData).forEach(function(k) { | ||
| expect(ptData[k]).toBe(expectedPtData[k], 'point data for ' + k); | ||
| }); | ||
| } | ||
|
|
||
| var ptData = d.points[0]; | ||
| Object.keys(expectedPtData).forEach(function(k) { | ||
| expect(ptData[k]).toBe(expectedPtData[k], 'point data for ' + k); | ||
| }); | ||
| } | ||
| it('should output correct click event data', function(done) { | ||
| var fig = Lib.extendDeep({}, mock); | ||
|
|
||
| Plotly.plot(gd, fig) | ||
| .then(function() { return _hover('node'); }) | ||
| .then(function() { return _click('node'); }) | ||
| .then(function(d) { | ||
| _assert(d, { | ||
| curveNumber: 0, | ||
| pointNumber: 4, | ||
| label: 'Solid' | ||
| }); | ||
| }) | ||
| .then(function() { return _hover('link'); }) | ||
| .then(function() { return _click('link'); }) | ||
| .then(function(d) { | ||
| _assert(d, { | ||
| curveNumber: 0, | ||
| pointNumber: 61, | ||
| value: 46.477 | ||
| }); | ||
| }) | ||
| .then(function() { return _click('node'); }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
|
|
||
| it('should output correct hover/unhover event data', function(done) { | ||
| var fig = Lib.extendDeep({}, mock); | ||
|
|
||
| Plotly.plot(gd, fig) | ||
| .then(function() { return _hover('node'); }) | ||
| .then(function(d) { | ||
| _assert(d, { | ||
| curveNumber: 0, | ||
| pointNumber: 4, | ||
| label: 'Solid' | ||
| }); | ||
| }) | ||
| .then(function() { return _click('link'); }) | ||
| .then(function() { return _hover('link'); }) | ||
| .then(function(d) { | ||
| _assert(d, { | ||
| curveNumber: 0, | ||
|
|
@@ -591,6 +609,30 @@ describe('sankey tests', function() { | |
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
|
|
||
| it('should not output hover/unhover event data when hovermoder is false', function(done) { | ||
| var fig = Lib.extendDeep({}, mock); | ||
|
|
||
| Plotly.plot(gd, fig) | ||
| .then(function() { return Plotly.relayout(gd, 'hovermode', false); }) | ||
| .then(function() { return _hover('node'); }) | ||
| .then(failTest).catch(function(err) { | ||
| expect(err).toBe('plotly_hover did not get called!'); | ||
| }) | ||
|
Collaborator
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. Ah, clever 🎉
Contributor
Author
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 returns: What would be preferred?
Collaborator
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. That looks great, assuming there's a line number along with it too, so you can tell it's the
Collaborator
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. (no it doesn't give a line number, but neither do our normal |
||
| .then(function() { return _unhover('node'); }) | ||
| .then(failTest).catch(function(err) { | ||
| expect(err).toBe('plotly_unhover did not get called!'); | ||
| }) | ||
| .then(function() { return _hover('link'); }) | ||
| .then(failTest).catch(function(err) { | ||
| expect(err).toBe('plotly_hover did not get called!'); | ||
| }) | ||
| .then(function() { return _unhover('link'); }) | ||
| .then(failTest).catch(function(err) { | ||
| expect(err).toBe('plotly_unhover did not get called!'); | ||
| }) | ||
| .then(done); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -620,3 +662,8 @@ function assertLabel(content, style) { | |
| fontColor: style[4] | ||
| }); | ||
| } | ||
|
|
||
| function assertNoLabel() { | ||
| var g = d3.selectAll('.hovertext'); | ||
| expect(g.size()).toBe(0); | ||
| } | ||
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.
Do we need to bail out of the
unhoverhandlers as well, to ensure that we don't emitplotly_unhoverevents? Or does this already avoid these events?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.
@alexcjohnson It was indeed emitting a bunch of
plotly_unhoverevents. It is fixed in my next commit.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! I guess then we should 🔒 the events too, by adding a
hovermode: falsecase to the click/hover events test