8000 add spikedistance, hoverdistance, spikesnap · apalchys/plotly.js@253cdc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 253cdc7

Browse files
committed
add spikedistance, hoverdistance, spikesnap
1 parent f3ed835 commit 253cdc7

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
@@ -235,9 +235,6 @@ function handleCartesian(gd, ev) {
235235
if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
236236
val = fullLayout._isHoriz ? 'y' : 'x';
237237
button.setAttribute('data-val', val);
238-
if(val !== 'closest') {
239-
fullLayout._cartesianSpikesEnabled = 'off';
240-
}
241238
} else if(astr === 'hovermode' && val === 'closest') {
242239
for(i = 0; i < axList.length; i++) {
243240
ax = axList[i];
@@ -550,12 +547,10 @@ modeBarButtons.toggleSpikelines = {
550547
click: function(gd) {
551548
var fullLayout = gd._fullLayout;
552549

553-
fullLayout._cartesianSpikesEnabled = fullLayout.hovermode === 'closest' ?
554-
(fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on') : 'on';
550+
fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';
555551

556552
var aobj = setSpikelineVisibility(gd);
557553

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

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
@@ -426,30 +426,6 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
426426
return hasOneAxisChanged;
427427
};
428428

429-
// save a copy of the initial crossline visibility
430-
axes.saveShowCrosslineInitial = function(gd, overwrite) {
431-
var axList = axes.list(gd, '', true),
432-
hasOneAxisChanged = false;
433-
434-
for(var i = 0; i < axList.length; i++) {
435-
var ax = axList[i];
436-
437-
var isNew = (ax._showCrosslineInitial === undefined);
438-
var hasChanged = (
439-
isNew || !(
440-
ax.showcrossline === ax._showcrossline
441-
)
442-
);
443-
444-
if((isNew) || (overwrite && hasChanged)) {
445-
ax._showCrosslineInitial = ax.showcrossline;
446-
hasOneAxisChanged = true;
447-
}
448-
449-
}
450-
return hasOneAxisChanged;
451-
};
452-
453429
// axes.expand: if autoranging, include new data in the outer limits
454430
// for this axis
455431
// 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
B971
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
191191

192192
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
193193

194-
var showCrossline = coerce('showcrossline');
195-
if(showCrossline) {
196-
coerce('crosslinecolor');
197-
coerce('crosslinethickness');
198-
coerce('crosslinedash');
199-
}
200-
201194
var showSpikes = coerce('showspikes');
202195
if(showSpikes) {
203196
coerce('spikecolor');
204197
coerce('spikethickness');
205198
coerce('spikedash');
206199
coerce('spikemode');
200+
coerce('spikesnap');
207201
}
208202

209203
var positioningOptions = {

test/jasmine/tests/hover_crossline_test.js

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

0 commit comments

Comments
 (0)
0