]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix options update when changing to shared opts (#10451)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 29 Jun 2022 13:44:51 +0000 (16:44 +0300)
committerGitHub <noreply@github.com>
Wed, 29 Jun 2022 13:44:51 +0000 (16:44 +0300)
src/controllers/controller.bar.js
src/controllers/controller.bubble.js
src/controllers/controller.doughnut.js
src/controllers/controller.line.js
src/core/core.datasetController.js
test/fixtures/controller.line/radius/scriptable-to-value.js [new file with mode: 0644]
test/fixtures/controller.line/radius/scriptable-to-value.png [new file with mode: 0644]

index cc047e4a62d6291d5aea8290af01ec7ca386e615..557bffbd8c91a5ee46f3e227b2cad48aeeb8cc57 100644 (file)
@@ -350,11 +350,7 @@ export default class BarController extends DatasetController {
     const base = vScale.getBasePixel();
     const horizontal = vScale.isHorizontal();
     const ruler = this._getRuler();
-    const firstOpts = this.resolveDataElementOptions(start, mode);
-    const sharedOptions = this.getSharedOptions(firstOpts);
-    const includeOptions = this.includeOptions(mode, sharedOptions);
-
-    this.updateSharedOptions(sharedOptions, mode, firstOpts);
+    const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
 
     for (let i = start; i < start + count; i++) {
       const parsed = this.getParsed(i);
index 1b0241fcae627710838379cfd14b10f5d0729981..67ceb2a06208c938c0c89d32192716ac270a4cfa 100644 (file)
@@ -85,9 +85,7 @@ export default class BubbleController extends DatasetController {
   updateElements(points, start, count, mode) {
     const reset = mode === 'reset';
     const {iScale, vScale} = this._cachedMeta;
-    const firstOpts = this.resolveDataElementOptions(start, mode);
-    const sharedOptions = this.getSharedOptions(firstOpts);
-    const includeOptions = this.includeOptions(mode, sharedOptions);
+    const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
     const iAxis = iScale.axis;
     const vAxis = vScale.axis;
 
@@ -101,7 +99,7 @@ export default class BubbleController extends DatasetController {
       properties.skip = isNaN(iPixel) || isNaN(vPixel);
 
       if (includeOptions) {
-        properties.options = this.resolveDataElementOptions(i, point.active ? 'active' : mode);
+        properties.options = sharedOptions || this.resolveDataElementOptions(i, point.active ? 'active' : mode);
 
         if (reset) {
           properties.options.radius = 0;
@@ -110,8 +108,6 @@ export default class BubbleController extends DatasetController {
 
       this.updateElement(point, i, properties, mode);
     }
-
-    this.updateSharedOptions(sharedOptions, mode, firstOpts);
   }
 
   /**
index 2be27615bcdd0602454af7f10bf7819fe124b523..848432bba6076149ca6f40e7076d6b353e8e0a37 100644 (file)
@@ -170,9 +170,7 @@ export default class DoughnutController extends DatasetController {
     const animateScale = reset && animationOpts.animateScale;
     const innerRadius = animateScale ? 0 : this.innerRadius;
     const outerRadius = animateScale ? 0 : this.outerRadius;
-    const firstOpts = this.resolveDataElementOptions(start, mode);
-    const sharedOptions = this.getSharedOptions(firstOpts);
-    const includeOptions = this.includeOptions(mode, sharedOptions);
+    const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
     let startAngle = this._getRotation();
     let i;
 
@@ -199,7 +197,6 @@ export default class DoughnutController extends DatasetController {
 
       this.updateElement(arc, i, properties, mode);
     }
-    this.updateSharedOptions(sharedOptions, mode, firstOpts);
   }
 
   calculateTotal() {
index 7fe2efecbcb8285ea9101c812a675dd6bdab4735..9e799cd5567579456455c70d2424f28c1ae11026 100644 (file)
@@ -49,9 +49,7 @@ export default class LineController extends DatasetController {
   updateElements(points, start, count, mode) {
     const reset = mode === 'reset';
     const {iScale, vScale, _stacked, _dataset} = this._cachedMeta;
-    const firstOpts = this.resolveDataElementOptions(start, mode);
-    const sharedOptions = this.getSharedOptions(firstOpts);
-    const includeOptions = this.includeOptions(mode, sharedOptions);
+    const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
     const iAxis = iScale.axis;
     const vAxis = vScale.axis;
     const {spanGaps, segment} = this.options;
@@ -84,8 +82,6 @@ export default class LineController extends DatasetController {
 
       prevParsed = parsed;
     }
-
-    this.updateSharedOptions(sharedOptions, mode, firstOpts);
   }
 
   /**
index 85cc50e91627110085e5a8523e0dc9729a92de43..a2f031f9e0950efd539105f61b8957fb8d3c4d39 100644 (file)
@@ -840,6 +840,18 @@ export default class DatasetController {
     return !sharedOptions || isDirectUpdateMode(mode) || this.chart._animationsDisabled;
   }
 
+  /**
+   * @todo v4, rename to getSharedOptions and remove excess functions
+   */
+  _getSharedOptions(start, mode) {
+    const firstOpts = this.resolveDataElementOptions(start, mode);
+    const previouslySharedOptions = this._sharedOptions;
+    const sharedOptions = this.getSharedOptions(firstOpts);
+    const includeOptions = this.includeOptions(mode, sharedOptions) || (sharedOptions !== previouslySharedOptions);
+    this.updateSharedOptions(sharedOptions, mode, firstOpts);
+    return {sharedOptions, includeOptions};
+  }
+
   /**
         * Utility for updating an element with new properties, using animations when appropriate.
         * @protected
diff --git a/test/fixtures/controller.line/radius/scriptable-to-value.js b/test/fixtures/controller.line/radius/scriptable-to-value.js
new file mode 100644 (file)
index 0000000..9492ccf
--- /dev/null
@@ -0,0 +1,32 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['A', 'B', 'C'],
+      datasets: [{
+        data: [12, 19, 3]
+      }]
+    },
+    options: {
+      animation: {
+        duration: 0
+      },
+      backgroundColor: 'red',
+      radius: () => 20,
+      scales: {
+        x: {display: false},
+        y: {display: false}
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    },
+    run: (chart) => {
+      chart.options.radius = 5;
+      chart.update();
+    }
+  }
+};
diff --git a/test/fixtures/controller.line/radius/scriptable-to-value.png b/test/fixtures/controller.line/radius/scriptable-to-value.png
new file mode 100644 (file)
index 0000000..d0e3b21
Binary files /dev/null and b/test/fixtures/controller.line/radius/scriptable-to-value.png differ