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

Scale: Make sure grace is applied only once #8913

Merged
merged 2 commits into from Apr 17, 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: 3 additions & 1 deletion src/core/core.scale.js
Expand Up @@ -3,7 +3,7 @@ import {_alignPixel, _measureText, renderText, clipArea, unclipArea} from '../he
import {callback as call, each, finiteOrDefault, isArray, isFinite, isNullOrUndef, isObject} from '../helpers/helpers.core';
import {toDegrees, toRadians, _int16Range, _limitValue, HALF_PI} from '../helpers/helpers.math';
import {_alignStartEnd, _toLeftRightCenter} from '../helpers/helpers.extras';
import {toFont, toPadding} from '../helpers/helpers.options';
import {toFont, toPadding, _addGrace} from '../helpers/helpers.options';

import './core.scale.defaults';

Expand Down Expand Up @@ -204,6 +204,7 @@ export default class Scale extends Element {
this.labelRotation = undefined;
this.min = undefined;
this.max = undefined;
this._range = undefined;
/** @type {Tick[]} */
this.ticks = [];
/** @type {object[]|null} */
Expand Down Expand Up @@ -401,6 +402,7 @@ export default class Scale extends Element {
me.beforeDataLimits();
me.determineDataLimits();
me.afterDataLimits();
me._range = _addGrace(me, me.options.grace);
me._dataLimitsCached = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/scales/scale.linearbase.js
Expand Up @@ -2,7 +2,6 @@ import {isNullOrUndef} from '../helpers/helpers.core';
import {almostEquals, almostWhole, niceNum, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
import {formatNumber} from '../helpers/helpers.intl';
import {_addGrace} from '../helpers/helpers.options';

/**
* Generate a set of linear ticks for an axis
Expand Down Expand Up @@ -232,7 +231,8 @@ export default class LinearScaleBase extends Scale {
step: tickOpts.stepSize,
count: tickOpts.count,
};
const ticks = generateTicks(numericGeneratorOptions, _addGrace(me, opts.grace));
const dataRange = me._range || me;
const ticks = generateTicks(numericGeneratorOptions, dataRange);

// At this point, we need to update our max and min given the tick values,
// since we probably have expanded the range of the scale
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/scale.linear/grace/issue-8912.js
@@ -0,0 +1,26 @@
module.exports = {
description: 'https://github.com/chartjs/Chart.js/issues/8912',
config: {
type: 'bar',
data: {
labels: ['Red', 'Blue'],
datasets: [{
data: [10, -10]
}]
},
options: {
plugins: false,
scales: {
x: {
display: false,
},
y: {
grace: '100%'
}
}
}
},
options: {
spriteText: true
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.