Skip to content

Commit 92e73fe

Browse files
authored
Merge pull request #851 from john-soklaski/hoverinfo_skip
Add hoverinfo skip
2 parents 9ffdcff + db4ae7e commit 92e73fe

File tree

8 files changed

+74
-8
lines changed

8 files changed

+74
-8
lines changed

src/plots/attributes.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ module.exports = {
7272
valType: 'flaglist',
7373
role: 'info',
7474
flags: ['x', 'y', 'z', 'text', 'name'],
75-
extras: ['all', 'none'],
75+
extras: ['all', 'none', 'skip'],
7676
dflt: 'all',
77-
description: 'Determines which trace information appear on hover.'
77+
description: [
78+
'Determines which trace information appear on hover.',
79+
'If `none` or `skip` are set, no information is displayed upon hovering.',
80+
'But, if `none` is set, click and hover events are still fired.'
81+
].join(' ')
7882
},
7983
stream: {
8084
token: {

src/plots/cartesian/graph_interact.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,16 @@ function hover(gd, evt, subplot) {
394394
hovermode = 'array';
395395
for(itemnum = 0; itemnum < evt.length; itemnum++) {
396396
cd = gd.calcdata[evt[itemnum].curveNumber||0];
397-
searchData.push(cd);
397+
if(cd[0].trace.hoverinfo !== 'skip') {
398+
searchData.push(cd);
399+
}
398400
}
399401
}
400402
else {
401403
for(curvenum = 0; curvenum < gd.calcdata.length; curvenum++) {
402404
cd = gd.calcdata[curvenum];
403405
trace = cd[0].trace;
404-
if(subplots.indexOf(getSubplot(trace)) !== -1) {
406+
if(trace.hoverinfo !== 'skip' && subplots.indexOf(getSubplot(trace)) !== -1) {
405407
searchData.push(cd);
406408
}
407409
}

src/plots/gl2d/scene2d.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ proto.draw = function() {
478478
(y / glplot.pixelRatio) - (size.t + (1 - domainY[1]) * size.h)
479479
);
480480

481-
if(result && fullLayout.hovermode) {
481+
if(result && result.object._trace.hoverinfo !== 'skip' && fullLayout.hovermode) {
482482
var nextSelection = result.object._trace.handlePick(result);
483483

484484
if(nextSelection && (
@@ -488,6 +488,7 @@ proto.draw = function() {
488488
this.lastPickResult.dataCoord[1] !== nextSelection.dataCoord[1])
489489
) {
490490
var selection = nextSelection;
491+
491492
this.lastPickResult = {
492493
traceUid: nextSelection.trace ? nextSelection.trace.uid : null,
493494
dataCoord: nextSelection.dataCoord.slice()

src/plots/gl3d/scene.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function render(scene) {
5050
var selection = scene.glplot.selection;
5151
for(var i = 0; i < keys.length; ++i) {
5252
trace = scene.traces[keys[i]];
53-
if(trace.handlePick(selection)) {
53+
if(trace.data.hoverinfo !== 'skip' && trace.handlePick(selection)) {
5454
lastPicked = trace;
5555
}
5656

src/traces/choropleth/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ plotChoropleth.style = function(geo) {
165165
function makeCleanHoverLabelsFunc(geo, trace) {
166166
var hoverinfo = trace.hoverinfo;
167167

168-
if(hoverinfo === 'none') {
168+
if(hoverinfo === 'none' || hoverinfo === 'skip') {
169169
return function cleanHoverLabelsFunc(pt) {
170170
delete pt.nameLabel;
171171
delete pt.textLabel;

src/traces/pie/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = function plot(gd, cdpie) {
9696
// in case we dragged over the pie from another subplot,
9797
// or if hover is turned off
9898
if(gd._dragging || fullLayout2.hovermode === false ||
99-
hoverinfo === 'none' || !hoverinfo) {
99+
hoverinfo === 'none' || hoverinfo === 'skip' || !hoverinfo) {
100100
return;
101101
}
102102

test/jasmine/tests/click_test.js

+42
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ describe('Test click interactions:', function() {
8282
});
8383
});
8484

85+
describe('click event with hoverinfo set to skip - plotly_click', function() {
86+
var futureData = null;
87+
88+
beforeEach(function(done) {
89+
90+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
91+
modifiedMockCopy.data[0].hoverinfo = 'skip';
92+
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
93+
.then(done);
94+
95+
gd.on('plotly_click', function(data) {
96+
futureData = data;
97+
});
98+
});
99+
100+
it('should not register the click', function() {
101+
click(pointPos[0], pointPos[1]);
102+
expect(futureData).toEqual(null);
103+
});
104+
});
105+
106+
describe('click events with hoverinfo set to skip - plotly_hover', function() {
107+
var futureData = null;
108+
109+
beforeEach(function(done) {
110+
111+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
112+
modifiedMockCopy.data[0].hoverinfo = 'skip';
113+
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
114+
.then(done);
115+
116+
gd.on('plotly_hover', function(data) {
117+
futureData = data;
118+
});
119+
});
120+
121+
it('should not register the hover', function() {
122+
click(pointPos[0], pointPos[1]);
123+
expect(futureData).toEqual(null);
124+
});
125+
});
126+
85127
describe('click event with hoverinfo set to none - plotly_click', function() {
86128
var futureData;
87129

test/jasmine/tests/hover_label_test.js

+17
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ describe('hover info', function() {
300300
});
301301
});
302302

303+
describe('hover info skip', function() {
304+
var mockCopy = Lib.extendDeep({}, mock);
305+
306+
mockCopy.data[0].hoverinfo = 'skip';
307+
308+
beforeEach(function(done) {
309+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
310+
});
311+
312+
it('does not hover if hover info is set to skip', function() {
313+
var gd = document.getElementById('graph');
314+
Fx.hover('graph', evt, 'xy');
315+
316+
expect(gd._hoverdata, undefined);
317+
});
318+
});
319+
303320
describe('hover info none', function() {
304321
var mockCopy = Lib.extendDeep({}, mock);
305322

0 commit comments

Comments
 (0)