mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Allow scale to auto-adjust it's min when stacked (#9045)
This commit is contained in:
parent
7c3a412887
commit
33c16382b3
@ -168,14 +168,14 @@ export default class LinearScaleBase extends Scale {
|
|||||||
|
|
||||||
handleTickRangeOptions() {
|
handleTickRangeOptions() {
|
||||||
const me = this;
|
const me = this;
|
||||||
const {beginAtZero, stacked} = me.options;
|
const {beginAtZero} = me.options;
|
||||||
const {minDefined, maxDefined} = me.getUserBounds();
|
const {minDefined, maxDefined} = me.getUserBounds();
|
||||||
let {min, max} = me;
|
let {min, max} = me;
|
||||||
|
|
||||||
const setMin = v => (min = minDefined ? min : v);
|
const setMin = v => (min = minDefined ? min : v);
|
||||||
const setMax = v => (max = maxDefined ? max : v);
|
const setMax = v => (max = maxDefined ? max : v);
|
||||||
|
|
||||||
if (beginAtZero || stacked) {
|
if (beginAtZero) {
|
||||||
const minSign = sign(min);
|
const minSign = sign(min);
|
||||||
const maxSign = sign(max);
|
const maxSign = sign(max);
|
||||||
|
|
||||||
|
@ -194,6 +194,12 @@ describe('Linear Scale', function() {
|
|||||||
chart.scales.y.options.stacked = true;
|
chart.scales.y.options.stacked = true;
|
||||||
chart.update();
|
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.min).toBe(0);
|
||||||
expect(chart.scales.y.max).toBe(90);
|
expect(chart.scales.y.max).toBe(90);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user