From: chtheis Date: Wed, 21 Nov 2018 08:35:49 +0000 (+0100) Subject: Correct calculation of padding in percent (#5846) X-Git-Tag: v2.8.0-rc.1~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b68341d9b888f0289edc7879619bdac86958709b;p=thirdparty%2FChart.js.git Correct calculation of padding in percent (#5846) --- diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 4b0a18c16..3b1eca5ed 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -499,7 +499,7 @@ module.exports = function() { helpers._calculatePadding = function(container, padding, parentDimension) { padding = helpers.getStyle(container, padding); - return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10); + return padding.indexOf('%') > -1 ? parentDimension * parseInt(padding, 10) / 100 : parseInt(padding, 10); }; /** * @private diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index de6d0b413..70f0981df 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -790,7 +790,7 @@ describe('Core helper tests', function() { div.style.height = '300px'; document.body.appendChild(div); - // Inner DIV to have 10% padding of parent + // Inner DIV to have 5% padding of parent var innerDiv = document.createElement('div'); div.appendChild(innerDiv); @@ -802,8 +802,8 @@ describe('Core helper tests', function() { expect(helpers.getMaximumWidth(canvas)).toBe(300); // test with percentage - innerDiv.style.padding = '10%'; - expect(helpers.getMaximumWidth(canvas)).toBe(240); + innerDiv.style.padding = '5%'; + expect(helpers.getMaximumWidth(canvas)).toBe(270); // test with pixels innerDiv.style.padding = '10px';