Skip to content

Commit b14286b

Browse files
committed
add spikedistance, hoverdistance, spikesnap
1 parent 006b55d commit b14286b

File tree

11 files changed

+191
-424
lines changed

11 files changed

+191
-424
lines changed

src/components/fx/hover.js

Lines changed: 160 additions & 159 deletions
Large diffs are not rendered by default.

src/components/fx/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function loneUnhover(containerOrSelection) {
5959

6060
selection.selectAll('g.hovertext').remove();
6161
selection.selectAll('.spikeline').remove();
62-
selection.selectAll('.crossline').remove();
6362
}
6463

6564
// helpers for traces that use Fx.loneHover

src/components/fx/layout_attributes.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,28 @@ module.exports = {
3838
editType: 'modebar',
3939
description: 'Determines the mode of hover interactions.'
4040
},
41-
41+
hoverdistance: {
42+
valType: 'integer',
43+
min: -1,
44+
dflt: 20,
45+
role: 'style',
46+
editType: 'none',
47+
description: [
48+
'Sets the default distance (in points) to look for data',
49+
'to add hover labels'
50+
].join(' ')
51+
},
52+
spikedistance: {
53+
valType: 'integer',
54+
min: -1,
55+
dflt: 20,
56+
role: 'style',
57+
editType: 'none',
58+
description: [
59+
'Sets the default distance (in points) to look for data',
60+
'to draw spikelines to. By default inherits from hoverdistance'
61+
].join(' ')
62+
},
4263
hoverlabel: {
4364
bgcolor: {
4465
valType: 'color',

src/components/fx/layout_defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
2828
else hovermodeDflt = 'closest';
2929

3030
coerce('hovermode', hovermodeDflt);
31+
coerce('hoverdistance');
32+
coerce('spikedistance');
3133

3234
// if only mapbox or geo subplots is present on graph,
3335
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,

src/components/modebar/buttons.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@ function handleCartesian(gd, ev) {
237237
if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
238238
val = fullLayout._isHoriz ? 'y' : 'x';
239239
button.setAttribute('data-val', val);
240-
if(val !== 'closest') {
241-
fullLayout._cartesianSpikesEnabled = 'off';
242-
}
243240
} else if(astr === 'hovermode' && val === 'closest') {
244241
for(i = 0; i < axList.length; i++) {
245242
ax = axList[i];
@@ -551,12 +548,10 @@ modeBarButtons.toggleSpikelines = {
551548
click: function(gd) {
552549
var fullLayout = gd._fullLayout;
553550

554-
fullLayout._cartesianSpikesEnabled = fullLayout.hovermode === 'closest' ?
555-
(fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on') : 'on';
551+
fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';
556552

557553
var aobj = setSpikelineVisibility(gd);
558554

559-
aobj.hovermode = 'closest';
560555
Plotly.relayout(gd, aobj);
561556
}
562557
};

src/plot_api/plot_api.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ Plotly.plot = function(gd, data, layout, config) {
166166
// save initial show spikes once per graph
167167
if(graphWasEmpty) Plotly.Axes.saveShowSpikeInitial(gd);
168168

169-
// save initial show crosslines once per graph
170-
if(graphWasEmpty) Plotly.Axes.saveShowCrosslineInitial(gd);
171-
172169
// prepare the data and find the autorange
173170

174171
// generate calcdata, if we need to

src/plots/cartesian/axes.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -423,30 +423,6 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
423423
return hasOneAxisChanged;
424424
};
425425

426-
// save a copy of the initial crossline visibility
427-
axes.saveShowCrosslineInitial = function(gd, overwrite) {
428-
var axList = axes.list(gd, '', true),
429-
hasOneAxisChanged = false;
430-
431-
for(var i = 0; i < axList.length; i++) {
432-
var ax = axList[i];
433-
434-
var isNew = (ax._showCrosslineInitial === undefined);
435-
var hasChanged = (
436-
isNew || !(
437-
ax.showcrossline === ax._showcrossline
438-
)
439-
);
440-
441-
if((isNew) || (overwrite && hasChanged)) {
442-
ax._showCrosslineInitial = ax.showcrossline;
443-
hasOneAxisChanged = true;
444-
}
445-
446-
}
447-
return hasOneAxisChanged;
448-
};
449-
450426
// axes.expand: if autoranging, include new data in the outer limits
451427
// for this axis
452428
// data is an array of numbers (ie already run through ax.d2c)

src/plots/cartesian/layout_attributes.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -387,28 +387,14 @@ module.exports = {
387387
'plotted on'
388388
].join(' ')
389389
},
390-
showcrossline: {
391-
valType: 'boolean',
392-
dflt: false,
393-
role: 'style',
394-
editType: 'none',
395-
description: 'Determines whether or not crossline are drawn for this axis.'
396-
},
397-
crosslinecolor: {
398-
valType: 'color',
399-
dflt: null,
400-
role: 'style',
401-
editType: 'none',
402-
description: 'Sets the crossline color. If undefined, will use the contrast to background color'
403-
},
404-
crosslinethickness: {
405-
valType: 'number',
406-
dflt: 2,
390+
spikesnap: {
391+
valType: 'enumerated',
392+
values: ['data', 'cursor'],
393+
dflt: 'data',
407394
role: 'style',
408395
editType: 'none',
409-
description: 'Sets the width (in px) of the zero line.'
396+
description: 'Determines whether spikelines are stuck to the cursor or to the closest datapoints.'
410397
},
411-
crosslinedash: extendFlat({}, dash, {dflt: 'solid', editType: 'none'}),
412398
tickfont: fontAttrs({
413399
editType: 'ticks',
414400
description: 'Sets the tick font.'

src/plots/cartesian/layout_defaults.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
139139

140140
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
141141

142-
var showCrossline = coerce('showcrossline');
143-
if(showCrossline) {
144-
coerce('crosslinecolor');
145-
coerce('crosslinethickness');
146-
coerce('crosslinedash');
147-
}
148-
149142
var showSpikes = coerce('showspikes');
150143
if(showSpikes) {
151144
coerce('spikecolor');
152145
coerce('spikethickness');
153146
coerce('spikedash');
154147
coerce('spikemode');
148+
coerce('spikesnap');
155149
}
156150

157151
var positioningOptions = {

test/jasmine/tests/hover_crossline_test.js

Lines changed: 0 additions & 179 deletions
This file was deleted.

test/jasmine/tests/modebar_test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -861,38 +861,13 @@ describe('ModeBar', function() {
861861
});
862862

863863
describe('button toggleSpikelines', function() {
864-
it('should update layout hovermode', function() {
865-
expect(gd._fullLayout.hovermode).toBe('x');
866-
assertActive(hovermodeButtons, buttonCompare);
867-
868-
buttonToggle.click();
869-
expect(gd._fullLayout.hovermode).toBe('closest');
870-
assertActive(hovermodeButtons, buttonClosest);
871-
});
872864
it('should makes spikelines visible', function() {
873865
buttonToggle.click();
874866
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
875867

876868
buttonToggle.click();
877869
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
878870
});
879-
it('should become disabled when hovermode is switched off closest', function() {
880-
buttonToggle.click();
881-
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
882-
883-
buttonCompare.click();
884-
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
885-
});
886-
it('should be re-enabled when hovermode is set to closest if it was previously on', function() {
887-
buttonToggle.click();
888-
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
889-
890-
buttonCompare.click();
891-
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
892-
893-
buttonClosest.click();
894-
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
895-
});
896871
});
897872
});
898873

0 commit comments

Comments
 (0)