Skip to content

Commit 8ab0260

Browse files
authored
Merge pull request #5611 from plotly/legend-title-size
New defaults for colorbar.title.font and legend.title.font to depend on colorbar.tickfont and legend.font and increase their sizes
2 parents 65f739d + 7fda4b7 commit 8ab0260

File tree

74 files changed

+53
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+53
-30
lines changed

src/components/colorbar/defaults.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
4848

4949
handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
5050

51-
var opts = {outerTicks: false, font: layout.font};
51+
var font = layout.font;
52+
var opts = {outerTicks: false, font: font};
5253
if(ticklabelposition.indexOf('inside') !== -1) {
5354
opts.bgColor = 'black'; // could we instead use the average of colors in the scale?
5455
}
5556
handleTickLabelDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
5657
handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
5758

5859
coerce('title.text', layout._dfltTitle.colorbar);
59-
Lib.coerceFont(coerce, 'title.font', layout.font);
60+
61+
var tickFont = colorbarOut.tickfont;
62+
var dfltTitleFont = Lib.extendFlat({}, tickFont, {
63+
color: font.color,
64+
size: Lib.bigFont(tickFont.size)
65+
});
66+
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
6067
coerce('title.side');
6168
};

src/components/legend/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ module.exports = {
189189
font: fontAttrs({
190190
editType: 'legend',
191191
description: [
192-
'Sets this legend\'s title font.'
192+
'Sets this legend\'s title font.',
193+
'Defaults to `legend.font` with its size increased about 20%.'
193194
].join(' '),
194195
}),
195196
side: {

src/components/legend/defaults.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
7777
coerce('bgcolor', layoutOut.paper_bgcolor);
7878
coerce('bordercolor');
7979
coerce('borderwidth');
80-
Lib.coerceFont(coerce, 'font', layoutOut.font);
80+
var itemFont = Lib.coerceFont(coerce, 'font', layoutOut.font);
8181

8282
var orientation = coerce('orientation');
83+
var isHorizontal = orientation === 'h';
8384
var defaultX, defaultY, defaultYAnchor;
8485

85-
if(orientation === 'h') {
86+
if(isHorizontal) {
8687
defaultX = 0;
8788

8889
if(Registry.getComponentMethod('rangeslider', 'isVisible')(layoutIn.xaxis)) {
@@ -119,7 +120,11 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
119120

120121
var titleText = coerce('title.text');
121122
if(titleText) {
122-
coerce('title.side', orientation === 'h' ? 'left' : 'top');
123-
Lib.coerceFont(coerce, 'title.font', layoutOut.font);
123+
coerce('title.side', isHorizontal ? 'left' : 'top');
124+
var dfltTitleFont = Lib.extendFlat({}, itemFont, {
125+
size: Lib.bigFont(itemFont.size)
126+
});
127+
128+
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
124129
}
125130
};

src/components/legend/draw.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ function computeTextDimensions(g, gd, legendObj, aTitle) {
539539
// approximation to height offset to center the font
540540
// to avoid getBoundingClientRect
541541
if(aTitle === MAIN_TITLE) {
542+
if(legendObj.title.side === 'left') {
543+
// add extra space between legend title and itmes
544+
width += constants.itemGap * 2;
545+
}
546+
542547
svgTextUtils.positionText(textEl,
543548
bw + constants.titlePad,
544549
bw + lineHeight

src/lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,3 +1263,7 @@ lib.join2 = function(arr, mainSeparator, lastSeparator) {
12631263
}
12641264
return arr.join(mainSeparator);
12651265
};
1266+
1267+
lib.bigFont = function(size) {
1268+
return Math.round(1.2 * size);
1269+
};

src/plots/cartesian/axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ axes.prepTicks = function(ax, opts) {
554554

555555
if(!nt) {
556556
if(ax.type === 'category' || ax.type === 'multicategory') {
557-
minPx = ax.tickfont ? (ax.tickfont.size || 12) * 1.2 : 15;
557+
minPx = ax.tickfont ? Lib.bigFont(ax.tickfont.size || 12) : 15;
558558
nt = ax._length / minPx;
559559
} else {
560560
minPx = ax._id.charAt(0) === 'y' ? 40 : 80;

src/plots/cartesian/axis_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
116116
coerce('title.text', dfltTitle);
117117
Lib.coerceFont(coerce, 'title.font', {
118118
family: font.family,
119-
size: Math.round(font.size * 1.2),
119+
size: Lib.bigFont(font.size),
120120
color: dfltFontColor
121121
});
122122

src/plots/polar/layout_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
9898
coerceAxis('title.text');
9999
Lib.coerceFont(coerceAxis, 'title.font', {
100100
family: opts.font.family,
101-
size: Math.round(opts.font.size * 1.2),
101+
size: Lib.bigFont(opts.font.size),
102102
color: dfltFontColor
103103
});
104104
}

src/plots/ternary/layout_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut
8282

8383
Lib.coerceFont(coerce, 'title.font', {
8484
family: options.font.family,
85-
size: Math.round(options.font.size * 1.2),
85+
size: Lib.bigFont(options.font.size),
8686
color: dfltFontColor
8787
});
8888

src/traces/carpet/axis_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
110110
if(title) {
111111
Lib.coerceFont(coerce, 'title.font', {
112112
family: font.family,
113-
size: Math.round(font.size * 1.2),
113+
size: Lib.bigFont(font.size),
114114
color: dfltFontColor
115115
});
116116
coerce('title.offset');

0 commit comments

Comments
 (0)