Skip to content

Commit ae9e6af

Browse files
committed
add unifiedhovertemplate
1 parent 5bbfbbc commit ae9e6af

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/components/fx/hover.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,22 @@ function createHoverText(hoverData, opts) {
12111211
// mock legend
12121212
var hoverlabel = fullLayout.hoverlabel;
12131213
var font = hoverlabel.font;
1214+
1215+
var unifiedhovertemplate = (
1216+
(hovermode === 'y unified') ?
1217+
groupedHoverData[0]?.xa :
1218+
groupedHoverData[0]?.ya
1219+
).unifiedhovertemplate;
1220+
1221+
var mainText = Lib.hovertemplateString(unifiedhovertemplate, {}, fullLayout._d3locale, {
1222+
x: hovermode === 'y unified' ? t0 : undefined,
1223+
y: hovermode === 'x unified' ? t0 : undefined,
1224+
});
1225+
12141226
var mockLayoutIn = {
12151227
showlegend: true,
12161228
legend: {
1217-
title: {text: t0, font: font},
1229+
title: {text: mainText, font: font},
12181230
font: font,
12191231
bgcolor: hoverlabel.bgcolor,
12201232
bordercolor: hoverlabel.bordercolor,

src/plots/cartesian/axis_defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
100100

101101
handleCategoryOrderDefaults(containerIn, containerOut, coerce, options);
102102

103-
if(axType !== 'category' && !options.noHover) coerce('hoverformat');
103+
if(!options.noHover) {
104+
if(axType !== 'category') coerce('hoverformat');
105+
coerce('unifiedhovertemplate');
106+
}
104107

105108
var dfltColor = coerce('color');
106109
// if axis.color was provided, use it for fonts too; otherwise,

src/plots/cartesian/layout_attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var colorAttrs = require('../../components/color/attributes');
55
var dash = require('../../components/drawing/attributes').dash;
66
var extendFlat = require('../../lib/extend').extendFlat;
77
var templatedArray = require('../../plot_api/plot_template').templatedArray;
8+
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
89
var descriptionWithDates = require('../../plots/cartesian/axis_format_attributes').descriptionWithDates;
910

1011
var ONEDAY = require('../../constants/numerical').ONEDAY;
@@ -974,6 +975,9 @@ module.exports = {
974975
editType: 'none',
975976
description: descriptionWithDates('hover text')
976977
},
978+
unifiedhovertemplate: hovertemplateAttrs({
979+
noSupportOther: true
980+
}),
977981
// lines and grids
978982
showline: {
979983
valType: 'boolean',

src/plots/template_attributes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ exports.hovertemplateAttrs = function(opts, extra) {
7171
description: [
7272
'Template string used for rendering the information that appear on hover box.',
7373
'Note that this will override `hoverinfo`.',
74-
templateFormatStringDescription({supportOther: true}),
74+
templateFormatStringDescription({
75+
supportOther: opts.noSupportOther ? false : true
76+
}),
7577
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data.',
7678
'Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
7779
descPart,

0 commit comments

Comments
 (0)