]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Handle font sizes that are set as strings (#6921)
authorEvert Timberg <evert.timberg+github@gmail.com>
Mon, 6 Jan 2020 12:40:49 +0000 (07:40 -0500)
committerGitHub <noreply@github.com>
Mon, 6 Jan 2020 12:40:49 +0000 (07:40 -0500)
src/helpers/helpers.options.js
test/specs/helpers.options.tests.js

index 15e20f1610387db0db8539d5370825d479e1e56e..4eb84707cd7eaf769c1156e215a455fdaaf34b47 100644 (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,
index f41dde4fb52ee71400ea5752624f8e2b9fa39437..268e9a9f6b243862a5976f1050c45716304ac4bf 100644 (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;