Skip to content

Commit

Permalink
Allow scale to auto-adjust it's min when stacked (#9045)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed May 7, 2021
1 parent 7c3a412 commit 33c1638
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/scales/scale.linearbase.js
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions test/specs/scale.linear.tests.js
Expand Up @@ -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);
});
Expand Down

0 comments on commit 33c1638

Please sign in to comment.