Skip to content

Commit 3509b99

Browse files
committed
fix and test finance hover labels - including test for #1807
1 parent 94c4560 commit 3509b99

File tree

3 files changed

+150
-65
lines changed

3 files changed

+150
-65
lines changed

src/components/fx/hover.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,6 @@ function createHoverText(hoverData, opts, gd) {
819819
}
820820
}
821821

822-
// used by other modules (initially just ternary) that
823-
// manage their own hoverinfo independent of cleanPoint
824-
// the rest of this will still apply, so such modules
825-
// can still put things in (x|y|z)Label, text, and name
826-
// and hoverinfo will still determine their visibility
827-
if(d.extraText !== undefined) text += d.extraText;
828-
829822
if(d.zLabel !== undefined) {
830823
if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';
831824
if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';
@@ -844,6 +837,13 @@ function createHoverText(hoverData, opts, gd) {
844837
text += (text ? '<br>' : '') + d.text;
845838
}
846839

840+
// used by other modules (initially just ternary) that
841+
// manage their own hoverinfo independent of cleanPoint
842+
// the rest of this will still apply, so such modules
843+
// can still put things in (x|y|z)Label, text, and name
844+
// and hoverinfo will still determine their visibility
845+
if(d.extraText !== undefined) text += (text ? '<br>' : '') + d.extraText;
846+
847847
// if 'text' is empty at this point,
848848
// put 'name' in main label and don't show secondary label
849849
if(text === '') {

src/traces/ohlc/hover.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,29 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
8383
return t.labels[attr] + Axes.hoverLabelText(ya, trace[attr][i]);
8484
}
8585

86-
var textParts = [
86+
var hoverinfo = trace.hoverinfo;
87+
var hoverParts = hoverinfo.split('+');
88+
var isAll = hoverinfo === 'all';
89+
var hasY = isAll || hoverParts.indexOf('y') !== -1;
90+
var hasText = isAll || hoverParts.indexOf('text') !== -1;
91+
92+
var textParts = hasY ? [
8793
getLabelLine('open'),
8894
getLabelLine('high'),
8995
getLabelLine('low'),
90-
getLabelLine('close')
91-
];
92-
fillHoverText(di, trace, textParts);
93-
pointData.text = textParts.join('<br>');
96+
getLabelLine('close') + ' ' + DIRSYMBOL[dir]
97+
] : [];
98+
if(hasText) fillHoverText(di, trace, textParts);
99+
100+
// don't make .yLabelVal or .text, since we're managing hoverinfo
101+
// put it all in .extraText
102+
pointData.extraText = textParts.join('<br>');
94103

95104
// this puts the label at the midpoint of the box, ie
96105
// halfway between open and close, not between high and low.
97106
// TODO: the spike also links to this point, whereas previously
98107
// it linked to close. Is one better?
99108
pointData.y0 = pointData.y1 = ya.c2p(di.yc, true);
100109

101-
// indicate increasing/decreasing in the "name" field
102-
// TODO: only shows up if name is displayed, ie multiple traces.
103-
pointData.name += '<br>' + DIRSYMBOL[dir];
104-
105110
return [pointData];
106111
};

0 commit comments

Comments
 (0)