Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layout.autoPadding option #9716

Merged
merged 1 commit into from Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.