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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions test/jasmine/tests/sankey_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,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,
Expand All @@ -601,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!');
})
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)

.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);
});
});
});

Expand Down