mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-21 23:56:52 +01:00
Font validate style, move defaults to weight (#8877)
This commit is contained in:
@@ -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: ''
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ export default {
|
||||
align: 'center',
|
||||
display: false,
|
||||
font: {
|
||||
style: 'bold',
|
||||
weight: 'bold',
|
||||
},
|
||||
fullSize: true,
|
||||
padding: 10,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user