From 4462fce32ae668e6df70f8373823420896fa1b06 Mon Sep 17 00:00:00 2001 From: Michal Szczepanski Date: Fri, 26 Jul 2024 02:21:42 +0200 Subject: [PATCH] feat: test basic graph functionality --- frontend/src/app/app.component.html | 28 +++++++------- frontend/src/app/app.component.ts | 60 +++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 4b1097a..d27e9ed 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -7,16 +7,22 @@ [autoZoom]="true" [autoCenter]="true" [animate]="false" [update$]="update$" [center$]="center$" [zoomToFit$]="zoomToFit$" (window:resize)="onResize($event)"> --> - + + + +
@@ -66,16 +71,11 @@ {{node.label}} - + +
+ +
+
diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 94f3043..ae12df7 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component} from "@angular/core"; +import {AfterViewInit, Component, OnInit} from "@angular/core"; import { RouterOutlet } from '@angular/router'; import {GraphModule} from "./view/graph/graph.module"; import {NgxGraphModule} from "@kr0san89/ngx-graph"; @@ -13,18 +13,20 @@ import {Subject} from "rxjs"; templateUrl: './app.component.html', styleUrl: './app.component.scss' }) -export class AppComponent implements AfterViewInit { +export class AppComponent implements AfterViewInit, OnInit { update$ = new Subject(); - zoom$ = new Subject(); + zoomToFit$ = new Subject() + center$ = new Subject() + zoomLevel = 1 links: any = [] nodes: any = [] - ngAfterViewInit() { + ngOnInit() { this.nodes = [ { id: 'first', - label: 'A' + label: 'A', }, { id: 'second', label: 'B' @@ -36,14 +38,17 @@ export class AppComponent implements AfterViewInit { label: 'C2' }, { id: 'd', - label: 'D' + label: 'D', } ] + this.nodes.forEach((n: any) => { + n.dimension = { width: 100, height: 100 } + }) this.links = [ { id: 'a', - source: 'first', - target: 'second', + source: 'second', + target: 'first', label: 'is parent of' }, { id: 'b', @@ -65,11 +70,39 @@ export class AppComponent implements AfterViewInit { source: 'c1', target: 'd', label: 'second link' + }, { + id: 'g', + source: 'second', + target: 'second', + label: 'loop' } ] - setTimeout(() => { - this.zoom$.next({ force: true, autoCenter: true }) - }, 1) + setTimeout(() => this.zoomToFit$.next(true), 1) + } + + ngAfterViewInit() { + console.log('ngAfterViewInit') + } + + handleEdit = (event: any) => { + console.log('handleEdit', event) + } + + handleZoomIn = () => { + this.zoomLevel += 0.1 + } + + handleZoomOut = () => { + this.zoomLevel -= 0.1 + } + + handleFit = () => { + this.zoomToFit$.next(true) + this.center$.next(true) + } + + handleZoomChange = (value: number) => { + this.zoomLevel = value } handleAddNode = () => { @@ -77,11 +110,6 @@ export class AppComponent implements AfterViewInit { 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) => {