From ae7db42b1d73ebcbc1a0513abf5ed78008a67271 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 11 Mar 2020 13:16:46 -0400 Subject: [PATCH 1/2] spikeline: test spikedistance -1 on a bar trace --- test/jasmine/tests/hover_spikeline_test.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/jasmine/tests/hover_spikeline_test.js b/test/jasmine/tests/hover_spikeline_test.js index 80823cb07f5..bbd965af5da 100644 --- a/test/jasmine/tests/hover_spikeline_test.js +++ b/test/jasmine/tests/hover_spikeline_test.js @@ -404,6 +404,33 @@ describe('spikeline hover', function() { .then(done); }); + it('correctly responds to setting the spikedistance to -1 by increasing ' + + 'the range of search for points to draw the spikelines to Infinity in a bar trace', function(done) { + var _mock = { + data: [{type: 'bar', y: [5, 6, 8, 10]}], + layout: {xaxis: {showspikes: true}} + }; + + Plotly.plot(gd, _mock).then(function() { + _hover({xval: 0, yval: 2}); + _assert( + [[147.5, 370, 147.5, 241.75]], + [] + ); + + _setSpikedistance(-1); + }) + .then(function() { + _hover({xval: 0, yval: 2}); + _assert( + [[147.5, 370, 147.5, 241.75]], + [] + ); + }) + .catch(failTest) + .then(done); + }); + it('correctly responds to setting the spikedistance to 0 by disabling ' + 'the search for points to draw the spikelines', function(done) { var _mock = makeMock('toaxis', 'closest'); From ebf75e6a89b477015fad590c1eede011682be031 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 11 Mar 2020 20:57:02 -0400 Subject: [PATCH 2/2] bar hover: fix spikedistance calculation --- src/traces/bar/hover.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 11cb91485ed..8c4ed26df81 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -39,7 +39,6 @@ function hoverOnBars(pointData, xval, yval, hovermode) { var isClosest = (hovermode === 'closest'); var isWaterfall = (trace.type === 'waterfall'); var maxHoverDistance = pointData.maxHoverDistance; - var maxSpikeDistance = pointData.maxSpikeDistance; var posVal, sizeVal, posLetter, sizeLetter, dx, dy, pRangeCalc; @@ -161,7 +160,7 @@ function hoverOnBars(pointData, xval, yval, hovermode) { pointData.valueLabel = hoverLabelText(sa, pointData[sizeLetter + 'LabelVal']); // spikelines always want "closest" distance regardless of hovermode - pointData.spikeDistance = (sizeFn(di) + thisBarPositionFn(di)) / 2 + maxSpikeDistance - maxHoverDistance; + pointData.spikeDistance = (sizeFn(di) + thisBarPositionFn(di)) / 2; // they also want to point to the data value, regardless of where the label goes // in case of bars shifted within groups pointData[posLetter + 'Spike'] = pa.c2p(di.p, true);