From 907415a84c9dc656eb3f6fa9725fd8e9e3910b89 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 May 2021 09:28:32 -0400 Subject: [PATCH 1/5] default spikedistance to -1 --- src/components/fx/layout_attributes.js | 2 +- src/components/fx/layout_defaults.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/fx/layout_attributes.js b/src/components/fx/layout_attributes.js index 756e5f79435..cc7c5a94217 100644 --- a/src/components/fx/layout_attributes.js +++ b/src/components/fx/layout_attributes.js @@ -99,7 +99,7 @@ module.exports = { spikedistance: { valType: 'integer', min: -1, - dflt: 20, + dflt: -1, editType: 'none', description: [ 'Sets the default distance (in pixels) to look for data to draw', diff --git a/src/components/fx/layout_defaults.js b/src/components/fx/layout_defaults.js index 1d28e242400..a9284e7a16a 100644 --- a/src/components/fx/layout_defaults.js +++ b/src/components/fx/layout_defaults.js @@ -1,7 +1,6 @@ 'use strict'; var Lib = require('../../lib'); -var isUnifiedHover = require('./helpers').isUnifiedHover; var layoutAttributes = require('./layout_attributes'); var handleHoverModeDefaults = require('./hovermode_defaults'); var handleHoverLabelDefaults = require('./hoverlabel_defaults'); @@ -14,7 +13,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { var hoverMode = handleHoverModeDefaults(layoutIn, layoutOut, fullData); if(hoverMode) { coerce('hoverdistance'); - coerce('spikedistance', isUnifiedHover(hoverMode) ? -1 : undefined); + coerce('spikedistance'); } var dragMode = coerce('dragmode'); From e0984cfff5d6fc879f231686914f0fcd14e65f14 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 May 2021 09:39:28 -0400 Subject: [PATCH 2/5] adjust tests --- test/jasmine/tests/hover_spikeline_test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/jasmine/tests/hover_spikeline_test.js b/test/jasmine/tests/hover_spikeline_test.js index ead962676d2..bc8763e0eb6 100644 --- a/test/jasmine/tests/hover_spikeline_test.js +++ b/test/jasmine/tests/hover_spikeline_test.js @@ -352,6 +352,7 @@ describe('spikeline hover', function() { it('increase the range of search for points to draw the spikelines on spikedistance change', function(done) { var _mock = makeMock('toaxis', 'closest'); + _mock.layout.spikedistance = 20; Plotly.newPlot(gd, _mock).then(function() { _hover({xval: 1.6, yval: 2.6}); @@ -387,6 +388,7 @@ describe('spikeline hover', function() { it('correctly responds to setting the spikedistance to -1 by increasing ' + 'the range of search for points to draw the spikelines to Infinity', function(done) { var _mock = makeMock('toaxis', 'closest'); + _mock.layout.spikedistance = 20; Plotly.newPlot(gd, _mock).then(function() { _hover({xval: 1.6, yval: 2.6}); @@ -498,6 +500,7 @@ describe('spikeline hover', function() { ] }], layout: { + spikedistance: 20, hovermode: 'x', xaxis: { showspikes: true }, yaxis: { showspikes: true }, @@ -567,6 +570,7 @@ describe('spikeline hover', function() { return { width: 600, height: 600, margin: {l: 100, r: 100, t: 100, b: 100}, showlegend: false, + spikedistance: 20, xaxis: {range: [-0.5, 1.5], showspikes: true, spikemode: 'toaxis+marker'}, yaxis: {range: [-1, 3], showspikes: true, spikemode: 'toaxis+marker'}, hovermode: 'x', From 75c35db6c543353e48f0e08e4eef9e342fa28a33 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 May 2021 10:00:07 -0400 Subject: [PATCH 3/5] simplify test --- test/jasmine/tests/hover_spikeline_test.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test/jasmine/tests/hover_spikeline_test.js b/test/jasmine/tests/hover_spikeline_test.js index bc8763e0eb6..3568269475b 100644 --- a/test/jasmine/tests/hover_spikeline_test.js +++ b/test/jasmine/tests/hover_spikeline_test.js @@ -293,9 +293,6 @@ describe('spikeline hover', function() { it('does not show spikes if no points are hovered in the spikesnap "hovered data" mode', function(done) { var _mock = makeMock('toaxis', 'x'); Plotly.newPlot(gd, _mock) - .then(function() { - _setSpikedistance(-1); - }) .then(function() { _hover({xval: 1.5}); _assert( @@ -388,33 +385,32 @@ describe('spikeline hover', function() { it('correctly responds to setting the spikedistance to -1 by increasing ' + 'the range of search for points to draw the spikelines to Infinity', function(done) { var _mock = makeMock('toaxis', 'closest'); - _mock.layout.spikedistance = 20; Plotly.newPlot(gd, _mock).then(function() { _hover({xval: 1.6, yval: 2.6}); _assert( - [], - [] + [[557, 401, 557, 250], [80, 250, 557, 250]], + [[83, 250]] ); _hover({xval: 26, yval: 36}, 'x2y2'); _assert( - [], + [[820, 220, 820, 167]], [] ); - _setSpikedistance(-1); + _setSpikedistance(20); }) .then(function() { _hover({xval: 1.6, yval: 2.6}); _assert( - [[557, 401, 557, 250], [80, 250, 557, 250]], - [[83, 250]] + [], + [] ); _hover({xval: 26, yval: 36}, 'x2y2'); _assert( - [[820, 220, 820, 167]], + [], [] ); }) From 77239d8e51891739830220131b627bdc6b548ee2 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 May 2021 10:01:49 -0400 Subject: [PATCH 4/5] default spikesnap to hovered data --- src/plots/cartesian/layout_attributes.js | 2 +- src/plots/cartesian/layout_defaults.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plots/cartesian/layout_attributes.js b/src/plots/cartesian/layout_attributes.js index fb8ffafcde2..4cdf5e9239a 100644 --- a/src/plots/cartesian/layout_attributes.js +++ b/src/plots/cartesian/layout_attributes.js @@ -603,7 +603,7 @@ module.exports = { spikesnap: { valType: 'enumerated', values: ['data', 'cursor', 'hovered data'], - dflt: 'data', + dflt: 'hovered data', editType: 'none', description: 'Determines whether spikelines are stuck to the cursor or to the closest datapoints.' }, diff --git a/src/plots/cartesian/layout_defaults.js b/src/plots/cartesian/layout_defaults.js index c500997541b..9c317180cd5 100644 --- a/src/plots/cartesian/layout_defaults.js +++ b/src/plots/cartesian/layout_defaults.js @@ -253,7 +253,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { var spikethickness = coerce2('spikethickness', unifiedHover ? 1.5 : undefined); var spikedash = coerce2('spikedash', unifiedHover ? 'dot' : undefined); var spikemode = coerce2('spikemode', unifiedHover ? 'across' : undefined); - var spikesnap = coerce2('spikesnap', unifiedHover ? 'hovered data' : undefined); + var spikesnap = coerce2('spikesnap'); var showSpikes = coerce('showspikes', !!unifiedSpike || !!spikecolor || !!spikethickness || !!spikedash || !!spikemode || !!spikesnap); if(!showSpikes) { From 036159247dd34e1765051d4a7a32889619da43b6 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 May 2021 10:55:38 -0400 Subject: [PATCH 5/5] adjust tests --- test/jasmine/tests/hover_spikeline_test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/jasmine/tests/hover_spikeline_test.js b/test/jasmine/tests/hover_spikeline_test.js index 3568269475b..7da9e9a9320 100644 --- a/test/jasmine/tests/hover_spikeline_test.js +++ b/test/jasmine/tests/hover_spikeline_test.js @@ -22,13 +22,17 @@ describe('spikeline hover', function() { function makeMock(spikemode, hovermode) { var _mock = Lib.extendDeep({}, require('@mocks/19.json')); + _mock.layout.xaxis.spikesnap = 'data'; _mock.layout.xaxis.showspikes = true; _mock.layout.xaxis.spikemode = spikemode; + _mock.layout.yaxis.spikesnap = 'data'; _mock.layout.yaxis.showspikes = true; _mock.layout.yaxis.spikemode = spikemode + '+marker'; + _mock.layout.xaxis2.spikesnap = 'data'; _mock.layout.xaxis2.showspikes = true; _mock.layout.xaxis2.spikemode = spikemode; _mock.layout.hovermode = hovermode; + return _mock; } @@ -445,6 +449,8 @@ describe('spikeline hover', function() { var mockCopy = Lib.extendDeep({}, mock); mockCopy.layout.xaxis.showspikes = true; mockCopy.layout.yaxis.showspikes = true; + mockCopy.layout.xaxis.spikesnap = 'data'; + mockCopy.layout.yaxis.spikesnap = 'data'; mockCopy.layout.spikedistance = -1; mockCopy.layout.hovermode = 'closest'; @@ -824,9 +830,9 @@ describe('spikeline hover', function() { data: [makeData(type, 'xaxis', x, data)], layout: { spikedistance: -1, - xaxis: {showspikes: true}, - yaxis: {showspikes: true}, - zaxis: {showspikes: true}, + xaxis: {showspikes: true, spikesnap: 'data'}, + yaxis: {showspikes: true, spikesnap: 'data'}, + zaxis: {showspikes: true, spikesnap: 'data'}, title: {text: trace.type}, width: 400, height: 400 }