Skip to content

Commit 69c11fe

Browse files
committed
implement hoverinfo 'none' and 'skip' in sankey
1 parent d340150 commit 69c11fe

File tree

2 files changed

+83
-22
lines changed

2 files changed

+83
-22
lines changed

src/traces/sankey/plot.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ module.exports = function plot(gd, calcData) {
132132
var linkHover = function(element, d, sankey) {
133133
if(gd._fullLayout.hovermode === false) return;
134134
d3.select(element).call(linkHoveredStyle.bind(0, d, sankey, true));
135-
gd.emit('plotly_hover', {
136-
event: d3.event,
137-
points: [d.link]
138-
});
135+
if(d.link.trace.hoverinfo !== 'skip') {
136+
gd.emit('plotly_hover', {
137+
event: d3.event,
138+
points: [d.link]
139+
});
140+
}
141+
139142
};
140143

141144
var sourceLabel = _(gd, 'source:') + ' ';
@@ -146,6 +149,7 @@ module.exports = function plot(gd, calcData) {
146149
var linkHoverFollow = function(element, d) {
147150
if(gd._fullLayout.hovermode === false) return;
148151
var trace = d.link.trace;
152+
if(trace.hoverinfo === 'none' || trace.hoverinfo === 'skip') return;
149153
var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect();
150154
var boundingBox = element.getBoundingClientRect();
151155
var hoverCenterX = boundingBox.left + boundingBox.width / 2;
@@ -179,10 +183,12 @@ module.exports = function plot(gd, calcData) {
179183
var linkUnhover = function(element, d, sankey) {
180184
if(gd._fullLayout.hovermode === false) return;
181185
d3.select(element).call(linkNonHoveredStyle.bind(0, d, sankey, true));
182-
gd.emit('plotly_unhover', {
183-
event: d3.event,
184-
points: [d.link]
185-
});
186+
if(d.link.trace.hoverinfo !== 'skip') {
187+
gd.emit('plotly_unhover', {
188+
event: d3.event,
189+
points: [d.link]
190+
});
191+
}
186192

187193
Fx.loneUnhover(fullLayout._hoverlayer.node());
188194
};
@@ -198,15 +204,19 @@ module.exports = function plot(gd, calcData) {
198204
var nodeHover = function(element, d, sankey) {
199205
if(gd._fullLayout.hovermode === false) return;
200206
d3.select(element).call(nodeHoveredStyle, d, sankey);
201-
gd.emit('plotly_hover', {
202-
event: d3.event,
203-
points: [d.node]
204-
});
207+
if(d.node.trace.hoverinfo !== 'skip') {
208+
gd.emit('plotly_hover', {
209+
event: d3.event,
210+
points: [d.node]
211+
});
212+
}
205213
};
206214

207215
var nodeHoverFollow = function(element, d) {
208216
if(gd._fullLayout.hovermode === false) return;
217+
209218
var trace = d.node.trace;
219+
if(trace.hoverinfo === 'none' || trace.hoverinfo === 'skip') return;
210220
var nodeRect = d3.select(element).select('.' + cn.nodeRect);
211221
var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect();
212222
var boundingBox = nodeRect.node().getBoundingClientRect();
@@ -243,10 +253,12 @@ module.exports = function plot(gd, calcData) {
243253
var nodeUnhover = function(element, d, sankey) {
244254
if(gd._fullLayout.hovermode === false) return;
245255
d3.select(element).call(nodeNonHoveredStyle, d, sankey);
246-
gd.emit('plotly_unhover', {
247-
event: d3.event,
248-
points: [d.node]
249-
});
256+
if(d.node.trace.hoverinfo !== 'skip') {
257+
gd.emit('plotly_unhover', {
258+
event: d3.event,
259+
points: [d.node]
260+
});
261+
}
250262

251263
Fx.loneUnhover(fullLayout._hoverlayer.node());
252264
};

test/jasmine/tests/sankey_test.js

+55-6
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,38 @@ describe('sankey tests', function() {
492492
.catch(failTest)
493493
.then(done);
494494
});
495+
496+
it('should not show labels if hoverinfo is none', function(done) {
497+
var gd = createGraphDiv();
498+
var mockCopy = Lib.extendDeep({}, mock);
499+
500+
Plotly.plot(gd, mockCopy).then(function() {
501+
return Plotly.restyle(gd, 'hoverinfo', 'none');
502+
})
503+
.then(function() {
504+
_hover(404, 302);
505+
506+
assertNoLabel();
507+
})
508+
.catch(failTest)
509+
.then(done);
510+
});
511+
512+
it('should not show labels if hoverinfo is skip', function(done) {
513+
var gd = createGraphDiv();
514+
var mockCopy = Lib.extendDeep({}, mock);
515+
516+
Plotly.plot(gd, mockCopy).then(function() {
517+
return Plotly.restyle(gd, 'hoverinfo', 'skip');
518+
})
519+
.then(function() {
520+
_hover(404, 302);
521+
522+
assertNoLabel();
523+
})
524+
.catch(failTest)
525+
.then(done);
526+
});
495527
});
496528

497529
describe('Test hover/click event data:', function() {
@@ -574,6 +606,7 @@ describe('sankey tests', function() {
574606
var fig = Lib.extendDeep({}, mock);
575607

576608
Plotly.plot(gd, fig)
609+
.then(function() { return Plotly.restyle(gd, 'hoverinfo', 'none'); })
577610
.then(function() { return _hover('node'); })
578611
.then(function(d) {
579612
_assert(d, {
@@ -610,11 +643,8 @@ describe('sankey tests', function() {
610643
.then(done);
611644
});
612645

613-
it('should not output hover/unhover event data when hovermoder is false', function(done) {
614-
var fig = Lib.extendDeep({}, mock);
615-
616-
Plotly.plot(gd, fig)
617-
.then(function() { return Plotly.relayout(gd, 'hovermode', false); })
646+
function assertNoHoverEvents() {
647+
return Promise.resolve()
618648
.then(function() { return _hover('node'); })
619649
.then(failTest).catch(function(err) {
620650
expect(err).toBe('plotly_hover did not get called!');
@@ -630,7 +660,26 @@ describe('sankey tests', function() {
630660
.then(function() { return _unhover('link'); })
631661
.then(failTest).catch(function(err) {
632662
expect(err).toBe('plotly_unhover did not get called!');
633-
})
663+
});
664+
}
665+
666+
it('should not output hover/unhover event data when hovermoder is false', function(done) {
667+
var fig = Lib.extendDeep({}, mock);
668+
669+
Plotly.plot(gd, fig)
670+
.then(function() { return Plotly.relayout(gd, 'hovermode', false); })
671+
.then(assertNoHoverEvents)
672+
.catch(failTest)
673+
.then(done);
674+
});
675+
676+
it('should not output hover/unhover event data when hoverinfo is skip', function(done) {
677+
var fig = Lib.extendDeep({}, mock);
678+
679+
Plotly.plot(gd, fig)
680+
.then(function() { return Plotly.restyle(gd, 'hoverinfo', 'skip'); })
681+
.then(assertNoHoverEvents)
682+
.catch(failTest)
634683
.then(done);
635684
});
636685
});

0 commit comments

Comments
 (0)