diff --git a/frontend/src/app/_functions/maked3hierarchy.ts b/frontend/src/app/_functions/maked3hierarchy.ts index 2bb5d41..0a30cb4 100644 --- a/frontend/src/app/_functions/maked3hierarchy.ts +++ b/frontend/src/app/_functions/maked3hierarchy.ts @@ -4,12 +4,10 @@ import { Post } from '../_interfaces/post'; * Returns hierearchy-like array specified for D3 graph */ export default function makeHierarchy(data: Post[]) { - console.log('In function!'); const tree: Post[] = []; const childOf: any = {}; data.forEach((element) => { const { id, parent } = element; - console.log(parent); childOf[id] = childOf[id] || []; element.children = childOf[id]; if (parent !== 0) { diff --git a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.html b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.html index e69de29..07e181b 100644 --- a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.html +++ b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.html @@ -0,0 +1 @@ +
diff --git a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.scss b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.scss index e69de29..9d69745 100644 --- a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.scss +++ b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.scss @@ -0,0 +1,5 @@ +::ng-deep .link { + fill: none; + stroke: #000; + stroke-width: 2px; +} diff --git a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.ts b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.ts index cca30d9..822bb08 100644 --- a/frontend/src/app/main-view/visualize-forum/visualize-forum.component.ts +++ b/frontend/src/app/main-view/visualize-forum/visualize-forum.component.ts @@ -1,9 +1,16 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { + Component, + OnInit, + OnDestroy, + ViewChild, + ElementRef, +} from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { GetVisualizationDataService } from '../../_services/get-visualization-data.service'; import { Subscription } from 'rxjs'; -import { concatMap } from 'rxjs/operators'; +import { concatMap, finalize } from 'rxjs/operators'; import { Post } from 'src/app/_interfaces/post'; +import * as d3 from 'd3'; import maked3hierarchy from '../../_functions/maked3hierarchy'; @Component({ @@ -14,6 +21,9 @@ import maked3hierarchy from '../../_functions/maked3hierarchy'; export class VisualizeForumComponent implements OnInit, OnDestroy { private subscription: Subscription; private data: Post[]; + private hierarchizedData: Post[]; + @ViewChild('tree', { read: ElementRef }) + private treeContainer: ElementRef; constructor( private route: ActivatedRoute, @@ -24,12 +34,101 @@ export class VisualizeForumComponent implements OnInit, OnDestroy { this.subscription = this.route.params .pipe(concatMap((params) => this.getDataService.getDiscussion(params.id))) .subscribe((result) => { - this.data = maked3hierarchy(result.posts); - console.log(this.data); + this.initializeData(result.posts); + this.generateGraph(); }); } ngOnDestroy(): void { this.subscription.unsubscribe(); } + + private initializeData(data: Post[]): void { + this.data = data; + this.hierarchizedData = maked3hierarchy(data); + } + + private generateGraph(): void { + /* ToDo: Add option to change sizes */ + const margin = { top: 50, right: 90, bottom: 30, left: 90 }; + const width = 660 - margin.left - margin.right; + const height = 500 - margin.top - margin.bottom; + + const hierarchizedNodes = d3.hierarchy