Skip to content

Commit

Permalink
Add layout.autoPadding option (#9716)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 4, 2021
1 parent 0d4880e commit e1ae5e6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/configuration/layout.md
Expand Up @@ -4,4 +4,5 @@ Namespace: `options.layout`, the global options for the chart layout is defined

| Name | Type | Default | [Scriptable](../general/options.md#scriptable-options) | Description
| ---- | ---- | ------- | :----: | -----------
| `autoPadding` | `boolean` | `true` | No | Apply automatic padding so visible elements are completely drawn.
| `padding` | [`Padding`](../general/padding.md) | `0` | Yes | The padding to add inside the chart.
10 changes: 5 additions & 5 deletions src/core/core.controller.js
Expand Up @@ -422,21 +422,21 @@ class Chart {
const config = this.config;

config.update();
this._options = config.createResolver(config.chartOptionScopes(), this.getContext());
const options = this._options = config.createResolver(config.chartOptionScopes(), this.getContext());

each(this.scales, (scale) => {
layouts.removeBox(this, scale);
});

const animsDisabled = this._animationsDisabled = !this.options.animation;
const animsDisabled = this._animationsDisabled = !options.animation;

this.ensureScalesHaveIDs();
this.buildOrUpdateScales();

const existingEvents = new Set(Object.keys(this._listeners));
const newEvents = new Set(this.options.events);
const newEvents = new Set(options.events);

if (!setsEqual(existingEvents, newEvents) || !!this._responsiveListeners !== this.options.responsive) {
if (!setsEqual(existingEvents, newEvents) || !!this._responsiveListeners !== options.responsive) {
// The configured events have changed. Rebind.
this.unbindEvents();
this.bindEvents();
Expand Down Expand Up @@ -465,7 +465,7 @@ class Chart {
controller.buildOrUpdateElements(reset);
minPadding = Math.max(+controller.getMaxOverflow(), minPadding);
}
this._minPadding = minPadding;
minPadding = this._minPadding = options.layout.autoPadding ? minPadding : 0;
this._updateLayout(minPadding);

// Only reset the controllers if we have animations
Expand Down
1 change: 1 addition & 0 deletions src/core/core.layouts.js
Expand Up @@ -260,6 +260,7 @@ function placeBoxes(boxes, chartArea, params, stacks) {
}

defaults.set('layout', {
autoPadding: true,
padding: {
top: 0,
right: 0,
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/controller.bubble/autoPadding-disabled.js
@@ -0,0 +1,26 @@
module.exports = {
config: {
type: 'bubble',
data: {
datasets: [{
backgroundColor: 'red',
data: [{x: 12, y: 54, r: 22.4}]
}, {
backgroundColor: 'blue',
data: [{x: 18, y: 38, r: 25}]
}]
},
options: {
layout: {
autoPadding: false,
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
}
}
};
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 e1ae5e6

Please sign in to comment.