Skip to content

Commit b66628e

Browse files
committed
introduce Axes.hoverLabelText
- dry special log-off-scale hover label text routine - use it in hover.js cleanPoint - allow hoverPoints modules to set their own xLabel and yLabel value
1 parent 8901528 commit b66628e

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/components/fx/hover.js

+2-24
Original file line numberDiff line numberDiff line change
@@ -1065,36 +1065,14 @@ function cleanPoint(d, hovermode) {
10651065

10661066
// and convert the x and y label values into objects
10671067
// formatted as text, with font info
1068-
var logOffScale;
10691068
if(d.xLabelVal !== undefined) {
1070-
logOffScale = (d.xa.type === 'log' && d.xLabelVal <= 0);
1071-
var xLabelObj = Axes.tickText(d.xa,
1072-
d.xa.c2l(logOffScale ? -d.xLabelVal : d.xLabelVal), 'hover');
1073-
if(logOffScale) {
1074-
if(d.xLabelVal === 0) d.xLabel = '0';
1075-
else d.xLabel = '-' + xLabelObj.text;
1076-
}
1077-
// TODO: should we do something special if the axis calendar and
1078-
// the data calendar are different? Somehow display both dates with
1079-
// their system names? Right now it will just display in the axis calendar
1080-
// but users could add the other one as text.
1081-
else d.xLabel = xLabelObj.text;
1069+
d.xLabel = ('xLabel' in d) ? d.xLabel : Axes.hoverLabelText(d.xa, d.xLabelVal);
10821070
d.xVal = d.xa.c2d(d.xLabelVal);
10831071
}
1084-
10851072
if(d.yLabelVal !== undefined) {
1086-
logOffScale = (d.ya.type === 'log' && d.yLabelVal <= 0);
1087-
var yLabelObj = Axes.tickText(d.ya,
1088-
d.ya.c2l(logOffScale ? -d.yLabelVal : d.yLabelVal), 'hover');
1089-
if(logOffScale) {
1090-
if(d.yLabelVal === 0) d.yLabel = '0';
1091-
else d.yLabel = '-' + yLabelObj.text;
1092-
}
1093-
// TODO: see above TODO
1094-
else d.yLabel = yLabelObj.text;
1073+
d.yLabel = ('yLabel' in d) ? d.yLabel : Axes.hoverLabelText(d.ya, d.yLabelVal);
10951074
d.yVal = d.ya.c2d(d.yLabelVal);
10961075
}
1097-
10981076
if(d.zLabelVal !== undefined) d.zLabel = String(d.zLabelVal);
10991077

11001078
// for box means and error bars, add the range to the label

src/plots/cartesian/axes.js

+15
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,21 @@ axes.tickText = function(ax, x, hover) {
12161216
return out;
12171217
};
12181218

1219+
axes.hoverLabelText = function(ax, val) {
1220+
var logOffScale = (ax.type === 'log' && val <= 0);
1221+
var tx = axes.tickText(ax, ax.c2l(logOffScale ? -val : val), 'hover').text;
1222+
1223+
if(logOffScale) {
1224+
return val === 0 ? '0' : '-' + tx;
1225+
}
1226+
1227+
// TODO: should we do something special if the axis calendar and
1228+
// the data calendar are different? Somehow display both dates with
1229+
// their system names? Right now it will just display in the axis calendar
1230+
// but users could add the other one as text.
1231+
return tx;
1232+
};
1233+
12191234
function tickTextObj(ax, x, text) {
12201235
var tf = ax.tickfont || {};
12211236

0 commit comments

Comments
 (0)