* - thickness of scales or legends in another orientation
*/
update(maxWidth, maxHeight, margins) {
- const tickOpts = this.options.ticks;
+ const {beginAtZero, grace, ticks: tickOpts} = this.options;
const sampleSize = tickOpts.sampleSize;
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
this.beforeDataLimits();
this.determineDataLimits();
this.afterDataLimits();
- this._range = _addGrace(this, this.options.grace);
+ this._range = _addGrace(this, grace, beginAtZero);
this._dataLimitsCached = true;
}
/**
* @param {{min: number, max: number}} minmax
* @param {number|string} grace
+ * @param {boolean} beginAtZero
* @private
*/
-export function _addGrace(minmax, grace) {
+export function _addGrace(minmax, grace, beginAtZero) {
const {min, max} = minmax;
+ const change = toDimension(grace, (max - min) / 2);
+ const keepZero = (value, add) => beginAtZero && value === 0 ? 0 : value + add;
return {
- min: min - Math.abs(toDimension(grace, min)),
- max: max + toDimension(grace, max)
+ min: keepZero(min, -Math.abs(change)),
+ max: keepZero(max, change)
};
}