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

Disable animations for BasicPlatform (offcreen) #9751

Merged
merged 2 commits into from Oct 11, 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 src/core/core.controller.js
Expand Up @@ -86,6 +86,7 @@ class Chart {
const options = config.createResolver(config.chartOptionScopes(), this.getContext());

this.platform = new (config.platform || _detectPlatform(initialCanvas))();
this.platform.updateConfig(config);

const context = this.platform.acquireContext(initialCanvas, options.aspectRatio);
const canvas = context && context.canvas;
Expand Down
8 changes: 8 additions & 0 deletions src/platform/platform.base.js
Expand Up @@ -72,6 +72,14 @@ export default class BasePlatform {
isAttached(canvas) { // eslint-disable-line no-unused-vars
return true;
}

/**
* Updates config with platform specific requirements
* @param {import("../core/core.config").default} config
*/
updateConfig(config) { // eslint-disable-line no-unused-vars
// no-op
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/platform/platform.basic.js
Expand Up @@ -17,4 +17,7 @@ export default class BasicPlatform extends BasePlatform {
// https://github.com/chartjs/Chart.js/issues/2807
return item && item.getContext && item.getContext('2d') || null;
}
updateConfig(config) {
config.options.animation = false;
}
}
9 changes: 9 additions & 0 deletions test/specs/platform.basic.tests.js
Expand Up @@ -8,6 +8,15 @@ describe('Platform.basic', function() {
chart.destroy();
});

it('should disable animations', function() {
const chart = acquireChart({type: 'line', options: {animation: {}}}, {useOffscreenCanvas: true});

expect(chart.options.animation).toEqual(false);

chart.destroy();
});


it('supports choosing the BasicPlatform in a web worker', function(done) {
const canvas = document.createElement('canvas');
if (!canvas.transferControlToOffscreen) {
Expand Down
5 changes: 5 additions & 0 deletions types/index.esm.d.ts
Expand Up @@ -2016,6 +2016,11 @@ export class BasePlatform {
* @returns {boolean} true if the canvas is attached to the platform, false if not.
*/
isAttached(canvas: HTMLCanvasElement): boolean;
/**
* Updates config with platform specific requirements
* @param {ChartConfiguration} config
*/
updateConfig(config: ChartConfiguration): void;
}

export class BasicPlatform extends BasePlatform {}
Expand Down