Font validate style, move defaults to weight (#8877)

This commit is contained in:
Jukka Kurkela
2021-04-10 22:58:11 +03:00
committed by GitHub
parent 9e70913bed
commit f8885ce7a2
13 changed files with 53 additions and 46 deletions

View File

@@ -3,6 +3,7 @@ import {isArray, isObject, toDimension, valueOrDefault} from './helpers.core';
import {toFontString} from './helpers.canvas';
const LINE_HEIGHT = new RegExp(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
const FONT_STYLE = new RegExp(/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/);
/**
* @alias Chart.helpers.options
@@ -95,6 +96,7 @@ export function toPadding(value) {
return obj;
}
/**
* Parses font options and returns the font object.
* @param {object} options - A object that contains font options to be parsed.
@@ -111,12 +113,17 @@ export function toFont(options, fallback) {
if (typeof size === 'string') {
size = parseInt(size, 10);
}
let style = valueOrDefault(options.style, fallback.style);
if (style && !('' + style).match(FONT_STYLE)) {
console.warn('Invalid font style specified: "' + style + '"');
style = '';
}
const font = {
family: valueOrDefault(options.family, fallback.family),
lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size),
size,
style: valueOrDefault(options.style, fallback.style),
style,
weight: valueOrDefault(options.weight, fallback.weight),
string: ''
};

View File

@@ -148,7 +148,7 @@ export default {
align: 'center',
display: false,
font: {
style: 'bold',
weight: 'bold',
},
fullSize: true,
padding: 10,

View File

@@ -1143,7 +1143,7 @@ export default {
backgroundColor: 'rgba(0,0,0,0.8)',
titleColor: '#fff',
titleFont: {
style: 'bold',
weight: 'bold',
},
titleSpacing: 2,
titleMarginBottom: 6,
@@ -1157,7 +1157,7 @@ export default {
footerSpacing: 2,
footerMarginTop: 6,
footerFont: {
style: 'bold',
weight: 'bold',
},
footerAlign: 'left',
padding: 6,