Skip to content

Commit

Permalink
Consider dynamically positioned scales for padding (#8868)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Apr 10, 2021
1 parent ba84cc5 commit 1ffdecf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/core/core.layouts.js
Expand Up @@ -93,16 +93,15 @@ function updateDims(chartArea, params, layout) {
const box = layout.box;
const maxPadding = chartArea.maxPadding;

if (isObject(layout.pos)) {
// dynamically placed boxes are not considered
return {same: false, other: false};
}
if (layout.size) {
// this layout was already counted for, lets first reduce old size
chartArea[layout.pos] -= layout.size;
// dynamically placed boxes size is not considered
if (!isObject(layout.pos)) {
if (layout.size) {
// this layout was already counted for, lets first reduce old size
chartArea[layout.pos] -= layout.size;
}
layout.size = layout.horizontal ? box.height : box.width;
chartArea[layout.pos] += layout.size;
}
layout.size = layout.horizontal ? box.height : box.width;
chartArea[layout.pos] += layout.size;

if (box.getPadding) {
updateMaxPadding(maxPadding, box.getPadding());
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/core.scale/x-axis-position-dynamic-margin.js
@@ -0,0 +1,27 @@
module.exports = {
config: {
type: 'line',
options: {
scales: {
x: {
labels: ['Left Label', 'Center Label', 'Right Label'],
position: {
y: 30
},
},
y: {
display: false,
min: -100,
max: 100,
}
}
}
},
options: {
canvas: {
height: 256,
width: 512
},
spriteText: true
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/core.scale/x-axis-position-dynamic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1ffdecf

Please sign in to comment.