Skip to content

Commit 61a2da7

Browse files
committed
list available variables in pie's hovertemplate description
1 parent 1e4bd33 commit 61a2da7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/components/fx/hovertemplate_attributes.js

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ module.exports = function(opts, extra) {
1313
extra = extra || {};
1414

1515
var descPart = extra.description ? ' ' + extra.description : '';
16+
var keys = extra.keys || [];
17+
if(keys.length > 0) {
18+
for(var i = 0; i < keys.length; i++) {
19+
keys[i] = '`' + keys[i] + '`';
20+
}
21+
descPart = descPart + 'This trace supports the additional ';
22+
if(keys.length === 1) {
23+
descPart = 'variable ' + keys[0];
24+
} else {
25+
descPart = 'variables ' + keys.slice(0, -1).join(', ') + ' and ' + keys.slice(-1) + '.';
26+
}
27+
}
1628

1729
var hovertemplate = {
1830
valType: 'string',
@@ -26,6 +38,7 @@ module.exports = function(opts, extra) {
2638
'Variables are inserted using %{variable}, for example "y: %{y}".',
2739
'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{y:$.2f}".',
2840
'See https://github.com/d3/d3-format/blob/master/README.md#locale_format for details on the formatting syntax.',
41+
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plot.ly/javascript/plotlyjs-events/#event-data.',
2942
descPart
3043
].join(' ')
3144
};

src/traces/pie/attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ module.exports = {
159159
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
160160
flags: ['label', 'text', 'value', 'percent', 'name']
161161
}),
162-
hovertemplate: hovertemplateAttrs(),
162+
hovertemplate: hovertemplateAttrs({}, {
163+
keys: ['label', 'color', 'value', 'percent', 'text']
164+
}),
163165
textposition: {
164166
valType: 'enumerated',
165167
role: 'info',

0 commit comments

Comments
 (0)