Skip to content

fix for spikedistance set to infinity #4627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/traces/bar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/hover_spikeline_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down