Skip to content

Commit c3a6458

Browse files
committed
implement grouptitlesfont for hover and legend
1 parent 2b01f3c commit c3a6458

File tree

8 files changed

+90
-15
lines changed

8 files changed

+90
-15
lines changed

src/components/fx/hover.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,8 @@ function createHoverText(hoverData, opts) {
11441144

11451145
// Draw unified hover label
11461146
mockLegend._inHover = true;
1147-
mockLegend._groupTitleFont = font;
1147+
mockLegend._groupTitleFont = hoverlabel.grouptitlesfont;
1148+
11481149
legendDraw(gd, mockLegend);
11491150

11501151
// Position the hover

src/components/fx/layout_attributes.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
var constants = require('./constants');
44

5-
var fontAttrs = require('../../plots/font_attributes')({
5+
var fontAttrs = require('../../plots/font_attributes');
6+
7+
var font = fontAttrs({
68
editType: 'none',
79
description: 'Sets the default hover label font used by all traces on the graph.'
810
});
9-
fontAttrs.family.dflt = constants.HOVERFONT;
10-
fontAttrs.size.dflt = constants.HOVERFONTSIZE;
11+
font.family.dflt = constants.HOVERFONT;
12+
font.size.dflt = constants.HOVERFONTSIZE;
1113

1214
module.exports = {
1315
clickmode: {
@@ -118,7 +120,7 @@ module.exports = {
118120
'Sets the border color of all hover labels on graph.'
119121
].join(' ')
120122
},
121-
font: fontAttrs,
123+
font: font,
122124
align: {
123125
valType: 'enumerated',
124126
values: ['left', 'right', 'auto'],
@@ -143,6 +145,14 @@ module.exports = {
143145
'`namelength - 3` characters and add an ellipsis.'
144146
].join(' ')
145147
},
148+
grouptitlesfont: fontAttrs({
149+
editType: 'none',
150+
description: [
151+
'Sets the font for group titles in hover (unified modes).',
152+
'Defaults to `hoverlabel.font`.'
153+
].join(' ')
154+
}),
155+
146156
editType: 'none'
147157
},
148158
selectdirection: {

src/components/fx/layout_defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
3434
}
3535

3636
handleHoverLabelDefaults(layoutIn, layoutOut, coerce);
37+
38+
Lib.coerceFont(coerce, 'hoverlabel.grouptitlesfont', layoutOut.hoverlabel.font);
3739
};

src/plots/layout_attributes.js

+8
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ module.exports = {
309309
'c) One trace is explicitly given with `showlegend: true`.'
310310
].join(' ')
311311
},
312+
legendgrouptitlesfont: fontAttrs({
313+
editType: 'legend',
314+
description: [
315+
'Sets the font for group titles in legend.',
316+
'Defaults to `legend.font` with its size increased about 10%.'
317+
].join(' ')
318+
}),
319+
312320
colorway: {
313321
valType: 'colorlist',
314322
dflt: colorAttrs.defaults,

src/plots/plots.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,7 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
13231323
coerce('legendgroup');
13241324
var titleText = coerce('legendgrouptitle.text');
13251325
if(titleText) {
1326-
Lib.coerceFont(coerce, 'legendgrouptitle.font', Lib.extendFlat({}, layout.font, {
1327-
size: Math.round(layout.font.size * 1.1) // default to larger font size
1328-
}));
1326+
Lib.coerceFont(coerce, 'legendgrouptitle.font', layout.legendgrouptitlesfont);
13291327
}
13301328

13311329
coerce('legendrank');
@@ -1475,16 +1473,18 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
14751473

14761474
coerce('autotypenumbers');
14771475

1478-
var globalFont = Lib.coerceFont(coerce, 'font');
1476+
var font = Lib.coerceFont(coerce, 'font');
1477+
var fontSize = font.size;
14791478

1480-
coerce('title.text', layoutOut._dfltTitle.plot);
1479+
Lib.coerceFont(coerce, 'legendgrouptitlesfont', Lib.extendFlat({}, font, {
1480+
size: Math.round(fontSize * 1.1)
1481+
}));
14811482

1482-
Lib.coerceFont(coerce, 'title.font', {
1483-
family: globalFont.family,
1484-
size: Math.round(globalFont.size * 1.4),
1485-
color: globalFont.color
1486-
});
1483+
Lib.coerceFont(coerce, 'title.font', Lib.extendFlat({}, font, {
1484+
size: Math.round(fontSize * 1.4)
1485+
}));
14871486

1487+
coerce('title.text', layoutOut._dfltTitle.plot);
14881488
coerce('title.xref');
14891489
coerce('title.yref');
14901490
coerce('title.x');

test/image/baselines/legendrank.png

-275 Bytes
Loading

test/image/mocks/legendrank.json

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
"text": "legendrank"
3838
},
3939
"hovermode": "x unified",
40+
"hoverlabel": {
41+
"grouptitlesfont": {
42+
"family": "Raleway",
43+
"color": "red",
44+
"size": 16
45+
}
46+
},
47+
"legendgrouptitlesfont": {
48+
"family": "Times New Roman",
49+
"color": "orange",
50+
"size": 14
51+
},
4052
"margin": {
4153
"t": 50,
4254
"b": 25

test/plot-schema.json

+42
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,27 @@
24942494
"valType": "number"
24952495
}
24962496
},
2497+
"grouptitlesfont": {
2498+
"color": {
2499+
"editType": "none",
2500+
"valType": "color"
2501+
},
2502+
"description": "Sets the font for group titles in hover (unified modes). Defaults to `hoverlabel.font`.",
2503+
"editType": "none",
2504+
"family": {
2505+
"description": "HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include *Arial*, *Balto*, *Courier New*, *Droid Sans*,, *Droid Serif*, *Droid Sans Mono*, *Gravitas One*, *Old Standard TT*, *Open Sans*, *Overpass*, *PT Sans Narrow*, *Raleway*, *Times New Roman*.",
2506+
"editType": "none",
2507+
"noBlank": true,
2508+
"strict": true,
2509+
"valType": "string"
2510+
},
2511+
"role": "object",
2512+
"size": {
2513+
"editType": "none",
2514+
"min": 1,
2515+
"valType": "number"
2516+
}
2517+
},
24972518
"namelength": {
24982519
"description": "Sets the default length (in number of characters) of the trace name in the hover labels for all traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, and an integer >3 will show the whole name if it is less than that many characters, but if it is longer, will truncate to `namelength - 3` characters and add an ellipsis.",
24992520
"dflt": 15,
@@ -2857,6 +2878,27 @@
28572878
]
28582879
}
28592880
},
2881+
"legendgrouptitlesfont": {
2882+
"color": {
2883+
"editType": "legend",
2884+
"valType": "color"
2885+
},
2886+
"description": "Sets the font for group titles in legend. Defaults to `legend.font` with its size increased about 10%.",
2887+
"editType": "legend",
2888+
"family": {
2889+
"description": "HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include *Arial*, *Balto*, *Courier New*, *Droid Sans*,, *Droid Serif*, *Droid Sans Mono*, *Gravitas One*, *Old Standard TT*, *Open Sans*, *Overpass*, *PT Sans Narrow*, *Raleway*, *Times New Roman*.",
2890+
"editType": "legend",
2891+
"noBlank": true,
2892+
"strict": true,
2893+
"valType": "string"
2894+
},
2895+
"role": "object",
2896+
"size": {
2897+
"editType": "legend",
2898+
"min": 1,
2899+
"valType": "number"
2900+
}
2901+
},
28602902
"mapbox": {
28612903
"_arrayAttrRegexps": [
28622904
{}

0 commit comments

Comments
 (0)