Allow scale to auto-adjust it's min when stacked (#9045)

This commit is contained in:
Jukka Kurkela 2021-05-07 22:48:55 +03:00 committed by GitHub
parent 7c3a412887
commit 33c16382b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -168,14 +168,14 @@ export default class LinearScaleBase extends Scale {
handleTickRangeOptions() {
const me = this;
const {beginAtZero, stacked} = me.options;
const {beginAtZero} = me.options;
const {minDefined, maxDefined} = me.getUserBounds();
let {min, max} = me;
const setMin = v => (min = minDefined ? min : v);
const setMax = v => (max = maxDefined ? max : v);
if (beginAtZero || stacked) {
if (beginAtZero) {
const minSign = sign(min);
const maxSign = sign(max);

View File

@ -194,6 +194,12 @@ describe('Linear Scale', function() {
chart.scales.y.options.stacked = true;
chart.update();
expect(chart.scales.y.min).toBe(30);
expect(chart.scales.y.max).toBe(90);
chart.scales.y.options.beginAtZero = true;
chart.update();
expect(chart.scales.y.min).toBe(0);
expect(chart.scales.y.max).toBe(90);
});