]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update scale polarArea correctly on data hide (#10340)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Sun, 22 May 2022 13:50:32 +0000 (15:50 +0200)
committerGitHub <noreply@github.com>
Sun, 22 May 2022 13:50:32 +0000 (09:50 -0400)
* give correct range back for polarArea
* added test
* tab to spaces

src/controllers/controller.polarArea.js
test/specs/controller.polarArea.tests.js

index 92642a32fef5d59fa73cbdeae128041655b58d8f..b717eca7c256c8e7bbadd3aa4c204f147a82aa82 100644 (file)
@@ -33,6 +33,30 @@ export default class PolarAreaController extends DatasetController {
     this.updateElements(arcs, 0, arcs.length, mode);
   }
 
+  /**
+   * @protected
+   */
+  getMinMax() {
+    const meta = this._cachedMeta;
+    const range = {min: Number.POSITIVE_INFINITY, max: Number.NEGATIVE_INFINITY};
+
+    meta.data.forEach((element, index) => {
+      const parsed = this.getParsed(index).r;
+
+      if (!isNaN(parsed) && this.chart.getDataVisibility(index)) {
+        if (parsed < range.min) {
+          range.min = parsed;
+        }
+
+        if (parsed > range.max) {
+          range.max = parsed;
+        }
+      }
+    });
+
+    return range;
+  }
+
   /**
         * @private
         */
index 340c58413cda741b219ed4412ff3cc1fe4baad1d..a5266e215214ffa4a17dea5c378ec0fcdc437b53 100644 (file)
@@ -1,6 +1,24 @@
 describe('Chart.controllers.polarArea', function() {
   describe('auto', jasmine.fixture.specs('controller.polarArea'));
 
+  it('should update the scale correctly when data visibility is changed', function() {
+    var expectedScaleMax = 1;
+    var chart = window.acquireChart({
+      type: 'polarArea',
+      data: {
+        datasets: [
+          {data: [100]}
+        ],
+        labels: ['x']
+      }
+    });
+
+    chart.toggleDataVisibility(0);
+    chart.update();
+
+    expect(chart.scales.r.max).toBe(expectedScaleMax);
+  });
+
   it('should be registered as dataset controller', function() {
     expect(typeof Chart.controllers.polarArea).toBe('function');
   });