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 resizeDelay option #8509

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/configuration/responsive.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Namespace: `options`
| `maintainAspectRatio` | `boolean` | `true` | Maintain the original canvas aspect ratio `(width / height)` when resizing.
| `aspectRatio` | `number` | `2` | Canvas aspect ratio (i.e. `width / height`, a value of 1 representing a square canvas). Note that this option is ignored if the height is explicitly defined either as attribute or via the style.
| `onResize` | `function` | `null` | Called when a resize occurs. Gets passed two arguments: the chart instance and the new size.
| `resizeDelay` | `number` | `0` | Delay the resize update by give amount of milliseconds. This can ease the resize process by debouncing update of the elements.

## Important Note

Expand Down
11 changes: 10 additions & 1 deletion src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Chart {
this.attached = false;
this._animationsDisabled = undefined;
this.$context = undefined;
this._resizeTimer = undefined;

// Add the chart instance to the global namespace
instances[me.id] = me;
Expand Down Expand Up @@ -242,7 +243,15 @@ class Chart {
callCallback(options.onResize, [newSize], me);

if (me.attached) {
me.update('resize');
const delay = options.resizeDelay || 0;
const resizeUpdate = () => me.update('resize');
if (delay) {
clearTimeout(me._resizeTimer);
me._resizeTimer = setTimeout(resizeUpdate, delay);
me.render();
} else {
resizeUpdate();
}
}
}

Expand Down