Skip to content

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

Merged
merged 5 commits into from
Aug 29, 2018

Conversation

antoinerg
Copy link
Contributor

Fixes #2782

Simple fix: hover handler functions now simply return if hovermode is false.

cc @etpinard


function assertNoLabel() {
var g = d3.selectAll('.hovertext');
expect(g[0].length).toBe(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g.size() is better than g[0].length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

mouseEvent('mousemove', px, py);
mouseEvent('mouseover', px, py);
Lib.clearThrottle();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we push this to an outer scope so we're not just repeating the function from above?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh I see, it was already duplicated - great, we can clean them all up into just one _hover

push _hover into outer scope. use d3 size() instead of manually checking objects length.
@@ -143,6 +144,7 @@ module.exports = function plot(gd, calcData) {
var outgoingLabel = _(gd, 'outgoing flow count:') + ' ';

var linkHoverFollow = function(element, d) {
if(gd._fullLayout.hovermode === false) return;
Copy link
Collaborator

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 unhover handlers as well, to ensure that we don't emit plotly_unhover events? Or does this already avoid these events?

Copy link
Contributor Author

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_unhover events. It is fixed in my next commit.

Copy link
Collaborator

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: false case to the click/hover events test

.then(function() { return _hover('node'); })
.then(failTest).catch(function(err) {
expect(err).toBe('plotly_hover did not get called!');
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, clever 🎉
Does failTest give an intelligible message if we get there? ie if we run this test without your previous commit, would it be clear what went wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns: Chrome 68.0.3440 (Windows 10 0.0.0) sankey tests Test hover/click event data: should not output hover/unhover event data when hovermoder is false FAILED
followed by:
Expected Object({ event: [object MouseEvent], points: [ Object({ pointNumber: 4, label: 'Solid', color: 'rgba(148, 103, 189, 0.8)', sourceLinks: [ Object({ pointNumber: 60, label: '', color: 'rgba(0,0,96,0.2)', source: <circular reference: Object>, target: Object({ pointNumber: 26, label: 'Thermal generation', color: 'rgba(227, 119, 194, 0.8)', sourceLinks: [ Object({ pointNumber: 63, label: '', color: 'rgba(0,0,96,0.2)', source: <circular reference: Object>, target: Object, value: 787.129, originalIndex: 63, dy: 84.76807405050613, ty: 0, sy: 0, trace: Object, curveNumber: 0 }), Object({ pointNumber: 62, label: '', color: 'rgba(0,0,96,0.2)', source: <circular reference: Object>, target: Object, value: 525.531, originalIndex: 62, dy: 56.595870211663566, ty: 0, sy: 84.76807405050613, trace: Object, curveNumber: 0 }), Object({ pointNumber: 64, label: '', color: 'rgba(0,0,96,0.2)', source: <circular reference: Object>, target: Object, value: 79.329, originalIndex: 64, dy: 8.543156898491352, ty: 0, ... to be undefined.

What would be preferred?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 _hover on line 618 that caused the failure.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 failTest invocations... lets leave it as is at least for now)

@alexcjohnson
Copy link
Collaborator

Nicely done @antoinerg! 💃

@antoinerg antoinerg merged commit 19f3800 into master Aug 29, 2018
@antoinerg antoinerg deleted the 2782-sankey-disable-hover branch August 29, 2018 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hoverinfo 'none' and 'skip' do not work with sankey traces
2 participants