mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Disable animations for BasicPlatform (offcreen) (#9751)
* Disable animations for BasicPlatform (offcreen) * Update types
This commit is contained in:
parent
7993fc95dc
commit
bc5e5cbf11
@ -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;
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
5
types/index.esm.d.ts
vendored
5
types/index.esm.d.ts
vendored
@ -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 {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user