diff --git a/src/chart/components/y_axis/y-axis-scale.handler.ts b/src/chart/components/y_axis/y-axis-scale.handler.ts index 7188cd47..b0c2b80f 100644 --- a/src/chart/components/y_axis/y-axis-scale.handler.ts +++ b/src/chart/components/y_axis/y-axis-scale.handler.ts @@ -32,12 +32,12 @@ export class YAxisScaleHandler extends ChartBaseElement { constructor( private bus: EventBus, - config: YAxisConfig, + private config: YAxisConfig, panning: ChartPanComponent, private scale: ScaleModel, - canvasInputListener: CanvasInputListenerComponent, + private canvasInputListener: CanvasInputListenerComponent, private bounds: CanvasBoundsContainer, - hitTest: HitBoundsTest, + private hitTest: HitBoundsTest, private autoScaleCallback: (auto: boolean) => void, ) { super(); @@ -58,13 +58,17 @@ export class YAxisScaleHandler extends ChartBaseElement { }, ); this.addChildEntity(dragNDropYComponent); + } + } - if (config.customScaleDblClick) { - canvasInputListener.observeDbClick(hitTest).subscribe(() => { - autoScaleCallback(true); + protected doActivate(): void { + if (this.config.customScaleDblClick) { + this.addRxSubscription( + this.canvasInputListener.observeDbClick(this.hitTest).subscribe(() => { + this.autoScaleCallback(true); this.bus.fireDraw(); - }); - } + }), + ); } } diff --git a/src/chart/model/scale.model.ts b/src/chart/model/scale.model.ts index 0a40d4fc..a9de1083 100644 --- a/src/chart/model/scale.model.ts +++ b/src/chart/model/scale.model.ts @@ -55,7 +55,7 @@ type Constraints = (initialState: ViewportModelState, state: ViewportModelState) export class ScaleModel extends ViewportModel { public scaleInversedSubject: Subject = new Subject(); // y-axis component needs this subject in order to halt prev animation if axis type is percent - public beforeStartAnimationSubject = new Subject(); + public beforeStartAnimationSubject: Subject = new Subject(); // TODO rework, make a new history based on units history: ScaleHistoryItem[] = []; @@ -84,6 +84,9 @@ export class ScaleModel extends ViewportModel { } protected doActivate(): void { + super.doActivate(); + this.scaleInversedSubject = new Subject(); + this.beforeStartAnimationSubject = new Subject(); this.addRxSubscription( this.scaleInversedSubject.subscribe(() => { this.fireChanged(); @@ -91,6 +94,12 @@ export class ScaleModel extends ViewportModel { ); } + protected doDeactivate(): void { + super.doDeactivate(); + this.scaleInversedSubject.complete(); + this.beforeStartAnimationSubject.complete(); + } + /** * The method adds a new "constraint" to the existing list of x-axis constraints for charting. * The "constraint" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis. diff --git a/src/chart/model/scaling/viewport.model.ts b/src/chart/model/scaling/viewport.model.ts index 1bd88dd4..8be8871d 100644 --- a/src/chart/model/scaling/viewport.model.ts +++ b/src/chart/model/scaling/viewport.model.ts @@ -152,6 +152,16 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable share(), ); //endregion + + protected doActivate(): void { + super.doActivate(); + this.changed = new Subject(); + } + + protected doDeactivate(): void { + super.doDeactivate(); + this.changed.complete(); + } //region conversion methods /** * Converts a unit value to pixels based on the current zoom level and xStart value. @@ -217,10 +227,7 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable return pixelsToUnits(normalizedPx + unitToPixels(this.yStart, this.zoomY), this.zoomY); } else { // inverse by default because canvas calculation [0,0] point starts from top-left corner - return pixelsToUnits( - bounds.height - normalizedPx + unitToPixels(this.yStart, this.zoomY), - this.zoomY, - ); + return pixelsToUnits(bounds.height - normalizedPx + unitToPixels(this.yStart, this.zoomY), this.zoomY); } }