Skip to content

Commit

Permalink
Update scale polarArea correctly on data hide (#10340)
Browse files Browse the repository at this point in the history
* give correct range back for polarArea
* added test
* tab to spaces
  • Loading branch information
LeeLenaleee committed May 22, 2022
1 parent 4183b7f commit 1422c93
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/controllers/controller.polarArea.js
Expand Up @@ -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
*/
Expand Down
18 changes: 18 additions & 0 deletions test/specs/controller.polarArea.tests.js
@@ -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');
});
Expand Down

0 comments on commit 1422c93

Please sign in to comment.