Skip to content

Commit

Permalink
Disable animations for BasicPlatform (offcreen)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 11, 2021
1 parent 7993fc9 commit 5e9f017
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
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

0 comments on commit 5e9f017

Please sign in to comment.