parse(start, count) {
const me = this;
const {_cachedMeta: meta, _data: data} = me;
- const {iScale, vScale, _stacked} = meta;
+ const {iScale, _stacked} = meta;
const iAxis = iScale.axis;
let sorted = true;
let i, parsed, cur, prev;
if (_stacked) {
updateStacks(me, parsed);
}
-
- iScale.invalidateCaches();
- vScale.invalidateCaches();
}
/**
const verticalBoxes = boxes.vertical;
const horizontalBoxes = boxes.horizontal;
+ // Before any changes are made, notify boxes that an update is about to being
+ // This is used to clear any cached data (e.g. scale limits)
+ each(chart.boxes, box => {
+ if (typeof box.beforeLayout === 'function') {
+ box.beforeLayout();
+ }
+ });
+
// Essentially we now have any number of boxes on each of the 4 sides.
// Our canvas looks like the following.
// The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
this._ticksLength = 0;
this._borderValue = 0;
this._cache = {};
+ this._dataLimitsCached = false;
this.$context = undefined;
}
};
}
- invalidateCaches() {
- this._cache = {};
- }
-
/**
* Get the padding needed for the scale
* @return {{top: number, left: number, bottom: number, right: number}} the necessary padding
return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels || [];
}
+ // When a new layout is created, reset the data limits cache
+ beforeLayout() {
+ this._cache = {};
+ this._dataLimitsCached = false;
+ }
+
// These methods are ordered by lifecycle. Utilities then follow.
// Any function defined here is inherited by all scale types.
// Any function can be extended by the scale type
me.afterSetDimensions();
// Data min/max
- me.beforeDataLimits();
- me.determineDataLimits();
- me.afterDataLimits();
+ if (!me._dataLimitsCached) {
+ me.beforeDataLimits();
+ me.determineDataLimits();
+ me.afterDataLimits();
+ me._dataLimitsCached = true;
+ }
me.beforeBuildTicks();
return parse(this, raw);
}
- invalidateCaches() {
+ beforeLayout() {
+ super.beforeLayout();
this._cache = {
data: [],
labels: [],
/**
* Returns an object with padding on the edges
*/
- getPadding?(): ChartArea;
+ getPadding?(): ChartArea;
+
+ /**
+ * Called before the layout process starts
+ */
+ beforeLayout?(): void;
/**
* Width of item. Must be valid after update()
parse(raw: any, index: number): any;
getUserBounds(): { min: number; max: number; minDefined: boolean; maxDefined: boolean };
getMinMax(canStack: boolean): { min: number; max: number };
- invalidateCaches(): void;
+ beforeLayout(): void;
getPadding(): ChartArea;
getTicks(): Tick[];
getLabels(): string[];