diff --git a/src/chart/inputhandlers/hover-producer.component.ts b/src/chart/inputhandlers/hover-producer.component.ts index badfc75e..7ce5cbe3 100644 --- a/src/chart/inputhandlers/hover-producer.component.ts +++ b/src/chart/inputhandlers/hover-producer.component.ts @@ -1,9 +1,10 @@ /* - * Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited + * Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { BehaviorSubject, merge } from 'rxjs'; +import { filter, switchMap } from 'rxjs/operators'; import { CHART_UUID, CanvasBoundsContainer, CanvasElement } from '../canvas/canvas-bounds-container'; import { FullChartConfig } from '../chart.config'; import { ChartModel } from '../components/chart/chart.model'; @@ -94,11 +95,16 @@ export class HoverProducerComponent extends ChartBaseElement { protected doActivate() { super.doActivate(); this.addRxSubscription( - this.chartModel.candlesSetSubject.subscribe(() => { - // required for initial legend initialization, do not show cross tool - const lastCandle = this.chartModel.getLastVisualCandle(); - lastCandle && this.createAndFireHoverFromCandle(lastCandle); - }), + // required for initial legend initialization, do not show cross tool + this.chartModel.candlesSetSubject + .pipe( + // check the scale is valid before doing candle-based hover event + switchMap(() => this.scale.initialViewportValidSubject.pipe(filter(Boolean))), + ) + .subscribe(() => { + const lastCandle = this.chartModel.getLastVisualCandle(); + lastCandle && this.createAndFireHoverFromCandle(lastCandle); + }), ); this.addRxSubscription( this.chartModel.candlesUpdatedSubject.subscribe(() => { diff --git a/src/chart/model/scaling/viewport.model.ts b/src/chart/model/scaling/viewport.model.ts index 54f0884e..f396a4f9 100644 --- a/src/chart/model/scaling/viewport.model.ts +++ b/src/chart/model/scaling/viewport.model.ts @@ -1,9 +1,9 @@ /* - * Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited + * Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { Subject } from 'rxjs'; +import { BehaviorSubject, Subject } from 'rxjs'; import { distinctUntilChanged, map, share } from 'rxjs/operators'; import { ChartBaseElement } from '../chart-base-element'; import { ViewportMovementAnimation } from '../../animation/types/viewport-movement-animation'; @@ -151,10 +151,18 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable distinctUntilChanged((p, c) => p.start === c.start && p.end === c.end), share(), ); + public initialViewportValidSubject = new BehaviorSubject(false); //endregion protected doActivate(): void { super.doActivate(); + + this.addRxSubscription( + this.changed.subscribe(() => { + !this.initialViewportValidSubject.getValue() && + this.initialViewportValidSubject.next(this.isViewportValid()); + }), + ); } protected doDeactivate(): void {