Skip to content

Commit d680bd4

Browse files
committed
Name back to showspikes
Keep spike background color to the chart background, unless the series color is too close, then use contrast color
1 parent 762b54a commit d680bd4

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

src/components/modebar/buttons.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function handleCartesian(gd, ev) {
206206
aobj[axName + '.range[1]'] = rangeInitial[1];
207207
}
208208
if(ax._showSpikeInitial !== undefined) {
209-
aobj[axName + '.showspike'] = ax._showSpikeInitial;
209+
aobj[axName + '.showspikes'] = ax._showSpikeInitial;
210210
if(allEnabled === 'on' && !ax._showSpikeInitial) {
211211
allEnabled = 'off';
212212
}
@@ -241,7 +241,7 @@ function handleCartesian(gd, ev) {
241241
} else if(astr === 'hovermode' && val === 'closest') {
242242
for(i = 0; i < axList.length; i++) {
243243
ax = axList[i];
244-
if(allEnabled === 'on' && !ax.showspike) {
244+
if(allEnabled === 'on' && !ax.showspikes) {
245245
allEnabled = 'off';
246246
}
247247
}
@@ -569,7 +569,7 @@ function setSpikelineVisibility(gd) {
569569
for(var i = 0; i < axList.length; i++) {
570570
ax = axList[i];
571571
axName = ax._name;
572-
aobj[axName + '.showspike'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : false;
572+
aobj[axName + '.showspikes'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : false;
573573
}
574574

575575
return aobj;

src/plots/cartesian/axes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,16 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
373373
var isNew = (ax._showSpikeInitial === undefined);
374374
var hasChanged = (
375375
isNew || !(
376-
ax.showspike === ax._showspike
376+
ax.showspikes === ax._showspikes
377377
)
378378
);
379379

380380
if((isNew) || (overwrite && hasChanged)) {
381-
ax._showSpikeInitial = ax.showspike;
381+
ax._showSpikeInitial = ax.showspikes;
382382
hasOneAxisChanged = true;
383383
}
384384

385-
if(allEnabled === 'on' && !ax.showspike) {
385+
if(allEnabled === 'on' && !ax.showspikes) {
386386
allEnabled = 'off';
387387
}
388388
}

src/plots/cartesian/axis_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7575
coerce('range');
7676
containerOut.cleanRange();
7777

78-
coerce('showspike');
78+
coerce('showspikes');
7979
coerce('spikecolor');
8080
coerce('spikethickness');
8181
coerce('spikedash');

src/plots/cartesian/graph_interact.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,15 @@ function createDroplines(hoverData, opts) {
860860
yAnchoredBase = yEdge - outerBBox.top,
861861
xBase = c0.ya.anchor === 'free' ? xFreeBase : xAnchoredBase,
862862
yBase = c0.xa.anchor === 'free' ? yFreeBase : yAnchoredBase,
863-
xColor = c0.xa.spikecolor ? c0.xa.spikecolor : c0.color,
864-
yColor = c0.ya.spikecolor ? c0.ya.spikecolor : c0.color,
865-
xContrastColor = tinycolor(xColor).getBrightness() > 128 ?
866-
'#000' : Color.background,
867-
yContrastColor = tinycolor(yColor).getBrightness() > 128 ?
868-
'#000' : Color.background,
863+
contrastColor = Color.combine(fullLayout.plot_bgcolor, fullLayout.paper_bgcolor),
864+
xColor = c0.xa.spikecolor ? c0.xa.spikecolor : (
865+
tinycolor.readability(c0.color,contrastColor) < 1.5 ? (
866+
tinycolor(c0.color).getBrightness() > 128 ? '#000' : Color.background)
867+
: c0.color),
868+
yColor = c0.ya.spikecolor ? c0.ya.spikecolor : (
869+
tinycolor.readability(c0.color,contrastColor) < 1.5 ? (
870+
tinycolor(c0.color).getBrightness() > 128 ? '#000' : Color.background)
871+
: c0.color),
869872
xThickness = c0.xa.spikethickness,
870873
yThickness = c0.ya.spikethickness,
871874
xDash = Drawing.dashStyle(c0.xa.spikedash, xThickness),
@@ -882,7 +885,7 @@ function createDroplines(hoverData, opts) {
882885
container.selectAll('circle.dropline').remove();
883886

884887

885-
if(c0.ya.showspike) {
888+
if(c0.ya.showspikes) {
886889
if(ySpikeLine) {
887890
// Background horizontal Line (to y-axis)
888891
container.append('line')
@@ -892,7 +895,7 @@ function createDroplines(hoverData, opts) {
892895
'y1': yPoint,
893896
'y2': yPoint,
894897
'stroke-width': yThickness + 2,
895-
'stroke': yContrastColor
898+
'stroke': contrastColor
896899
})
897900
.classed('dropline', true)
898901
.classed('crisp', true);
@@ -925,17 +928,17 @@ function createDroplines(hoverData, opts) {
925928
}
926929
}
927930

928-
if(c0.xa.showspike) {
931+
if(c0.xa.showspikes) {
929932
if(xSpikeLine) {
930933
// Background vertical line (to x-axis)
931934
container.append('line')
932935
.attr({
933936
'x1': xPoint,
934937
'x2': xPoint,
935-
'y1': yEndSpike,
936-
'y2': yBase,
938+
'y1': yBase,
939+
'y2': yEndSpike,
937940
'stroke-width': xThickness + 2,
938-
'stroke': xContrastColor
941+
'stroke': contrastColor
939942
})
940943
.classed('dropline', true)
941944
.classed('crisp', true);
@@ -945,8 +948,8 @@ function createDroplines(hoverData, opts) {
945948
.attr({
946949
'x1': xPoint,
947950
'x2': xPoint,
948-
'y1': yEndSpike,
949-
'y2': yBase,
951+
'y1': yBase,
952+
'y2': yEndSpike,
950953
'stroke-width': xThickness,
951954
'stroke': xColor,
952955
'stroke-dasharray': xDash

src/plots/cartesian/layout_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ module.exports = {
279279
role: 'style',
280280
description: 'Determines whether or not the tick labels are drawn.'
281281
},
282-
showspike: {
282+
showspikes: {
283283
valType: 'boolean',
284284
dflt: false,
285285
role: 'style',

0 commit comments

Comments
 (0)