Skip to content

Commit 033eb39

Browse files
author
John Soklaski
committed
Add hoverinfo 'hide'
1 parent 7387b2b commit 033eb39

File tree

7 files changed

+73
-12
lines changed

7 files changed

+73
-12
lines changed

src/plots/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
valType: 'flaglist',
7373
role: 'info',
7474
flags: ['x', 'y', 'z', 'text', 'name'],
75-
extras: ['all', 'none'],
75+
extras: ['all', 'none', 'hide'],
7676
dflt: 'all',
7777
description: 'Determines which trace information appear on hover.'
7878
},

src/plots/cartesian/graph_interact.js

Lines changed: 4 additions & 2 deletions
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 !== 'none') {
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 !== 'none' && subplots.indexOf(getSubplot(trace)) !== -1) {
405407
searchData.push(cd);
406408
}
407409
}

src/traces/choropleth/plot.js

Lines changed: 1 addition & 1 deletion
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 === 'hide') {
169169
return function cleanHoverLabelsFunc(pt) {
170170
delete pt.nameLabel;
171171
delete pt.textLabel;

src/traces/pie/plot.js

Lines changed: 1 addition & 1 deletion
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 === 'hide' || !hoverinfo) {
100100
return;
101101
}
102102

src/traces/scattergeo/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ plotScatterGeo.style = function(geo) {
244244
function makeCleanHoverLabelsFunc(geo, trace) {
245245
var hoverinfo = trace.hoverinfo;
246246

247-
if(hoverinfo === 'none') {
247+
if(hoverinfo === 'none' || hoverinfo === 'hide') {
248248
return function cleanHoverLabelsFunc(d) { delete d.textLabel; };
249249
}
250250

test/jasmine/tests/click_test.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,28 @@ describe('Test click interactions:', function() {
8383
});
8484

8585
describe('click event with hoverinfo set to none - plotly_click', function() {
86-
var futureData;
86+
var futureData = null;
87+
88+
beforeEach(function(done) {
89+
90+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
91+
modifiedMockCopy.data[0].hoverinfo = 'none';
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 hover', function() {
101+
click(pointPos[0], pointPos[1]);
102+
expect(futureData).toEqual(null);
103+
});
104+
});
105+
106+
describe('click events with hoverinfo set to none - plotly_hover', function() {
107+
var futureData = null;
87108

88109
beforeEach(function(done) {
89110

@@ -92,12 +113,33 @@ describe('Test click interactions:', function() {
92113
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
93114
.then(done);
94115

116+
gd.on('plotly_hover', function(data) {
117+
futureData = data;
118+
});
119+
});
120+
121+
it('should not register the click', function() {
122+
click(pointPos[0], pointPos[1]);
123+
expect(futureData).toEqual(null);
124+
});
125+
});
126+
127+
describe('click event with hoverinfo set to hide - plotly_click', function() {
128+
var futureData;
129+
130+
beforeEach(function(done) {
131+
132+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
133+
modifiedMockCopy.data[0].hoverinfo = 'hide';
134+
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
135+
.then(done);
136+
95137
gd.on('plotly_click', function(data) {
96138
futureData = data;
97139
});
98140
});
99141

100-
it('should contain the correct fields despite hoverinfo: "none"', function() {
142+
it('should contain the correct fields despite hoverinfo: "hide"', function() {
101143
click(pointPos[0], pointPos[1]);
102144
expect(futureData.points.length).toEqual(1);
103145

@@ -113,13 +155,13 @@ describe('Test click interactions:', function() {
113155
});
114156
});
115157

116-
describe('click events with hoverinfo set to none - plotly_hover', function() {
158+
describe('click events with hoverinfo set to hide - plotly_hover', function() {
117159
var futureData;
118160

119161
beforeEach(function(done) {
120162

121163
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
122-
modifiedMockCopy.data[0].hoverinfo = 'none';
164+
modifiedMockCopy.data[0].hoverinfo = 'hide';
123165
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
124166
.then(done);
125167

@@ -128,7 +170,7 @@ describe('Test click interactions:', function() {
128170
});
129171
});
130172

131-
it('should contain the correct fields despite hoverinfo: "none"', function() {
173+
it('should contain the correct fields despite hoverinfo: "hide"', function() {
132174
click(pointPos[0], pointPos[1]);
133175
expect(futureData.points.length).toEqual(1);
134176

test/jasmine/tests/hover_label_test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,24 @@ describe('hover info', function() {
309309
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
310310
});
311311

312-
it('does not render if hover is set to none', function() {
312+
it('does not hover if hover info is set to none', function() {
313+
var gd = document.getElementById('graph');
314+
Fx.hover('graph', evt, 'xy');
315+
316+
expect(gd._hoverdata, undefined);
317+
});
318+
});
319+
320+
describe('hover info hide', function() {
321+
var mockCopy = Lib.extendDeep({}, mock);
322+
323+
mockCopy.data[0].hoverinfo = 'hide';
324+
325+
beforeEach(function(done) {
326+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
327+
});
328+
329+
it('does not render if hover is set to hide', function() {
313330
var gd = document.getElementById('graph');
314331
Fx.hover('graph', evt, 'xy');
315332

0 commit comments

Comments
 (0)