From 34fccf5982f31758cd901718566c406298a6eb3a Mon Sep 17 00:00:00 2001 From: Michal Szczepanski Date: Thu, 25 Jul 2024 02:00:59 +0200 Subject: [PATCH] feat: ngx-graph automatic fit to screen and dynamic data --- frontend/src/app/app.component.html | 195 +++++++++++++--------------- frontend/src/app/app.component.ts | 75 ++++++++++- 2 files changed, 160 insertions(+), 110 deletions(-) diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 7c82a56..4b1097a 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -1,122 +1,101 @@

Slow shit

- + --> + +
+ - - - - - + layout="dagreCluster" + (select)="handleNodeSelect($event)" + > + + + + + - - - - - + + + + + - - - - - {{node.label}} - - - - + --> + + - - - - - - {{link.label}} - - - - - + + + + + + {{link.label}} + + + + + +
diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 3baec84..94f3043 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,7 +1,9 @@ -import {Component} from "@angular/core"; +import {AfterViewInit, Component} from "@angular/core"; import { RouterOutlet } from '@angular/router'; import {GraphModule} from "./view/graph/graph.module"; import {NgxGraphModule} from "@kr0san89/ngx-graph"; +import {randomString} from "./utils/utils"; +import {Subject} from "rxjs"; @Component({ @@ -11,9 +13,78 @@ import {NgxGraphModule} from "@kr0san89/ngx-graph"; templateUrl: './app.component.html', styleUrl: './app.component.scss' }) -export class AppComponent { +export class AppComponent implements AfterViewInit { + update$ = new Subject(); + zoom$ = new Subject(); + links: any = [] + + nodes: any = [] + + ngAfterViewInit() { + this.nodes = [ + { + id: 'first', + label: 'A' + }, { + id: 'second', + label: 'B' + }, { + id: 'c1', + label: 'C1' + }, { + id: 'c2', + label: 'C2' + }, { + id: 'd', + label: 'D' + } + ] + this.links = [ + { + id: 'a', + source: 'first', + target: 'second', + label: 'is parent of' + }, { + id: 'b', + source: 'first', + target: 'c1', + label: 'custom label' + }, { + id: 'd', + source: 'first', + target: 'c2', + label: 'custom label' + }, { + id: 'e', + source: 'c1', + target: 'd', + label: 'first link' + }, { + id: 'f', + source: 'c1', + target: 'd', + label: 'second link' + } + ] + setTimeout(() => { + this.zoom$.next({ force: true, autoCenter: true }) + }, 1) + } + + handleAddNode = () => { + const node = {id: randomString(5), label: randomString(5)} + this.nodes.push(node) + console.log('node', node) + this.update$.next(true) + this.zoom$.next(true) + } handleNodeSelect = (event: any) => { console.log('handleNodeSelect', event) } + + toJSON = (val: any) => { + return JSON.stringify(val) + } }