]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Disable animations for BasicPlatform (offcreen) (#9751)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 11 Oct 2021 18:37:25 +0000 (21:37 +0300)
committerGitHub <noreply@github.com>
Mon, 11 Oct 2021 18:37:25 +0000 (14:37 -0400)
* Disable animations for BasicPlatform (offcreen)
* Update types

src/core/core.controller.js
src/platform/platform.base.js
src/platform/platform.basic.js
test/specs/platform.basic.tests.js
types/index.esm.d.ts

index 33ba6734ce786695b518ed4cbdb54d9f64e3f9f7..19cfeca0cc277dabd82fc17fbe35ca52006f0159 100644 (file)
@@ -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;
index 44803cdbd23a598b4c0a88c7af07dea28fedf561..c29a5945a1c4c358d6c2fdc5d4c6b6f6d6c6dd10 100644 (file)
@@ -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
+  }
 }
 
 /**
index 7b38caf4a190a862258d463d66add449e7d588c3..4d0717bc1474dba27a2054641029b661dad1f7a8 100644 (file)
@@ -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;
+  }
 }
index 16b9699123e0f204676444bd76067e29db644ffa..a2f7a2188d22d5da0e6a34a107639aa34cabf023 100644 (file)
@@ -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) {
index 848d824c15c162e8cf3e03fbc69702f5d0978858..9ae7132b459c1fe1063d316f8e80387b03b9faec 100644 (file)
@@ -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 {}