From 6bbc7c4b62595825b41aff190c380a4d452b2393 Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Tue, 24 Dec 2024 15:06:24 +0000 Subject: [PATCH] Pull request #5412: Bugfix/DXCF-5765 chart viewport incorrect viewport position after reload page Merge in DXCHARTS/dxchart5 from bugfix/DXCF-5765-chart-viewport-incorrect-viewport-position-after-reload-page to master * commit '4f664c0a3126d3692ec4df8751e2747d6a566a96': [DXCF-5765] Chart Viewport - Incorrect viewport position after reload page // copy [DXCF-5765] Chart Viewport - Incorrect viewport position after reload page // init [DXCF-5765] Chart Viewport - Incorrect viewport position after reload page // init [DXCF-5765] Chart Viewport - Incorrect viewport position after reload page // init [DXCF-5765] Chart Viewport - Incorrect viewport position after reload page // init GitOrigin-RevId: e11e48a474948d92c379822b06114a4d877e28c8 --- src/chart/components/chart/chart.model.ts | 4 ++-- src/chart/model/scaling/viewport.model.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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 ); } }