Skip to content

Commit 150f0c8

Browse files
committed
introduce overrideDflt option for coerceFont
1 parent 58cfeb3 commit 150f0c8

File tree

12 files changed

+47
-112
lines changed

12 files changed

+47
-112
lines changed

src/components/legend/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
3333
};
3434

3535
var globalFont = layoutOut.font || {};
36-
var grouptitlefont = Lib.coerceFont(coerce, 'grouptitlefont', Lib.extendFlat({}, globalFont, {
36+
var grouptitlefont = Lib.coerceFont(coerce, 'grouptitlefont', globalFont, { overrideDflt: {
3737
size: Math.round(globalFont.size * 1.1)
38-
}));
38+
}});
3939

4040
var legendTraceCount = 0;
4141
var legendReallyHasATrace = false;

src/lib/coerce.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var isNumeric = require('fast-isnumeric');
44
var tinycolor = require('tinycolor2');
55

6+
var extendFlat = require('./extend').extendFlat;
7+
68
var baseTraceAttrs = require('../plots/attributes');
79
var colorscales = require('../components/colorscale/scales');
810
var Color = require('../components/color');
@@ -457,17 +459,17 @@ exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dfl
457459
*/
458460
exports.coerceFont = function(coerce, attr, dfltObj, opts) {
459461
if(!opts) opts = {};
462+
dfltObj = extendFlat({}, dfltObj);
463+
dfltObj = extendFlat(dfltObj, opts.overrideDflt || {});
460464

461-
var out = {};
462-
463-
dfltObj = dfltObj || {};
464-
465-
out.family = coerce(attr + '.family', dfltObj.family);
466-
out.size = coerce(attr + '.size', dfltObj.size);
467-
out.color = coerce(attr + '.color', dfltObj.color);
465+
var out = {
466+
family: coerce(attr + '.family', dfltObj.family),
467+
size: coerce(attr + '.size', dfltObj.size),
468+
color: coerce(attr + '.color', dfltObj.color),
469+
weight: coerce(attr + '.weight', dfltObj.weight),
470+
style: coerce(attr + '.style', dfltObj.style),
471+
};
468472

469-
out.weight = coerce(attr + '.weight', dfltObj.weight);
470-
out.style = coerce(attr + '.style', dfltObj.style);
471473
if(!opts.noFontVariant) out.variant = coerce(attr + '.variant', dfltObj.variant);
472474
if(!opts.noFontStriding) out.striding = coerce(attr + '.striding', dfltObj.striding);
473475
if(!opts.noFontCapitalize) out.capitalize = coerce(attr + '.capitalize', dfltObj.capitalize);

src/plots/cartesian/axis_defaults.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
111111
if(!visible) return containerOut;
112112

113113
coerce('title.text', dfltTitle);
114-
Lib.coerceFont(coerce, 'title.font', {
115-
family: font.family,
116-
weight: font.weight,
117-
style: font.style,
118-
variant: font.variant,
119-
capitalize: font.capitalize,
120-
striding: font.striding,
121-
shadow: font.shadow,
114+
Lib.coerceFont(coerce, 'title.font', font, { overrideDflt: {
122115
size: Lib.bigFont(font.size),
123116
color: dfltFontColor
124-
});
117+
}});
125118

126119
// major ticks
127120
handleTickValueDefaults(containerIn, containerOut, coerce, axType);

src/plots/cartesian/tick_label_defaults.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
2626
(contColor && contColor !== layoutAttributes.color.dflt) ?
2727
contColor : font.color;
2828

29-
Lib.coerceFont(coerce, 'tickfont', {
30-
family: font.family,
31-
weight: font.weight,
32-
style: font.style,
33-
variant: font.variant,
34-
capitalize: font.capitalize,
35-
striding: font.striding,
36-
shadow: font.shadow,
37-
size: font.size,
29+
Lib.coerceFont(coerce, 'tickfont', font, { overrideDflt: {
3830
color: dfltFontColor
39-
});
31+
}});
4032

4133
if(
4234
!options.noTicklabelstep &&

src/plots/plots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,9 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
14761476
var font = Lib.coerceFont(coerce, 'font');
14771477
var fontSize = font.size;
14781478

1479-
Lib.coerceFont(coerce, 'title.font', Lib.extendFlat({}, font, {
1479+
Lib.coerceFont(coerce, 'title.font', font, { overrideDflt: {
14801480
size: Math.round(fontSize * 1.4)
1481-
}));
1481+
}});
14821482

14831483
coerce('title.text', layoutOut._dfltTitle.plot);
14841484
coerce('title.xref');

src/plots/ternary/layout_defaults.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,10 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut
8181
var title = coerce('title.text', dfltTitle);
8282
containerOut._hovertitle = title === dfltTitle ? title : letterUpper;
8383

84-
Lib.coerceFont(coerce, 'title.font', {
85-
weight: options.font.weight,
86-
style: options.font.style,
87-
variant: options.font.variant,
88-
capitalize: options.font.capitalize,
89-
striding: options.font.striding,
90-
shadow: options.font.shadow,
91-
family: options.font.family,
84+
Lib.coerceFont(coerce, 'title.font', options.font, { overrideDflt: {
9285
size: Lib.bigFont(options.font.size),
9386
color: dfltFontColor
94-
});
87+
}});
9588

9689
// range is just set by 'min' - max is determined by the other axes mins
9790
coerce('min');
@@ -104,17 +97,9 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut
10497

10598
var showTickLabels = coerce('showticklabels');
10699
if(showTickLabels) {
107-
Lib.coerceFont(coerce, 'tickfont', {
108-
weight: options.font.weight,
109-
style: options.font.style,
110-
variant: options.font.variant,
111-
capitalize: options.font.capitalize,
112-
striding: options.font.striding,
113-
shadow: options.font.shadow,
114-
family: options.font.family,
115-
size: options.font.size,
100+
Lib.coerceFont(coerce, 'tickfont', options.font, { overrideDflt: {
116101
color: dfltFontColor
117-
});
102+
}});
118103
coerce('tickangle');
119104
coerce('tickformat');
120105
}

src/traces/carpet/axis_defaults.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
109109

110110
var title = coerce('title.text');
111111
if(title) {
112-
Lib.coerceFont(coerce, 'title.font', {
113-
weight: font.weight,
114-
style: font.style,
115-
variant: font.variant,
116-
capitalize: font.capitalize,
117-
striding: font.striding,
118-
shadow: font.shadow,
119-
family: font.family,
112+
Lib.coerceFont(coerce, 'title.font', font, { overrideDflt: {
120113
size: Lib.bigFont(font.size),
121114
color: dfltFontColor
122-
});
115+
}});
123116
coerce('title.offset');
124117
}
125118

src/traces/contour/label_defaults.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ module.exports = function handleLabelDefaults(coerce, layout, lineColor, opts) {
77
var showLabels = coerce('contours.showlabels');
88
if(showLabels) {
99
var globalFont = layout.font;
10-
Lib.coerceFont(coerce, 'contours.labelfont', {
11-
weight: globalFont.weight,
12-
style: globalFont.style,
13-
variant: globalFont.variant,
14-
capitalize: globalFont.capitalize,
15-
striding: globalFont.striding,
16-
shadow: globalFont.shadow,
17-
family: globalFont.family,
18-
size: globalFont.size,
10+
Lib.coerceFont(coerce, 'contours.labelfont', globalFont, { overrideDflt: {
1911
color: lineColor
20-
});
12+
}});
2113
coerce('contours.labelformat');
2214
}
2315

src/traces/parcats/defaults.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,18 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9595
coerce('sortpaths');
9696
coerce('counts');
9797

98-
var labelfontDflt = {
99-
weight: layout.font.weight,
100-
style: layout.font.style,
101-
variant: layout.font.variant,
102-
capitalize: layout.font.capitalize,
103-
striding: layout.font.striding,
104-
shadow: layout.font.shadow,
105-
family: layout.font.family,
106-
size: Math.round(layout.font.size),
107-
color: layout.font.color
108-
};
109-
110-
Lib.coerceFont(coerce, 'labelfont', labelfontDflt);
111-
112-
var categoryfontDefault = {
113-
weight: layout.font.weight,
114-
style: layout.font.style,
115-
variant: layout.font.variant,
116-
capitalize: layout.font.capitalize,
117-
striding: layout.font.striding,
118-
shadow: layout.font.shadow,
119-
family: layout.font.family,
120-
size: Math.round(layout.font.size / 1.2),
121-
color: layout.font.color
122-
};
123-
124-
Lib.coerceFont(coerce, 'tickfont', categoryfontDefault, { autoShadowDflt: true });
98+
var layoutFont = layout.font;
99+
100+
Lib.coerceFont(coerce, 'labelfont', layoutFont, {
101+
overrideDflt: {
102+
size: Math.round(layoutFont.size)
103+
}
104+
});
105+
106+
Lib.coerceFont(coerce, 'tickfont', layoutFont, {
107+
autoShadowDflt: true,
108+
overrideDflt: {
109+
size: Math.round(layoutFont.size / 1.2)
110+
}
111+
});
125112
};

src/traces/parcoords/defaults.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9595

9696
// make default font size 10px (default is 12),
9797
// scale linearly with global font size
98-
var fontDflt = {
99-
weight: layout.font.weight,
100-
style: layout.font.style,
101-
variant: layout.font.variant,
102-
capitalize: layout.font.capitalize,
103-
striding: layout.font.striding,
104-
shadow: layout.font.shadow,
105-
family: layout.font.family,
106-
size: Math.round(layout.font.size / 1.2),
107-
color: layout.font.color
108-
};
98+
var fontDflt = Lib.extendFlat({}, layout.font, {
99+
size: Math.round(layout.font.size / 1.2)
100+
});
109101

110102
Lib.coerceFont(coerce, 'labelfont', fontDflt);
111103
Lib.coerceFont(coerce, 'tickfont', fontDflt, { autoShadowDflt: true });

0 commit comments

Comments
 (0)