Skip to content

Commit acce9bf

Browse files
committed
Add hoverlabel.zformat attribute
1 parent f1faa28 commit acce9bf

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

src/components/fx/attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ module.exports = {
5050
'`namelength - 3` characters and add an ellipsis.'
5151
].join(' ')
5252
},
53+
zformat: {
54+
valType: 'string',
55+
dflt: '',
56+
role: 'style',
57+
editType: 'none',
58+
description: [
59+
'Sets the hover text formatting rule using d3 formatting mini-languages',
60+
'which are very similar to those in Python. See:',
61+
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
62+
].join(' ')
63+
},
5364
editType: 'calc'
5465
}
5566
};

src/components/fx/calc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = function calc(gd) {
4242
fillFn(trace.hoverlabel.font.color, cd, 'htc');
4343
fillFn(trace.hoverlabel.font.family, cd, 'htf');
4444
fillFn(trace.hoverlabel.namelength, cd, 'hnl');
45+
fillFn(trace.hoverlabel.zformat, cd, 'hzf');
4546
}
4647
};
4748

src/components/fx/hover.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ function cleanPoint(d, hovermode) {
10541054
fill('fontSize', 'hts', 'hoverlabel.font.size');
10551055
fill('fontColor', 'htc', 'hoverlabel.font.color');
10561056
fill('nameLength', 'hnl', 'hoverlabel.namelength');
1057+
fill('zformat', 'hzf', 'hoverlabel.zformat');
10571058

10581059
d.posref = hovermode === 'y' ? (d.x0 + d.x1) / 2 : (d.y0 + d.y1) / 2;
10591060

@@ -1095,7 +1096,13 @@ function cleanPoint(d, hovermode) {
10951096
d.yVal = d.ya.c2d(d.yLabelVal);
10961097
}
10971098

1098-
if(d.zLabelVal !== undefined) d.zLabel = String(d.zLabelVal);
1099+
if(d.zLabelVal !== undefined) {
1100+
if(d.zformat !== undefined) {
1101+
d.zLabel = d3.format(d.zformat)(d.zLabelVal).replace(/-/g, constants.MINUS_SIGN);
1102+
} else {
1103+
d.zLabel = String(d.zLabelVal);
1104+
}
1105+
}
10991106

11001107
// for box means and error bars, add the range to the label
11011108
if(!isNaN(d.xerr) && !(d.xa.type === 'log' && d.xerr <= 0)) {

src/components/fx/hoverlabel_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts
1616
coerce('hoverlabel.bgcolor', opts.bgcolor);
1717
coerce('hoverlabel.bordercolor', opts.bordercolor);
1818
coerce('hoverlabel.namelength', opts.namelength);
19+
coerce('hoverlabel.zformat', opts.zformat);
1920
Lib.coerceFont(coerce, 'hoverlabel.font', opts.font);
2021
};

src/components/fx/layout_attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ module.exports = {
7272
'`namelength - 3` characters and add an ellipsis.'
7373
].join(' ')
7474
},
75+
zformat: {
76+
valType: 'string',
77+
dflt: '',
78+
role: 'style',
79+
editType: 'none',
80+
description: [
81+
'Sets the hover text formatting rule using d3 formatting mini-languages',
82+
'which are very similar to those in Python. See:',
83+
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
84+
].join(' ')
85+
},
7586
editType: 'none'
7687
}
7788
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"data": [
3+
{
4+
"z": [
5+
[
6+
0.123456789,
7+
10.123456789,
8+
20.123456789
9+
]
10+
],
11+
"type": "heatmap"
12+
},
13+
{
14+
"x": [0,1,2],
15+
"y": [2, 2, 2],
16+
"z": [
17+
1.123456789,
18+
2.123456789,
19+
3.123456789
20+
],
21+
"type": "heatmap",
22+
"hoverlabel": {
23+
"zformat": "undefined"
24+
},
25+
"zmin": 0,
26+
"zmax": 20,
27+
"showscale": false
28+
}
29+
],
30+
"layout": {
31+
"title": "XXX",
32+
"xaxis": {
33+
"hoverformat": ".1f"
34+
},
35+
"hoverlabel": {
36+
"zformat": ".2f"
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)