Skip to content

Commit 4651f3e

Browse files
committed
Merge pull request #438 from monfera/313-hoverinfo-none-callbacks-squashed
Click, hover callbacks should work despite hoverinfo = none, fixes #313
2 parents 7d7e948 + 1c6014a commit 4651f3e

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

src/plots/cartesian/graph_interact.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ function hover(gd, evt, subplot) {
371371
hovermode = 'array';
372372
for(itemnum = 0; itemnum<evt.length; itemnum++) {
373373
cd = gd.calcdata[evt[itemnum].curveNumber||0];
374-
if(cd[0].trace.hoverinfo!=='none') searchData.push(cd);
374+
searchData.push(cd);
375375
}
376376
}
377377
else {
378378
for(curvenum = 0; curvenum<gd.calcdata.length; curvenum++) {
379379
cd = gd.calcdata[curvenum];
380380
trace = cd[0].trace;
381-
if(trace.hoverinfo!=='none' && subplots.indexOf(getSubplot(trace))!==-1) {
381+
if(subplots.indexOf(getSubplot(trace))!==-1) {
382382
searchData.push(cd);
383383
}
384384
}

test/jasmine/tests/click_test.js

+62
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,68 @@ describe('Test click interactions:', function() {
9696
});
9797
});
9898

99+
describe('click event with hoverinfo set to none - plotly_click', function() {
100+
var futureData;
101+
102+
beforeEach(function(done) {
103+
104+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
105+
modifiedMockCopy.data[0].hoverinfo = 'none';
106+
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
107+
.then(done);
108+
109+
gd.on('plotly_click', function(data) {
110+
futureData = data;
111+
});
112+
});
113+
114+
it('should contain the correct fields despite hoverinfo: "none"', function() {
115+
click(pointPos[0], pointPos[1]);
116+
expect(futureData.points.length).toEqual(1);
117+
118+
var pt = futureData.points[0];
119+
expect(Object.keys(pt)).toEqual([
120+
'data', 'fullData', 'curveNumber', 'pointNumber',
121+
'x', 'y', 'xaxis', 'yaxis'
122+
]);
123+
expect(pt.curveNumber).toEqual(0);
124+
expect(pt.pointNumber).toEqual(11);
125+
expect(pt.x).toEqual(0.125);
126+
expect(pt.y).toEqual(2.125);
127+
});
128+
});
129+
130+
describe('click events with hoverinfo set to none - plotly_hover', function() {
131+
var futureData;
132+
133+
beforeEach(function(done) {
134+
135+
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
136+
modifiedMockCopy.data[0].hoverinfo = 'none';
137+
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
138+
.then(done);
139+
140+
gd.on('plotly_hover', function(data) {
141+
futureData = data;
142+
});
143+
});
144+
145+
it('should contain the correct fields despite hoverinfo: "none"', function() {
146+
click(pointPos[0], pointPos[1]);
147+
expect(futureData.points.length).toEqual(1);
148+
149+
var pt = futureData.points[0];
150+
expect(Object.keys(pt)).toEqual([
151+
'data', 'fullData', 'curveNumber', 'pointNumber',
152+
'x', 'y', 'xaxis', 'yaxis'
153+
]);
154+
expect(pt.curveNumber).toEqual(0);
155+
expect(pt.pointNumber).toEqual(11);
156+
expect(pt.x).toEqual(0.125);
157+
expect(pt.y).toEqual(2.125);
158+
});
159+
});
160+
99161
describe('double click events', function() {
100162
var futureData;
101163

test/jasmine/tests/gl_plot_interact_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Test gl plot interactions', function() {
5252
destroyGraphDiv();
5353
});
5454

55-
// ...
55+
// put callback in the event queue
5656
function delay(done) {
5757
setTimeout(done, 0);
5858
}

test/jasmine/tests/hover_label_test.js

+25
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,31 @@ describe('hover info', function() {
244244
});
245245
});
246246

247+
describe('hover info none', function() {
248+
var mockCopy = Lib.extendDeep({}, mock);
249+
250+
mockCopy.data[0].hoverinfo = 'none';
251+
252+
beforeEach(function(done) {
253+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
254+
});
255+
256+
it('does not render if hover is set to none', function() {
257+
var gd = document.getElementById('graph');
258+
Fx.hover('graph', evt, 'xy');
259+
260+
var hoverTrace = gd._hoverdata[0];
261+
262+
expect(hoverTrace.curveNumber).toEqual(0);
263+
expect(hoverTrace.pointNumber).toEqual(17);
264+
expect(hoverTrace.x).toEqual(0.388);
265+
expect(hoverTrace.y).toEqual(1);
266+
267+
expect(d3.selectAll('g.axistext').size()).toEqual(0);
268+
expect(d3.selectAll('g.hovertext').size()).toEqual(0);
269+
});
270+
});
271+
247272
describe('hoverformat', function() {
248273

249274
var data = [{

0 commit comments

Comments
 (0)