From acb23c7044106b61bb55569d4046b7d2ff68664b Mon Sep 17 00:00:00 2001 From: John Soklaski Date: Fri, 12 Aug 2016 08:45:22 -0700 Subject: [PATCH 1/3] Add hoverinfo skip --- src/plots/attributes.js | 2 +- src/plots/cartesian/graph_interact.js | 6 ++-- src/traces/choropleth/plot.js | 2 +- src/traces/pie/plot.js | 2 +- test/jasmine/tests/click_test.js | 42 ++++++++++++++++++++++++++ test/jasmine/tests/hover_label_test.js | 17 +++++++++++ 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/plots/attributes.js b/src/plots/attributes.js index 52b03c671ed..636a5747fb6 100644 --- a/src/plots/attributes.js +++ b/src/plots/attributes.js @@ -72,7 +72,7 @@ module.exports = { valType: 'flaglist', role: 'info', flags: ['x', 'y', 'z', 'text', 'name'], - extras: ['all', 'none'], + extras: ['all', 'none', 'skip'], dflt: 'all', description: 'Determines which trace information appear on hover.' }, diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index a367d6e65b3..f3f6ade5a14 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -394,14 +394,16 @@ function hover(gd, evt, subplot) { hovermode = 'array'; for(itemnum = 0; itemnum < evt.length; itemnum++) { cd = gd.calcdata[evt[itemnum].curveNumber||0]; - searchData.push(cd); + if(cd[0].trace.hoverinfo !== 'skip') { + searchData.push(cd); + } } } else { for(curvenum = 0; curvenum < gd.calcdata.length; curvenum++) { cd = gd.calcdata[curvenum]; trace = cd[0].trace; - if(subplots.indexOf(getSubplot(trace)) !== -1) { + if(trace.hoverinfo !== 'skip' && subplots.indexOf(getSubplot(trace)) !== -1) { searchData.push(cd); } } diff --git a/src/traces/choropleth/plot.js b/src/traces/choropleth/plot.js index b440f60cdf2..0393b55b15a 100644 --- a/src/traces/choropleth/plot.js +++ b/src/traces/choropleth/plot.js @@ -165,7 +165,7 @@ plotChoropleth.style = function(geo) { function makeCleanHoverLabelsFunc(geo, trace) { var hoverinfo = trace.hoverinfo; - if(hoverinfo === 'none') { + if(hoverinfo === 'none' || hoverinfo === 'skip') { return function cleanHoverLabelsFunc(pt) { delete pt.nameLabel; delete pt.textLabel; diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index e96c21fbf77..d50b0b307fb 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -96,7 +96,7 @@ module.exports = function plot(gd, cdpie) { // in case we dragged over the pie from another subplot, // or if hover is turned off if(gd._dragging || fullLayout2.hovermode === false || - hoverinfo === 'none' || !hoverinfo) { + hoverinfo === 'none' || hoverinfo === 'skip' || !hoverinfo) { return; } diff --git a/test/jasmine/tests/click_test.js b/test/jasmine/tests/click_test.js index 8dd517cdd15..d124fa17fca 100644 --- a/test/jasmine/tests/click_test.js +++ b/test/jasmine/tests/click_test.js @@ -82,6 +82,48 @@ describe('Test click interactions:', function() { }); }); + describe('click event with hoverinfo set to skip - plotly_click', function() { + var futureData = null; + + beforeEach(function(done) { + + var modifiedMockCopy = Lib.extendDeep({}, mockCopy); + modifiedMockCopy.data[0].hoverinfo = 'skip'; + Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout) + .then(done); + + gd.on('plotly_click', function(data) { + futureData = data; + }); + }); + + it('should not register the click', function() { + click(pointPos[0], pointPos[1]); + expect(futureData).toEqual(null); + }); + }); + + describe('click events with hoverinfo set to skip - plotly_hover', function() { + var futureData = null; + + beforeEach(function(done) { + + var modifiedMockCopy = Lib.extendDeep({}, mockCopy); + modifiedMockCopy.data[0].hoverinfo = 'skip'; + Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout) + .then(done); + + gd.on('plotly_hover', function(data) { + futureData = data; + }); + }); + + it('should not register the hover', function() { + click(pointPos[0], pointPos[1]); + expect(futureData).toEqual(null); + }); + }); + describe('click event with hoverinfo set to none - plotly_click', function() { var futureData; diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 8f4c71e0eae..7adf6db7d0a 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -300,6 +300,23 @@ describe('hover info', function() { }); }); + describe('hover info skip', function() { + var mockCopy = Lib.extendDeep({}, mock); + + mockCopy.data[0].hoverinfo = 'skip'; + + beforeEach(function(done) { + Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); + }); + + it('does not hover if hover info is set to skip', function() { + var gd = document.getElementById('graph'); + Fx.hover('graph', evt, 'xy'); + + expect(gd._hoverdata, undefined); + }); + }); + describe('hover info none', function() { var mockCopy = Lib.extendDeep({}, mock); From f19033f5686552a524db954756324a261db22443 Mon Sep 17 00:00:00 2001 From: John Soklaski Date: Fri, 12 Aug 2016 11:21:55 -0700 Subject: [PATCH 2/3] Support hoverinfo skip for gl2d and gl3d plots --- src/plots/gl2d/scene2d.js | 3 ++- src/plots/gl3d/scene.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plots/gl2d/scene2d.js b/src/plots/gl2d/scene2d.js index 0d33abebec8..d43003b4bd7 100644 --- a/src/plots/gl2d/scene2d.js +++ b/src/plots/gl2d/scene2d.js @@ -478,7 +478,7 @@ proto.draw = function() { (y / glplot.pixelRatio) - (size.t + (1 - domainY[1]) * size.h) ); - if(result && fullLayout.hovermode) { + if(result && result.object._trace.hoverinfo !== 'skip' && fullLayout.hovermode) { var nextSelection = result.object._trace.handlePick(result); if(nextSelection && ( @@ -488,6 +488,7 @@ proto.draw = function() { this.lastPickResult.dataCoord[1] !== nextSelection.dataCoord[1]) ) { var selection = nextSelection; + this.lastPickResult = { traceUid: nextSelection.trace ? nextSelection.trace.uid : null, dataCoord: nextSelection.dataCoord.slice() diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index f799c40543b..6c6c82dbff8 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -50,7 +50,7 @@ function render(scene) { var selection = scene.glplot.selection; for(var i = 0; i < keys.length; ++i) { trace = scene.traces[keys[i]]; - if(trace.handlePick(selection)) { + if(trace.data.hoverinfo !== 'skip' && trace.handlePick(selection)) { lastPicked = trace; } From db4ae7ecb15892bd3efd7e5ddb58c99782f36beb Mon Sep 17 00:00:00 2001 From: John Soklaski Date: Tue, 16 Aug 2016 13:51:07 -0700 Subject: [PATCH 3/3] Add description of 'none' and 'skip' flags --- src/plots/attributes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plots/attributes.js b/src/plots/attributes.js index 636a5747fb6..a9c09f810fd 100644 --- a/src/plots/attributes.js +++ b/src/plots/attributes.js @@ -74,7 +74,11 @@ module.exports = { flags: ['x', 'y', 'z', 'text', 'name'], extras: ['all', 'none', 'skip'], dflt: 'all', - description: 'Determines which trace information appear on hover.' + description: [ + 'Determines which trace information appear on hover.', + 'If `none` or `skip` are set, no information is displayed upon hovering.', + 'But, if `none` is set, click and hover events are still fired.' + ].join(' ') }, stream: { token: {