Skip to content

Commit 14b31a1

Browse files
committed
provide description for hover on other positions
1 parent f83a962 commit 14b31a1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/plots/template_attributes.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ var docs = require('../constants/docs');
44
var FORMAT_LINK = docs.FORMAT_LINK;
55
var DATE_FORMAT_LINK = docs.DATE_FORMAT_LINK;
66

7-
var templateFormatStringDescription = [
8-
'Variables are inserted using %{variable}, for example "y: %{y}".',
9-
'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{y:$.2f}".',
10-
FORMAT_LINK,
11-
'for details on the formatting syntax.',
12-
'Dates are formatted using d3-time-format\'s syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}".',
13-
DATE_FORMAT_LINK,
14-
'for details on the date formatting syntax.'
15-
].join(' ');
7+
function templateFormatStringDescription(opts) {
8+
var supportOther = opts && opts.supportOther;
9+
10+
return [
11+
'Variables are inserted using %{variable},',
12+
'for example "y: %{y}".' + (supportOther ? ' as well as %{xother} when positions do not match' : ''),
13+
'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{y:$.2f}".',
14+
FORMAT_LINK,
15+
'for details on the formatting syntax.',
16+
'Dates are formatted using d3-time-format\'s syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}".',
17+
DATE_FORMAT_LINK,
18+
'for details on the date formatting syntax.'
19+
].join(' ');
20+
}
1621

1722
function describeVariables(extra) {
1823
var descPart = extra.description ? ' ' + extra.description : '';
@@ -45,7 +50,7 @@ exports.hovertemplateAttrs = function(opts, extra) {
4550
description: [
4651
'Template string used for rendering the information that appear on hover box.',
4752
'Note that this will override `hoverinfo`.',
48-
templateFormatStringDescription,
53+
templateFormatStringDescription({supportOther: true}),
4954
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data.',
5055
'Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
5156
descPart,
@@ -74,7 +79,7 @@ exports.texttemplateAttrs = function(opts, extra) {
7479
description: [
7580
'Template string used for rendering the information text that appear on points.',
7681
'Note that this will override `textinfo`.',
77-
templateFormatStringDescription,
82+
templateFormatStringDescription(),
7883
'Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
7984
descPart
8085
].join(' ')

0 commit comments

Comments
 (0)