mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Correct calculation of padding in percent (#5846)
This commit is contained in:
parent
bc494e0a81
commit
b68341d9b8
@ -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
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user