Skip to content

Commit c62e632

Browse files
committed
move grouptitlefont inside legend object
1 parent ebb9c63 commit c62e632

File tree

10 files changed

+68
-53
lines changed

10 files changed

+68
-53
lines changed

Diff for: draftlogs/6040_add.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Implement legendgrouptitlefont and hoverlabel.grouptitlefont [[#6040](https://github.com/plotly/plotly.js/pull/6040)]
1+
- Implement legend.grouptitlefont and hoverlabel.grouptitlefont [[#6040](https://github.com/plotly/plotly.js/pull/6040)]

Diff for: src/components/fx/hover.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,9 @@ function createHoverText(hoverData, opts) {
11031103
orientation: 'v'
11041104
}
11051105
};
1106-
var mockLayoutOut = {};
1106+
var mockLayoutOut = {
1107+
font: font
1108+
};
11071109
legendSupplyDefaults(mockLayoutIn, mockLayoutOut, gd._fullData);
11081110
var mockLegend = mockLayoutOut.legend;
11091111

Diff for: src/components/fx/hoverlabel_defaults.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ var isUnifiedHover = require('./helpers').isUnifiedHover;
77
module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts) {
88
opts = opts || {};
99

10+
var hasLegend =
11+
contOut.legend &&
12+
contOut.legend.font;
13+
1014
function inheritFontAttr(attr) {
1115
if(!opts.font[attr]) {
12-
opts.font[attr] = contOut.legend ? contOut.legend.font[attr] : contOut.font[attr];
16+
opts.font[attr] = hasLegend ? contOut.legend.font[attr] : contOut.font[attr];
1317
}
1418
}
1519

@@ -20,7 +24,7 @@ module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts
2024
inheritFontAttr('family');
2125
inheritFontAttr('color');
2226

23-
if(contOut.legend) {
27+
if(hasLegend) {
2428
if(!opts.bgcolor) opts.bgcolor = Color.combine(contOut.legend.bgcolor, contOut.paper_bgcolor);
2529
if(!opts.bordercolor) opts.bordercolor = contOut.legend.bordercolor;
2630
} else {

Diff for: src/components/legend/attributes.js

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ module.exports = {
3030
editType: 'legend',
3131
description: 'Sets the font used to text the legend items.'
3232
}),
33+
grouptitlefont: fontAttrs({
34+
editType: 'legend',
35+
description: [
36+
'Sets the font for group titles in legend.',
37+
'Defaults to `legend.font` with its size increased about 10%.'
38+
].join(' ')
39+
}),
3340
orientation: {
3441
valType: 'enumerated',
3542
values: ['v', 'h'],

Diff for: src/components/legend/defaults.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,39 @@ var Registry = require('../../registry');
44
var Lib = require('../../lib');
55
var Template = require('../../plot_api/plot_template');
66

7+
var plotsAttrs = require('../../plots/attributes');
78
var attributes = require('./attributes');
89
var basePlotLayoutAttributes = require('../../plots/layout_attributes');
910
var helpers = require('./helpers');
1011

1112

1213
module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
1314
var containerIn = layoutIn.legend || {};
15+
var containerOut = Template.newContainer(layoutOut, 'legend');
16+
17+
function coerce(attr, dflt) {
18+
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
19+
}
20+
21+
var trace;
22+
23+
function traceCoerce(attr, dflt) {
24+
var traceIn = trace._input;
25+
var traceOut = trace;
26+
return Lib.coerce(traceIn, traceOut, plotsAttrs, attr, dflt);
27+
}
28+
29+
var globalFont = layoutOut.font || {};
30+
var grouptitlefont = Lib.coerceFont(coerce, 'grouptitlefont', Lib.extendFlat({}, globalFont, {
31+
size: Math.round(globalFont.size * 1.1)
32+
}));
1433

1534
var legendTraceCount = 0;
1635
var legendReallyHasATrace = false;
1736
var defaultOrder = 'normal';
1837

1938
for(var i = 0; i < fullData.length; i++) {
20-
var trace = fullData[i];
39+
trace = fullData[i];
2140

2241
if(!trace.visible) continue;
2342

@@ -44,6 +63,8 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
4463
legendTraceCount++;
4564
}
4665
}
66+
67+
Lib.coerceFont(traceCoerce, 'legendgrouptitle.font', grouptitlefont);
4768
}
4869

4970
if((Registry.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') ||
@@ -64,12 +85,6 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
6485

6586
if(showLegend === false && !containerIn.uirevision) return;
6687

67-
var containerOut = Template.newContainer(layoutOut, 'legend');
68-
69-
function coerce(attr, dflt) {
70-
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
71-
}
72-
7388
coerce('uirevision', layoutOut.uirevision);
7489

7590
if(showLegend === false) return;

Diff for: src/plot_api/plot_api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ function cleanDeprecatedAttributeKeys(aobj) {
17191719
if((key === 'title' || oldAxisTitleRegex.test(key) || colorbarRegex.test(key)) &&
17201720
(typeof value === 'string' || typeof value === 'number')) {
17211721
replace(key, key.replace('title', 'title.text'));
1722-
} else if(key.indexOf('titlefont') > -1) {
1722+
} else if(key.indexOf('titlefont') > -1 && key.indexOf('grouptitlefont') === -1) {
17231723
replace(key, key.replace('titlefont', 'title.font'));
17241724
} else if(key.indexOf('titleposition') > -1) {
17251725
replace(key, key.replace('titleposition', 'title.position'));

Diff for: src/plots/layout_attributes.js

-7
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,6 @@ module.exports = {
309309
'c) One trace is explicitly given with `showlegend: true`.'
310310
].join(' ')
311311
},
312-
legendgrouptitlefont: 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-
}),
319312

320313
colorway: {
321314
valType: 'colorlist',

Diff for: src/plots/plots.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,7 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
13211321
);
13221322

13231323
coerce('legendgroup');
1324-
var titleText = coerce('legendgrouptitle.text');
1325-
if(titleText) {
1326-
Lib.coerceFont(coerce, 'legendgrouptitle.font', layout.legendgrouptitlefont);
1327-
}
1328-
1324+
coerce('legendgrouptitle.text');
13291325
coerce('legendrank');
13301326

13311327
traceOut._dfltShowLegend = true;
@@ -1476,10 +1472,6 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
14761472
var font = Lib.coerceFont(coerce, 'font');
14771473
var fontSize = font.size;
14781474

1479-
Lib.coerceFont(coerce, 'legendgrouptitlefont', Lib.extendFlat({}, font, {
1480-
size: Math.round(fontSize * 1.1)
1481-
}));
1482-
14831475
Lib.coerceFont(coerce, 'title.font', Lib.extendFlat({}, font, {
14841476
size: Math.round(fontSize * 1.4)
14851477
}));

Diff for: test/image/mocks/legendrank.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
"size": 16
4545
}
4646
},
47-
"legendgrouptitlefont": {
48-
"family": "Times New Roman",
49-
"color": "orange",
50-
"size": 14
47+
"legend": {
48+
"grouptitlefont": {
49+
"family": "Times New Roman",
50+
"color": "orange",
51+
"size": 14
52+
}
5153
},
5254
"margin": {
5355
"t": 50,

Diff for: test/plot-schema.json

+21-21
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,27 @@
27142714
"togglegroup"
27152715
]
27162716
},
2717+
"grouptitlefont": {
2718+
"color": {
2719+
"editType": "legend",
2720+
"valType": "color"
2721+
},
2722+
"description": "Sets the font for group titles in legend. Defaults to `legend.font` with its size increased about 10%.",
2723+
"editType": "legend",
2724+
"family": {
2725+
"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*.",
2726+
"editType": "legend",
2727+
"noBlank": true,
2728+
"strict": true,
2729+
"valType": "string"
2730+
},
2731+
"role": "object",
2732+
"size": {
2733+
"editType": "legend",
2734+
"min": 1,
2735+
"valType": "number"
2736+
}
2737+
},
27172738
"itemclick": {
27182739
"description": "Determines the behavior on legend item click. *toggle* toggles the visibility of the item clicked on the graph. *toggleothers* makes the clicked item the sole visible item on the graph. *false* disables legend item click interactions.",
27192740
"dflt": "toggle",
@@ -2878,27 +2899,6 @@
28782899
]
28792900
}
28802901
},
2881-
"legendgrouptitlefont": {
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-
},
29022902
"mapbox": {
29032903
"_arrayAttrRegexps": [
29042904
{}

0 commit comments

Comments
 (0)