Skip to content

Commit

Permalink
Merge pull request #438 from monfera/313-hoverinfo-none-callbacks-squ…
Browse files Browse the repository at this point in the history
…ashed

Click, hover callbacks should work despite hoverinfo = none, fixes #313
  • Loading branch information
etpinard committed Apr 18, 2016
2 parents 7d7e948 + 1c6014a commit 4651f3e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ function hover(gd, evt, subplot) {
hovermode = 'array';
for(itemnum = 0; itemnum<evt.length; itemnum++) {
cd = gd.calcdata[evt[itemnum].curveNumber||0];
if(cd[0].trace.hoverinfo!=='none') searchData.push(cd);
searchData.push(cd);
}
}
else {
for(curvenum = 0; curvenum<gd.calcdata.length; curvenum++) {
cd = gd.calcdata[curvenum];
trace = cd[0].trace;
if(trace.hoverinfo!=='none' && subplots.indexOf(getSubplot(trace))!==-1) {
if(subplots.indexOf(getSubplot(trace))!==-1) {
searchData.push(cd);
}
}
Expand Down
62 changes: 62 additions & 0 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,68 @@ describe('Test click interactions:', function() {
});
});

describe('click event with hoverinfo set to none - plotly_click', function() {
var futureData;

beforeEach(function(done) {

var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
modifiedMockCopy.data[0].hoverinfo = 'none';
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
.then(done);

gd.on('plotly_click', function(data) {
futureData = data;
});
});

it('should contain the correct fields despite hoverinfo: "none"', function() {
click(pointPos[0], pointPos[1]);
expect(futureData.points.length).toEqual(1);

var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber',
'x', 'y', 'xaxis', 'yaxis'
]);
expect(pt.curveNumber).toEqual(0);
expect(pt.pointNumber).toEqual(11);
expect(pt.x).toEqual(0.125);
expect(pt.y).toEqual(2.125);
});
});

describe('click events with hoverinfo set to none - plotly_hover', function() {
var futureData;

beforeEach(function(done) {

var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
modifiedMockCopy.data[0].hoverinfo = 'none';
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
.then(done);

gd.on('plotly_hover', function(data) {
futureData = data;
});
});

it('should contain the correct fields despite hoverinfo: "none"', function() {
click(pointPos[0], pointPos[1]);
expect(futureData.points.length).toEqual(1);

var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber',
'x', 'y', 'xaxis', 'yaxis'
]);
expect(pt.curveNumber).toEqual(0);
expect(pt.pointNumber).toEqual(11);
expect(pt.x).toEqual(0.125);
expect(pt.y).toEqual(2.125);
});
});

describe('double click events', function() {
var futureData;

Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Test gl plot interactions', function() {
destroyGraphDiv();
});

// ...
// put callback in the event queue
function delay(done) {
setTimeout(done, 0);
}
Expand Down
25 changes: 25 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ describe('hover info', function() {
});
});

describe('hover info none', function() {
var mockCopy = Lib.extendDeep({}, mock);

mockCopy.data[0].hoverinfo = 'none';

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
});

it('does not render if hover is set to none', function() {
var gd = document.getElementById('graph');
Fx.hover('graph', evt, 'xy');

var hoverTrace = gd._hoverdata[0];

expect(hoverTrace.curveNumber).toEqual(0);
expect(hoverTrace.pointNumber).toEqual(17);
expect(hoverTrace.x).toEqual(0.388);
expect(hoverTrace.y).toEqual(1);

expect(d3.selectAll('g.axistext').size()).toEqual(0);
expect(d3.selectAll('g.hovertext').size()).toEqual(0);
});
});

describe('hoverformat', function() {

var data = [{
Expand Down

0 comments on commit 4651f3e

Please sign in to comment.