Skip to content

Commit 876e74c

Browse files
committed
add unifiedhovertemplate
1 parent 5bbfbbc commit 876e74c

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-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 = !unifiedhovertemplate ? t0 : 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+
if(!options.noUnifiedhovertemplate) 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/gl3d/layout/axis_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
5151
noTicklabelposition: true,
5252
noTicklabeloverflow: true,
5353
noInsiderange: true,
54+
noUnifiedhovertemplate: true,
5455
bgColor: options.bgColor,
5556
calendar: options.calendar
5657
},

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,

test/plot-schema.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14949,6 +14949,18 @@
1494914949
"editType": "none",
1495014950
"valType": "any"
1495114951
},
14952+
"unifiedhovertemplate": {
14953+
"arrayOk": true,
14954+
"description": "Template string used for rendering the information that appear on hover box. Note that this will override `hoverinfo`. Variables are inserted using %{variable}, for example \"y: %{y}\". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example \"Price: %{y:$.2f}\". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example \"Day: %{2019-01-01|%A}\". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. Anything contained in tag `<extra>` is displayed in the secondary box, for example \"<extra>{fullData.name}</extra>\". To hide the secondary box completely, use an empty tag `<extra></extra>`.",
14955+
"dflt": "",
14956+
"editType": "none",
14957+
"valType": "string"
14958+
},
14959+
"unifiedhovertemplatesrc": {
14960+
"description": "Sets the source reference on Chart Studio Cloud for `unifiedhovertemplate`.",
14961+
"editType": "none",
14962+
"valType": "string"
14963+
},
1495214964
"visible": {
1495314965
"description": "A single toggle to hide the axis while preserving interaction like dragging. Default is true when a cheater plot is present on the axis, otherwise false",
1495414966
"editType": "plot",
@@ -16193,6 +16205,18 @@
1619316205
"editType": "none",
1619416206
"valType": "any"
1619516207
},
16208+
"unifiedhovertemplate": {
16209+
"arrayOk": true,
16210+
"description": "Template string used for rendering the information that appear on hover box. Note that this will override `hoverinfo`. Variables are inserted using %{variable}, for example \"y: %{y}\". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example \"Price: %{y:$.2f}\". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example \"Day: %{2019-01-01|%A}\". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. Anything contained in tag `<extra>` is displayed in the secondary box, for example \"<extra>{fullData.name}</extra>\". To hide the secondary box completely, use an empty tag `<extra></extra>`.",
16211+
"dflt": "",
16212+
"editType": "none",
16213+
"valType": "string"
16214+
},
16215+
"unifiedhovertemplatesrc": {
16216+
"description": "Sets the source reference on Chart Studio Cloud for `unifiedhovertemplate`.",
16217+
"editType": "none",
16218+
"valType": "string"
16219+
},
1619616220
"visible": {
1619716221
"description": "A single toggle to hide the axis while preserving interaction like dragging. Default is true when a cheater plot is present on the axis, otherwise false",
1619816222
"editType": "plot",

0 commit comments

Comments
 (0)