Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed memory leaks in scale and viewport model #96

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/chart/components/y_axis/y-axis-scale.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});
}
}),
);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/chart/model/scale.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = new Subject<void>();
public beforeStartAnimationSubject: Subject<void> = new Subject<void>();

// TODO rework, make a new history based on units
history: ScaleHistoryItem[] = [];
Expand Down Expand Up @@ -84,13 +84,22 @@ 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();
}),
);
}

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.
Expand Down
15 changes: 11 additions & 4 deletions src/chart/model/scaling/viewport.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand Down