From 644091dbe197b59de0e346dcbacd1ce4d61e28a9 Mon Sep 17 00:00:00 2001
From: Kirill Bobkov <kirill_2105@mail.ru>
Date: Tue, 12 Dec 2023 18:53:06 +0400
Subject: [PATCH] Revert "fix: fixed memory leaks in scale and viewport model"

---
 .../components/y_axis/y-axis-scale.handler.ts | 20 ++++++++-----------
 src/chart/model/scale.model.ts                | 11 +---------
 src/chart/model/scaling/viewport.model.ts     | 15 ++++----------
 3 files changed, 13 insertions(+), 33 deletions(-)

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 b0c2b80f..7188cd47 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,
-		private config: YAxisConfig,
+		config: YAxisConfig,
 		panning: ChartPanComponent,
 		private scale: ScaleModel,
-		private canvasInputListener: CanvasInputListenerComponent,
+		canvasInputListener: CanvasInputListenerComponent,
 		private bounds: CanvasBoundsContainer,
-		private hitTest: HitBoundsTest,
+		hitTest: HitBoundsTest,
 		private autoScaleCallback: (auto: boolean) => void,
 	) {
 		super();
@@ -58,17 +58,13 @@ export class YAxisScaleHandler extends ChartBaseElement {
 				},
 			);
 			this.addChildEntity(dragNDropYComponent);
-		}
-	}
 
-	protected doActivate(): void {
-		if (this.config.customScaleDblClick) {
-			this.addRxSubscription(
-				this.canvasInputListener.observeDbClick(this.hitTest).subscribe(() => {
-					this.autoScaleCallback(true);
+			if (config.customScaleDblClick) {
+				canvasInputListener.observeDbClick(hitTest).subscribe(() => {
+					autoScaleCallback(true);
 					this.bus.fireDraw();
-				}),
-			);
+				});
+			}
 		}
 	}
 
diff --git a/src/chart/model/scale.model.ts b/src/chart/model/scale.model.ts
index a9de1083..0a40d4fc 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<boolean> = new Subject<boolean>();
 	// y-axis component needs this subject in order to halt prev animation if axis type is percent
-	public beforeStartAnimationSubject: Subject<void> = new Subject<void>();
+	public beforeStartAnimationSubject = new Subject<void>();
 
 	// TODO rework, make a new history based on units
 	history: ScaleHistoryItem[] = [];
@@ -84,9 +84,6 @@ 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();
@@ -94,12 +91,6 @@ 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 8be8871d..1bd88dd4 100644
--- a/src/chart/model/scaling/viewport.model.ts
+++ b/src/chart/model/scaling/viewport.model.ts
@@ -152,16 +152,6 @@ 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.
@@ -227,7 +217,10 @@ 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,
+			);
 		}
 	}