From edc20b0601cfb033366493b871ce37d5c37fbaa4 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 28 Aug 2018 11:04:11 -0400 Subject: [PATCH 1/5] disable hover when hovermode is false --- src/traces/sankey/plot.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/traces/sankey/plot.js b/src/traces/sankey/plot.js index bfb9c70fbec..9d4959d1110 100644 --- a/src/traces/sankey/plot.js +++ b/src/traces/sankey/plot.js @@ -130,6 +130,7 @@ module.exports = function plot(gd, calcData) { }; var linkHover = function(element, d, sankey) { + if(gd._fullLayout.hovermode === false) return; d3.select(element).call(linkHoveredStyle.bind(0, d, sankey, true)); gd.emit('plotly_hover', { event: d3.event, @@ -143,6 +144,7 @@ module.exports = function plot(gd, calcData) { var outgoingLabel = _(gd, 'outgoing flow count:') + ' '; var linkHoverFollow = function(element, d) { + if(gd._fullLayout.hovermode === false) return; var trace = d.link.trace; var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect(); var boundingBox = element.getBoundingClientRect(); @@ -193,6 +195,7 @@ module.exports = function plot(gd, calcData) { }; var nodeHover = function(element, d, sankey) { + if(gd._fullLayout.hovermode === false) return; d3.select(element).call(nodeHoveredStyle, d, sankey); gd.emit('plotly_hover', { event: d3.event, @@ -201,6 +204,7 @@ module.exports = function plot(gd, calcData) { }; var nodeHoverFollow = function(element, d) { + if(gd._fullLayout.hovermode === false) return; var trace = d.node.trace; var nodeRect = d3.select(element).select('.' + cn.nodeRect); var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect(); From 45f06c447af2bc6b5e7196b2b949d6b4b4737ca6 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 28 Aug 2018 13:31:53 -0400 Subject: [PATCH 2/5] sankey test that labels are not shown when hovermode is false --- test/jasmine/tests/sankey_test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index d29d1967bc0..c0ee6b09e24 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -482,6 +482,28 @@ describe('sankey tests', function() { .catch(failTest) .then(done); }); + + it('should not show labels if hovermode is false', function(done) { + var gd = createGraphDiv(); + var mockCopy = Lib.extendDeep({}, mock); + + function _hover(px, py) { + mouseEvent('mousemove', px, py); + mouseEvent('mouseover', px, py); + Lib.clearThrottle(); + } + + Plotly.plot(gd, mockCopy).then(function() { + return Plotly.relayout(gd, 'hovermode', false); + }) + .then(function() { + _hover(404, 302); + + assertNoLabel(); + }) + .catch(failTest) + .then(done); + }); }); describe('Test hover/click event data:', function() { @@ -620,3 +642,8 @@ function assertLabel(content, style) { fontColor: style[4] }); } + +function assertNoLabel() { + var g = d3.selectAll('.hovertext'); + expect(g[0].length).toBe(0); +} From 98c18f826cd87b07b4fcfdd8f3627cae92523488 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 28 Aug 2018 14:30:12 -0400 Subject: [PATCH 3/5] clean up sankey test push _hover into outer scope. use d3 size() instead of manually checking objects length. --- test/jasmine/tests/sankey_test.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index c0ee6b09e24..ce8abb3f938 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -388,16 +388,16 @@ describe('sankey tests', function() { describe('Test hover/click interactions:', function() { afterEach(destroyGraphDiv); + function _hover(px, py) { + mouseEvent('mousemove', px, py); + mouseEvent('mouseover', px, py); + Lib.clearThrottle(); + } + it('should show the correct hover labels', function(done) { var gd = createGraphDiv(); var mockCopy = Lib.extendDeep({}, mock); - function _hover(px, py) { - mouseEvent('mousemove', px, py); - mouseEvent('mouseover', px, py); - Lib.clearThrottle(); - } - Plotly.plot(gd, mockCopy).then(function() { _hover(404, 302); @@ -464,12 +464,6 @@ describe('sankey tests', function() { var mockCopy = Lib.extendDeep({}, mock); delete mockCopy.data[0].link.label; - function _hover(px, py) { - mouseEvent('mousemove', px, py); - mouseEvent('mouseover', px, py); - Lib.clearThrottle(); - } - Plotly.plot(gd, mockCopy) .then(function() { _hover(450, 300); @@ -487,12 +481,6 @@ describe('sankey tests', function() { var gd = createGraphDiv(); var mockCopy = Lib.extendDeep({}, mock); - function _hover(px, py) { - mouseEvent('mousemove', px, py); - mouseEvent('mouseover', px, py); - Lib.clearThrottle(); - } - Plotly.plot(gd, mockCopy).then(function() { return Plotly.relayout(gd, 'hovermode', false); }) @@ -645,5 +633,5 @@ function assertLabel(content, style) { function assertNoLabel() { var g = d3.selectAll('.hovertext'); - expect(g[0].length).toBe(0); + expect(g.size()).toBe(0); } From aafa886f29cb2d948348b095428bb235b475cad7 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 28 Aug 2018 15:46:30 -0400 Subject: [PATCH 4/5] bail out of the unhover handlers if hovermode is false --- src/traces/sankey/plot.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/traces/sankey/plot.js b/src/traces/sankey/plot.js index 9d4959d1110..150cff65b9f 100644 --- a/src/traces/sankey/plot.js +++ b/src/traces/sankey/plot.js @@ -177,6 +177,7 @@ module.exports = function plot(gd, calcData) { }; var linkUnhover = function(element, d, sankey) { + if(gd._fullLayout.hovermode === false) return; d3.select(element).call(linkNonHoveredStyle.bind(0, d, sankey, true)); gd.emit('plotly_unhover', { event: d3.event, @@ -240,6 +241,7 @@ module.exports = function plot(gd, calcData) { }; var nodeUnhover = function(element, d, sankey) { + if(gd._fullLayout.hovermode === false) return; d3.select(element).call(nodeNonHoveredStyle, d, sankey); gd.emit('plotly_unhover', { event: d3.event, From 3d32b6ff869c4a90c93039bff017b1e85ac48ec9 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 28 Aug 2018 17:01:08 -0400 Subject: [PATCH 5/5] sankey test: adding a hovermode: false case to the click/hover events --- test/jasmine/tests/sankey_test.js | 58 ++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index ce8abb3f938..f2f26d3a2c1 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -537,20 +537,20 @@ describe('sankey tests', function() { mouseEvent('mouseout', pos[0], pos[1]); }); - it('should output correct hover/click/unhover event data', function(done) { - var fig = Lib.extendDeep({}, mock); + function _assert(d, expectedPtData) { + expect(d.event).toBeDefined('original event reference'); - function _assert(d, expectedPtData) { - expect(d.event).toBeDefined('original event reference'); + var ptData = d.points[0]; + Object.keys(expectedPtData).forEach(function(k) { + expect(ptData[k]).toBe(expectedPtData[k], 'point data for ' + k); + }); + } - var ptData = d.points[0]; - Object.keys(expectedPtData).forEach(function(k) { - expect(ptData[k]).toBe(expectedPtData[k], 'point data for ' + k); - }); - } + it('should output correct click event data', function(done) { + var fig = Lib.extendDeep({}, mock); Plotly.plot(gd, fig) - .then(function() { return _hover('node'); }) + .then(function() { return _click('node'); }) .then(function(d) { _assert(d, { curveNumber: 0, @@ -558,7 +558,7 @@ describe('sankey tests', function() { label: 'Solid' }); }) - .then(function() { return _hover('link'); }) + .then(function() { return _click('link'); }) .then(function(d) { _assert(d, { curveNumber: 0, @@ -566,7 +566,15 @@ describe('sankey tests', function() { value: 46.477 }); }) - .then(function() { return _click('node'); }) + .catch(failTest) + .then(done); + }); + + it('should output correct hover/unhover event data', function(done) { + var fig = Lib.extendDeep({}, mock); + + Plotly.plot(gd, fig) + .then(function() { return _hover('node'); }) .then(function(d) { _assert(d, { curveNumber: 0, @@ -574,7 +582,7 @@ describe('sankey tests', function() { label: 'Solid' }); }) - .then(function() { return _click('link'); }) + .then(function() { return _hover('link'); }) .then(function(d) { _assert(d, { curveNumber: 0, @@ -601,6 +609,30 @@ describe('sankey tests', function() { .catch(failTest) .then(done); }); + + it('should not output hover/unhover event data when hovermoder is false', function(done) { + var fig = Lib.extendDeep({}, mock); + + Plotly.plot(gd, fig) + .then(function() { return Plotly.relayout(gd, 'hovermode', false); }) + .then(function() { return _hover('node'); }) + .then(failTest).catch(function(err) { + expect(err).toBe('plotly_hover did not get called!'); + }) + .then(function() { return _unhover('node'); }) + .then(failTest).catch(function(err) { + expect(err).toBe('plotly_unhover did not get called!'); + }) + .then(function() { return _hover('link'); }) + .then(failTest).catch(function(err) { + expect(err).toBe('plotly_hover did not get called!'); + }) + .then(function() { return _unhover('link'); }) + .then(failTest).catch(function(err) { + expect(err).toBe('plotly_unhover did not get called!'); + }) + .then(done); + }); }); });