Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/scales/scale.linearbase.js
Expand Up @@ -155,14 +155,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