mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Handle font sizes that are set as strings (#6921)
This commit is contained in:
parent
b5d5ed987a
commit
ac85ce41db
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user