|
1 | | -import { Component, OnInit, Input, ElementRef, SimpleChanges, OnChanges } from '@angular/core'; |
| 1 | +import { Component, OnInit, OnDestroy, Input, ElementRef, SimpleChanges, OnChanges } from '@angular/core'; |
2 | 2 | import * as d3 from 'd3'; |
| 3 | +import { Subject } from 'rxjs'; |
| 4 | +import { takeUntil } from 'rxjs/operators'; |
3 | 5 | import { LoaderService } from '../../service/loader/data-loader.service'; |
4 | 6 | import { Activity } from 'src/app/model/activity-store'; |
5 | 7 | import { DataStore } from 'src/app/model/data-store'; |
@@ -38,7 +40,8 @@ interface ThemeColors { |
38 | 40 | templateUrl: './dependency-graph.component.html', |
39 | 41 | styleUrls: ['./dependency-graph.component.css'], |
40 | 42 | }) |
41 | | -export class DependencyGraphComponent implements OnInit, OnChanges { |
| 43 | +export class DependencyGraphComponent implements OnInit, OnChanges, OnDestroy { |
| 44 | + private destroy$ = new Subject<void>(); |
42 | 45 | css: CSSStyleDeclaration = getComputedStyle(document.body); |
43 | 46 | themeColors: Partial<ThemeColors> = {}; |
44 | 47 | theme: string; |
@@ -66,11 +69,19 @@ export class DependencyGraphComponent implements OnInit, OnChanges { |
66 | 69 | }); |
67 | 70 |
|
68 | 71 | // Reactively handle theme changes (if user toggles later) |
69 | | - this.themeService.theme$.subscribe((theme: string) => { |
| 72 | + this.themeService.theme$.pipe(takeUntil(this.destroy$)).subscribe((theme: string) => { |
70 | 73 | this.setThemeColors(theme); |
71 | 74 | }); |
72 | 75 | } |
73 | 76 |
|
| 77 | + ngOnDestroy(): void { |
| 78 | + this.destroy$.next(); |
| 79 | + this.destroy$.complete(); |
| 80 | + if (this.simulation) { |
| 81 | + this.simulation.stop(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
74 | 85 | ngOnChanges(changes: SimpleChanges): void { |
75 | 86 | if (this.dataStore?.activityStore) { |
76 | 87 | if (changes?.hasOwnProperty('activityName')) { |
|
0 commit comments