diff --git a/src/app/cartography/components/map/map.component.ts b/src/app/cartography/components/map/map.component.ts index f867e046..ee67cea2 100644 --- a/src/app/cartography/components/map/map.component.ts +++ b/src/app/cartography/components/map/map.component.ts @@ -16,6 +16,7 @@ import { Subscription } from 'rxjs'; import { InterfaceLabelWidget } from '../../widgets/interface-label'; import { SelectionTool } from '../../tools/selection-tool'; import { MovingTool } from '../../tools/moving-tool'; +import { LinksWidget } from '../../widgets/links'; @Component({ @@ -37,7 +38,7 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { private d3: D3; private parentNativeElement: any; private svg: Selection; - + private isReady = false; private onNodeDraggingSubscription: Subscription; @@ -51,6 +52,7 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { protected element: ElementRef, protected d3Service: D3Service, protected nodesWidget: NodesWidget, + protected linksWidget: LinksWidget, protected interfaceLabelWidget: InterfaceLabelWidget, protected selectionToolWidget: SelectionTool, protected movingToolWidget: MovingTool, @@ -122,26 +124,21 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { this.createGraph(this.parentNativeElement); } this.context.size = this.getSize(); + + this.onNodeDraggingSubscription = this.nodesWidget.onNodeDragging.subscribe((eventNode: NodeEvent) => { + const links = this.links.filter((link) => link.target.node_id === eventNode.node.node_id || link.source.node_id === eventNode.node.node_id) + + links.forEach((link) => { + this.linksWidget.redrawLink(this.svg, link); + }); + }); } public createGraph(domElement: HTMLElement) { const rootElement = this.d3.select(domElement); this.svg = rootElement.select('svg'); - this.graphLayout.connect(this.svg, this.context); - - this.onNodeDraggingSubscription = this.graphLayout.getNodesWidget().onNodeDragging.subscribe((eventNode: NodeEvent) => { - const linksWidget = this.graphLayout.getLinksWidget(); - - const links = this.links.filter((link) => link.target.node_id === eventNode.node.node_id || link.source.node_id === eventNode.node.node_id) - - links.forEach((link) => { - linksWidget.redrawLink(this.svg, link); - }); - }); - this.graphLayout.draw(this.svg, this.context); - this.isReady = true; } diff --git a/src/app/cartography/widgets/graph-layout.ts b/src/app/cartography/widgets/graph-layout.ts index ec1fd640..fadbb18b 100644 --- a/src/app/cartography/widgets/graph-layout.ts +++ b/src/app/cartography/widgets/graph-layout.ts @@ -48,14 +48,6 @@ export class GraphLayout implements Widget { return this.nodesWidget; } - public getLinksWidget() { - return this.linksWidget; - } - - public getDrawingsWidget() { - return this.drawingsWidget; - } - public getDrawingLineTool() { return this.drawingLineTool; } @@ -98,7 +90,6 @@ export class GraphLayout implements Widget { layersManager.setDrawings(this.drawings); layersManager.setLinks(this.links); - this.layersWidget.graphLayout = this; this.layersWidget.draw(canvas, layersManager.getLayersList()); this.drawingLineTool.draw(view, context); diff --git a/src/app/cartography/widgets/layers.ts b/src/app/cartography/widgets/layers.ts index 59b7c27d..963d1d01 100644 --- a/src/app/cartography/widgets/layers.ts +++ b/src/app/cartography/widgets/layers.ts @@ -4,11 +4,18 @@ import { Widget } from "./widget"; import { SVGSelection } from "../models/types"; import { GraphLayout } from "./graph-layout"; import { Layer } from "../models/layer"; +import { LinksWidget } from "./links"; +import { NodesWidget } from "./nodes"; +import { DrawingsWidget } from "./drawings"; @Injectable() export class LayersWidget implements Widget { - public graphLayout: GraphLayout; + constructor( + private linksWidget: LinksWidget, + private nodesWidget: NodesWidget, + private drawingsWidget: DrawingsWidget + ) {} public draw(view: SVGSelection, layers: Layer[]) { @@ -56,18 +63,9 @@ export class LayersWidget implements Widget { .exit() .remove(); - // @FixMe - this.graphLayout - .getLinksWidget() - .draw(links_container); - - this.graphLayout - .getNodesWidget() - .draw(nodes_container); - - this.graphLayout - .getDrawingsWidget() - .draw(drawings_container); + this.linksWidget.draw(links_container); + this.nodesWidget.draw(nodes_container); + this.drawingsWidget.draw(drawings_container); } }