Skip to content

Commit 177e0ab

Browse files
aiAdrianCopilot
andauthored
Fix: Multiply filter change event (signal) triggers when filter panel gets shown (#610)
* Fix: Filtering was updated without changed. Please retest and check whether this fix has any side-effects which are not detected during this change. If no side-effects - the overall behavior is improved (performance) * cleaned code and formated * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e38ca69 commit 177e0ab

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/app/services/analytics/origin-destination/components/origin-destination.component.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {OriginDestination, OriginDestinationService} from "./origin-destination.service";
2-
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from "@angular/core";
2+
import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from "@angular/core";
33
import * as d3 from "d3";
44

55
import {Subject, takeUntil} from "rxjs";
@@ -26,7 +26,7 @@ type ColorSetName = "red" | "blue" | "orange" | "gray";
2626
templateUrl: "./origin-destination.component.html",
2727
styleUrls: ["./origin-destination.component.scss"],
2828
})
29-
export class OriginDestinationComponent implements OnInit, OnDestroy {
29+
export class OriginDestinationComponent implements OnInit, AfterViewInit, OnDestroy {
3030
@ViewChild("div") divRef: ElementRef;
3131

3232
private readonly destroyed$ = new Subject<void>();
@@ -54,11 +54,17 @@ export class OriginDestinationComponent implements OnInit, OnDestroy {
5454

5555
private cellSize: number = 30;
5656

57+
private isReadyToRender = false;
58+
5759
private extractNumericODValues(odList: OriginDestination[], field: FieldName): number[] {
5860
return odList.filter((od) => od["found"]).map((od) => od[field]);
5961
}
6062

6163
private renderView() {
64+
if (!this.isReadyToRender) {
65+
return;
66+
}
67+
6268
const nodes = this.originDestinationService.getODOutputNodes();
6369
const nodeNames = nodes.map((node) => ({
6470
shortName: node.getBetriebspunktName(),
@@ -78,9 +84,6 @@ export class OriginDestinationComponent implements OnInit, OnDestroy {
7884

7985
// Compute the matrix (expensive) and render the default view.
8086
ngOnInit(): void {
81-
this.loadMatrixData();
82-
this.renderView();
83-
8487
this.uiInteractionService.zoomInObservable
8588
.pipe(takeUntil(this.destroyed$))
8689
.subscribe((zoomCenter: Vec2D) => this.controller.zoomIn(zoomCenter));
@@ -101,7 +104,17 @@ export class OriginDestinationComponent implements OnInit, OnDestroy {
101104
});
102105
}
103106

107+
ngAfterViewInit(): void {
108+
this.isReadyToRender = true;
109+
this.loadMatrixData();
110+
this.renderView();
111+
}
112+
104113
private loadMatrixData(): void {
114+
if (!this.isReadyToRender) {
115+
return;
116+
}
117+
105118
// Load raw OD data and ensure diagonal entries exist (only once on init)
106119
this.matrixData = this.originDestinationService.originDestinationData();
107120

src/app/view/editor-filter-view/editor-filter-view.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class EditorFilterViewComponent implements OnInit, OnDestroy {
4949
) {
5050
this.activeFilterName = undefined;
5151
this.activeEditFilterSettingId = undefined;
52-
this.filterService.filterChanged();
5352
this.filterService.filter.pipe(takeUntil(this.destroyed)).subscribe(() => {
5453
this.updateFilterData();
5554
});

src/app/view/editor-filter-view/filterable-label-filter/filterable-label-filter.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export class FilterableLabelFilterComponent implements OnInit, OnDestroy {
4141
this.translateComponentLabelRef(),
4242
);
4343
});
44-
45-
this.filterService.filterChanged();
4644
}
4745

4846
ngOnDestroy(): void {

0 commit comments

Comments
 (0)