From 778efff79a751a9df8b95a015d10102c57b4b665 Mon Sep 17 00:00:00 2001 From: ziajka Date: Thu, 18 Oct 2018 12:54:24 +0200 Subject: [PATCH] separate createGraph --- .../components/map/map.component.ts | 51 ++++++++++--------- src/app/cartography/widgets/graph-layout.ts | 1 + src/app/cartography/widgets/layers.ts | 1 + 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/app/cartography/components/map/map.component.ts b/src/app/cartography/components/map/map.component.ts index 3cfcec9c..a6cba58c 100644 --- a/src/app/cartography/components/map/map.component.ts +++ b/src/app/cartography/components/map/map.component.ts @@ -10,7 +10,7 @@ import { GraphLayout } from "../../widgets/graph-layout"; import { Context } from "../../models/context"; import { Size } from "../../models/size"; import { Drawing } from "../../models/drawing"; -import { Symbol } from "../../models/symbol"; +import { Symbol } from '../../../models/symbol'; @Component({ @@ -72,34 +72,35 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { ngOnInit() { const d3 = this.d3; - let rootElement: Selection; - if (this.parentNativeElement !== null) { - rootElement = d3.select(this.parentNativeElement); - - this.svg = rootElement.select('svg'); - - this.graphContext = new Context(true); - - this.graphContext.size = this.getSize(); - - this.graphLayout = new GraphLayout(); - this.graphLayout.connect(this.svg, this.graphContext); - - this.graphLayout.getNodesWidget().addOnNodeDraggingCallback((event: any, n: Node) => { - const linksWidget = this.graphLayout.getLinksWidget(); - linksWidget.select(this.svg).each(function(this: SVGGElement, link: Link) { - if (link.target.node_id === n.node_id || link.source.node_id === n.node_id) { - const selection = select(this); - linksWidget.revise(selection); - } - }); - }); - - this.graphLayout.draw(this.svg, this.graphContext); + this.createGraph(this.parentNativeElement); } } + public createGraph(domElement: HTMLElement) { + const rootElement = this.d3.select(domElement); + this.svg = rootElement.select('svg'); + + this.graphContext = new Context(true); + + this.graphContext.size = this.getSize(); + + this.graphLayout = new GraphLayout(); + this.graphLayout.connect(this.svg, this.graphContext); + + this.graphLayout.getNodesWidget().addOnNodeDraggingCallback((event: any, n: Node) => { + const linksWidget = this.graphLayout.getLinksWidget(); + linksWidget.select(this.svg).each(function(this: SVGGElement, link: Link) { + if (link.target.node_id === n.node_id || link.source.node_id === n.node_id) { + const selection = select(this); + linksWidget.revise(selection); + } + }); + }); + + this.graphLayout.draw(this.svg, this.graphContext); + } + public getSize(): Size { let width = document.documentElement.clientWidth; let height = document.documentElement.clientHeight; diff --git a/src/app/cartography/widgets/graph-layout.ts b/src/app/cartography/widgets/graph-layout.ts index d1e2deac..7e0b736c 100644 --- a/src/app/cartography/widgets/graph-layout.ts +++ b/src/app/cartography/widgets/graph-layout.ts @@ -105,6 +105,7 @@ export class GraphLayout implements Widget { return `translate(${xTrans}, ${yTrans}) scale(${kTrans})`; }); + // @fix me const layersManager = new LayersManager(); layersManager.setNodes(this.nodes); layersManager.setDrawings(this.drawings); diff --git a/src/app/cartography/widgets/layers.ts b/src/app/cartography/widgets/layers.ts index ffaa7158..9ea2f27e 100644 --- a/src/app/cartography/widgets/layers.ts +++ b/src/app/cartography/widgets/layers.ts @@ -53,6 +53,7 @@ export class LayersWidget implements Widget { .exit() .remove(); + // @FixMe this.graphLayout .getLinksWidget() .draw(links_container);