]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Correct calculation of padding in percent (#5846)
authorchtheis <theis@gmx.at>
Wed, 21 Nov 2018 08:35:49 +0000 (09:35 +0100)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Wed, 21 Nov 2018 08:35:49 +0000 (09:35 +0100)
src/core/core.helpers.js
test/specs/core.helpers.tests.js

index 4b0a18c1648bc8d07f623db74a61f86bc7265e1f..3b1eca5edb31cc137f70c14ea89c9beeb9b93470 100644 (file)
@@ -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
index de6d0b41301351f43f3fcb92f1fc21ed2b85343e..70f0981df0ec63905d78473bc5f24760ab36efc0 100644 (file)
@@ -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';