Skip to content

Commit c99340d

Browse files
committed
unifiedhovertitle.text
1 parent 4cdab8f commit c99340d

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

draftlogs/7439_add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Add unifiedhovertitle to format unified hover title [[#7439](https://github.com/plotly/plotly.js/pull/7439)]
1+
- Add `unifiedhovertitle.text` to format unified hover titles [[#7439](https://github.com/plotly/plotly.js/pull/7439)]

src/components/fx/hover.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,14 @@ function createHoverText(hoverData, opts) {
12141214

12151215
var item0 = groupedHoverData[0];
12161216

1217-
var unifiedhovertitle = (
1217+
var unifiedhovertitleText = ((
12181218
hovermode === 'x unified' ?
12191219
item0.xa :
12201220
item0.ya
1221-
).unifiedhovertitle;
1221+
).unifiedhovertitle || {}).text;
12221222

1223-
var mainText = !unifiedhovertitle ? t0 :
1224-
Lib.hovertemplateString(unifiedhovertitle, {}, fullLayout._d3locale,
1223+
var mainText = !unifiedhovertitleText ? t0 :
1224+
Lib.hovertemplateString(unifiedhovertitleText, {}, fullLayout._d3locale,
12251225
hovermode === 'x unified' ?
12261226
{xa: item0.xa, x: item0.xVal} :
12271227
{ya: item0.ya, y: item0.yVal}

src/plots/cartesian/axis_defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
102102

103103
if(!options.noHover) {
104104
if(axType !== 'category') coerce('hoverformat');
105-
if(!options.noUnifiedhovertitle) coerce('unifiedhovertitle');
105+
if(!options.noUnifiedhovertitle) {
106+
coerce('unifiedhovertitle.text');
107+
}
106108
}
107109

108110
var dfltColor = coerce('color');

src/plots/cartesian/layout_attributes.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,16 @@ module.exports = {
977977
description: descriptionWithDates('hover text')
978978
},
979979
unifiedhovertitle: {
980-
valType: 'string',
981-
dflt: '',
982-
editType: 'none',
983-
description: [
984-
'Template string used for rendering the title that appear on x or y unified hover box.',
985-
templateFormatStringDescription()
986-
].join(' ')
980+
text : {
981+
valType: 'string',
982+
dflt: '',
983+
editType: 'none',
984+
description: [
985+
'Template string used for rendering the title that appear on x or y unified hover box.',
986+
templateFormatStringDescription()
987+
].join(' ')
988+
},
989+
editType: 'none'
987990
},
988991
// lines and grids
989992
showline: {

test/jasmine/tests/hover_label_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6911,7 +6911,7 @@ describe('hovermode: (x|y)unified', function() {
69116911
y: [2, 3, 1]
69126912
}], {
69136913
xaxis: {
6914-
unifiedhovertitle: 'X: %{x:.2f}',
6914+
unifiedhovertitle: { text: 'X: %{x:.2f}' },
69156915
},
69166916
hovermode: 'x unified',
69176917
showlegend: false,
@@ -6946,7 +6946,7 @@ describe('hovermode: (x|y)unified', function() {
69466946
}], {
69476947
xaxis: {
69486948
type: 'date',
6949-
unifiedhovertitle: 'X: %{x|%x %X}',
6949+
unifiedhovertitle: { text: 'X: %{x|%x %X}' },
69506950
},
69516951
hovermode: 'x unified',
69526952
showlegend: false,

test/plot-schema.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14985,10 +14985,14 @@
1498514985
"valType": "any"
1498614986
},
1498714987
"unifiedhovertitle": {
14988-
"description": "Template string used for rendering the title that appear on x or y unified hover box. 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.",
14989-
"dflt": "",
1499014988
"editType": "none",
14991-
"valType": "string"
14989+
"role": "object",
14990+
"text": {
14991+
"description": "Template string used for rendering the title that appear on x or y unified hover box. 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.",
14992+
"dflt": "",
14993+
"editType": "none",
14994+
"valType": "string"
14995+
}
1499214996
},
1499314997
"visible": {
1499414998
"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",
@@ -16246,10 +16250,14 @@
1624616250
"valType": "any"
1624716251
},
1624816252
"unifiedhovertitle": {
16249-
"description": "Template string used for rendering the title that appear on x or y unified hover box. 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.",
16250-
"dflt": "",
1625116253
"editType": "none",
16252-
"valType": "string"
16254+
"role": "object",
16255+
"text": {
16256+
"description": "Template string used for rendering the title that appear on x or y unified hover box. 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.",
16257+
"dflt": "",
16258+
"editType": "none",
16259+
"valType": "string"
16260+
}
1625316261
},
1625416262
"visible": {
1625516263
"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",

0 commit comments

Comments
 (0)