Skip to content

Commit c0fcb78

Browse files
committed
implement hovertemplate for ohlc and candlestick traces
1 parent 06ece4b commit c0fcb78

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

src/components/fx/hover.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,11 @@ function getHoverLabelText(d, showCommonLabel, hovermode, fullLayout, t0, g) {
16621662
text = name;
16631663
}
16641664

1665-
// hovertemplate
1665+
// Ignore hovertemplate if hoverlabel.split is set
1666+
// This ensures correct behavior of hoverlabel.split for candlestick and OHLC traces
1667+
// Not very elegant but it works
1668+
if (d.trace?.hoverlabel?.split) d.hovertemplate = false;
1669+
16661670
const { hovertemplate = false } = d;
16671671
if (hovertemplate) {
16681672
const labels = d.hovertemplateLabels || d;

src/traces/candlestick/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var extendFlat = require('../../lib').extendFlat;
44
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
5+
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
6+
var templatefallbackAttrs = require('../../plots/template_attributes').templatefallbackAttrs;
57
var OHLCattrs = require('../ohlc/attributes');
68
var boxAttrs = require('../box/attributes');
79

@@ -49,6 +51,9 @@ module.exports = {
4951

5052
text: OHLCattrs.text,
5153
hovertext: OHLCattrs.hovertext,
54+
hovertemplate: OHLCattrs.hovertemplate,
55+
hovertemplatefallback: OHLCattrs.hovertemplatefallback,
56+
hoverinfo: OHLCattrs.hoverinfo,
5257

5358
whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),
5459

src/traces/candlestick/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2828

2929
coerce('text');
3030
coerce('hovertext');
31+
coerce('hoverinfo');
32+
coerce('hovertemplate');
33+
coerce('hovertemplatefallback');
34+
3135
coerce('whiskerwidth');
3236

3337
layout._requestRangeslider[traceOut.xaxis] = true;

src/traces/ohlc/attributes.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
var extendFlat = require('../../lib').extendFlat;
44
var scatterAttrs = require('../scatter/attributes');
5+
var baseAttrs = require('../../plots/attributes');
56
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
7+
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
8+
var templatefallbackAttrs = require('../../plots/template_attributes').templatefallbackAttrs;
69
var dash = require('../../components/drawing/attributes').dash;
710
var fxAttrs = require('../../components/fx/attributes');
811
var delta = require('../../constants/delta.js');
@@ -105,7 +108,16 @@ module.exports = {
105108
editType: 'calc',
106109
description: 'Same as `text`.'
107110
},
108-
111+
hovertemplate: hovertemplateAttrs(
112+
{},
113+
{
114+
keys: ['open', 'high', 'low', 'close']
115+
}
116+
),
117+
hovertemplatefallback: templatefallbackAttrs(),
118+
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
119+
flags: ['x', 'y', 'open', 'high', 'low', 'close', 'text', 'name']
120+
}),
109121
tickwidth: {
110122
valType: 'number',
111123
min: 0,

src/traces/ohlc/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2828

2929
coerce('text');
3030
coerce('hovertext');
31+
coerce('hoverinfo');
32+
coerce('hovertemplate');
33+
coerce('hovertemplatefallback');
34+
3135
coerce('tickwidth');
3236

3337
layout._requestRangeslider[traceOut.xaxis] = true;

0 commit comments

Comments
 (0)