mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-12 03:06:54 +01:00
Enable bounds option to all cartesian axes (#8060)
This commit is contained in:
@@ -17,6 +17,15 @@ defaults.set('scale', {
|
||||
reverse: false,
|
||||
beginAtZero: false,
|
||||
|
||||
/**
|
||||
* Scale boundary strategy (bypassed by min/max time options)
|
||||
* - `data`: make sure data are fully visible, ticks outside are removed
|
||||
* - `ticks`: make sure ticks are fully visible, data outside are truncated
|
||||
* @see https://github.com/chartjs/Chart.js/pull/4556
|
||||
* @since 3.0.0
|
||||
*/
|
||||
bounds: 'ticks',
|
||||
|
||||
// grid line settings
|
||||
gridLines: {
|
||||
display: true,
|
||||
|
||||
@@ -27,10 +27,20 @@ export default class CategoryScale extends Scale {
|
||||
|
||||
determineDataLimits() {
|
||||
const me = this;
|
||||
const max = me.getLabels().length - 1;
|
||||
const {minDefined, maxDefined} = me.getUserBounds();
|
||||
let {min, max} = me.getMinMax(true);
|
||||
|
||||
me.min = Math.max(me._userMin || 0, 0);
|
||||
me.max = Math.min(me._userMax || max, max);
|
||||
if (me.options.bounds === 'ticks') {
|
||||
if (!minDefined) {
|
||||
min = 0;
|
||||
}
|
||||
if (!maxDefined) {
|
||||
max = me.getLabels().length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
me.min = min;
|
||||
me.max = max;
|
||||
}
|
||||
|
||||
buildTicks() {
|
||||
|
||||
@@ -203,9 +203,11 @@ export default class LinearScaleBase extends Scale {
|
||||
};
|
||||
const ticks = generateTicks(numericGeneratorOptions, me);
|
||||
|
||||
// At this point, we need to update our max and min given the tick values since we have expanded the
|
||||
// range of the scale
|
||||
_setMinAndMaxByKey(ticks, me, 'value');
|
||||
// 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
|
||||
if (opts.bounds === 'ticks') {
|
||||
_setMinAndMaxByKey(ticks, me, 'value');
|
||||
}
|
||||
|
||||
if (opts.reverse) {
|
||||
ticks.reverse();
|
||||
|
||||
@@ -124,9 +124,11 @@ export default class LogarithmicScale extends Scale {
|
||||
};
|
||||
const ticks = generateTicks(generationOptions, me);
|
||||
|
||||
// At this point, we need to update our max and min given the tick values since we have expanded the
|
||||
// range of the scale
|
||||
_setMinAndMaxByKey(ticks, me, 'value');
|
||||
// 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
|
||||
if (opts.bounds === 'ticks') {
|
||||
_setMinAndMaxByKey(ticks, me, 'value');
|
||||
}
|
||||
|
||||
if (opts.reverse) {
|
||||
ticks.reverse();
|
||||
|
||||
Reference in New Issue
Block a user