From: Simon Brunel Date: Sat, 18 Mar 2017 10:54:56 +0000 (+0100) Subject: Correctly handle decimal display size (#4009) X-Git-Tag: v2.6.0~2^2~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd60fa2dfd25bae95520e7968a72eecac218f7ba;p=thirdparty%2FChart.js.git Correctly handle decimal display size (#4009) Fix the `readUsedSize` regular expression to correctly parse (truncate) pixel decimal values. --- diff --git a/src/platforms/platform.dom.js b/src/platforms/platform.dom.js index 761337b06..317d4bfed 100644 --- a/src/platforms/platform.dom.js +++ b/src/platforms/platform.dom.js @@ -33,7 +33,7 @@ module.exports = function(Chart) { */ function readUsedSize(element, property) { var value = helpers.getStyle(element, property); - var matches = value && value.match(/(\d+)px/); + var matches = value && value.match(/^(\d+)(\.\d+)?px$/); return matches? Number(matches[1]) : undefined; } diff --git a/test/specs/platform.dom.tests.js b/test/specs/platform.dom.tests.js index 06562c919..898de9c48 100644 --- a/test/specs/platform.dom.tests.js +++ b/test/specs/platform.dom.tests.js @@ -226,6 +226,24 @@ describe('Platform.dom', function() { rw: 165, rh: 85, }); }); + + // https://github.com/chartjs/Chart.js/issues/3860 + it('should support decimal display width and/or height', function() { + var chart = acquireChart({ + options: { + responsive: false + } + }, { + canvas: { + style: 'width: 345.42px; height: 125.42px;' + } + }); + + expect(chart).toBeChartOfSize({ + dw: 345, dh: 125, + rw: 345, rh: 125, + }); + }); }); describe('config.options.responsive: true (maintainAspectRatio: true)', function() {