diff --git a/src/chart/components/chart/chart.model.ts b/src/chart/components/chart/chart.model.ts index 38c75a2..56e1896 100755 --- a/src/chart/components/chart/chart.model.ts +++ b/src/chart/components/chart/chart.model.ts @@ -165,8 +165,8 @@ export class ChartModel extends ChartBaseElement { const nextChartWidth = this.canvasBoundsContainer.getEffectiveChartWidth(); const nextYAxisWidth = this.canvasBoundsContainer.getEffectiveYAxisWidth(); - if (this.prevChartWidth === 0) { - this.scale.isViewportValid() ? this.scale.recalculateZoom() : this.doBasicScale(); + if (this.prevChartWidth === 0 && this.scale) { + this.scale.isViewportValid(false) && this.scale.recalculateZoom(); this.prevChartWidth = nextChartWidth; this.prevYWidth = nextYAxisWidth; return; diff --git a/src/chart/model/scaling/viewport.model.ts b/src/chart/model/scaling/viewport.model.ts index f396a4f..7ad59a3 100644 --- a/src/chart/model/scaling/viewport.model.ts +++ b/src/chart/model/scaling/viewport.model.ts @@ -424,14 +424,15 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable * * @returns {boolean} - Returns true if the viewport is valid, false otherwise. */ - isViewportValid() { + isViewportValid(validateZoom: boolean = true) { + // zoom is checked separately because sometimes we need to recalculate zoom based on X and Y and zoom could be incorrect + const isZoomValid = validateZoom === false || (this.zoomX > 0 && this.zoomY > 0); return ( this.xStart !== this.xEnd && this.yStart !== this.yEnd && isFinite(this.yStart) && isFinite(this.yEnd) && - this.zoomX > 0 && - this.zoomY > 0 + isZoomValid ); } }