Fix graph disappearing

This commit is contained in:
Michał Romaszkin 2020-06-26 02:55:32 +02:00
parent 44d4c932c5
commit e4c4c6d03d

View File

@ -4,6 +4,7 @@ import {
OnDestroy, OnDestroy,
ViewChild, ViewChild,
ElementRef, ElementRef,
AfterViewInit,
} from '@angular/core'; } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { GetVisualizationDataService } from '../../_services/get-visualization-data.service'; import { GetVisualizationDataService } from '../../_services/get-visualization-data.service';
@ -18,7 +19,7 @@ import maked3hierarchy from '../../_functions/maked3hierarchy';
templateUrl: './visualize-forum.component.html', templateUrl: './visualize-forum.component.html',
styleUrls: ['./visualize-forum.component.scss'], styleUrls: ['./visualize-forum.component.scss'],
}) })
export class VisualizeForumComponent implements OnInit, OnDestroy { export class VisualizeForumComponent implements AfterViewInit, OnDestroy {
private subscription: Subscription; private subscription: Subscription;
private data: Post[]; private data: Post[];
private hierarchizedData: Post[]; private hierarchizedData: Post[];
@ -30,7 +31,7 @@ export class VisualizeForumComponent implements OnInit, OnDestroy {
private getDataService: GetVisualizationDataService private getDataService: GetVisualizationDataService
) {} ) {}
ngOnInit(): void { ngAfterViewInit(): void {
this.subscription = this.route.params this.subscription = this.route.params
.pipe(concatMap((params) => this.getDataService.getDiscussion(params.id))) .pipe(concatMap((params) => this.getDataService.getDiscussion(params.id)))
.subscribe((result) => { .subscribe((result) => {
@ -59,7 +60,7 @@ export class VisualizeForumComponent implements OnInit, OnDestroy {
const element = this.treeContainer.nativeElement; const element = this.treeContainer.nativeElement;
/* Clear previous graph */ /* Clear previous graph */
d3.select(element).select('svg').remove(); d3.select(element).select('svg').empty();
/* Create SVG */ /* Create SVG */
const svg = d3 const svg = d3