Handle font sizes that are set as strings (#6921)

This commit is contained in:
Evert Timberg 2020-01-06 07:40:49 -05:00 committed by GitHub
parent b5d5ed987a
commit ac85ce41db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -90,8 +90,13 @@ export function toPadding(value) {
* @private
*/
export function _parseFont(options) {
var size = valueOrDefault(options.fontSize, defaults.fontSize);
var font = {
let size = valueOrDefault(options.fontSize, defaults.fontSize);
if (typeof size === 'string') {
size = parseInt(size, 10);
}
const font = {
family: valueOrDefault(options.fontFamily, defaults.fontFamily),
lineHeight: toLineHeight(valueOrDefault(options.lineHeight, defaults.lineHeight), size),
size: size,

View File

@ -113,6 +113,21 @@ describe('Chart.helpers.options', function() {
weight: null
});
});
it ('should handle a string font size', function() {
expect(parseFont({
fontFamily: 'bla',
lineHeight: 8,
fontSize: '21',
fontStyle: 'zzz'
})).toEqual({
family: 'bla',
lineHeight: 8 * 21,
size: 21,
string: 'zzz 21px bla',
style: 'zzz',
weight: null
});
});
it('should return null as a font string if fontSize or fontFamily are missing', function() {
const fontFamily = Chart.defaults.fontFamily;
const fontSize = Chart.defaults.fontSize;