mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-08 02:54:16 +00:00
Clean code
This commit is contained in:
parent
467d6b6851
commit
cf62f3634b
@ -1,8 +1,7 @@
|
||||
import {
|
||||
Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange, EventEmitter, Output
|
||||
} from '@angular/core';
|
||||
import { D3, D3Service } from 'd3-ng2-service';
|
||||
import { Selection } from 'd3-selection';
|
||||
import { Selection, select } from 'd3-selection';
|
||||
|
||||
import { Node } from "../../models/node";
|
||||
import { Link } from "../../../models/link";
|
||||
@ -39,12 +38,9 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Output() onNodeDragged: EventEmitter<NodeDragged>;
|
||||
@Output() onLinkCreated = new EventEmitter<LinkCreated>();
|
||||
|
||||
private d3: D3;
|
||||
private parentNativeElement: any;
|
||||
private svg: Selection<SVGSVGElement, any, null, undefined>;
|
||||
|
||||
private isReady = false;
|
||||
|
||||
private onNodeDraggingSubscription: Subscription;
|
||||
private onChangesDetected: Subscription;
|
||||
|
||||
@ -56,7 +52,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
private context: Context,
|
||||
private mapChangeDetectorRef: MapChangeDetectorRef,
|
||||
protected element: ElementRef,
|
||||
protected d3Service: D3Service,
|
||||
protected nodesWidget: NodesWidget,
|
||||
protected linksWidget: LinksWidget,
|
||||
protected interfaceLabelWidget: InterfaceLabelWidget,
|
||||
@ -64,7 +59,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
protected movingToolWidget: MovingTool,
|
||||
public graphLayout: GraphLayout
|
||||
) {
|
||||
this.d3 = d3Service.getD3();
|
||||
this.parentNativeElement = element.nativeElement;
|
||||
this.onNodeDragged = nodesWidget.onNodeDragged;
|
||||
}
|
||||
@ -135,18 +129,18 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
});
|
||||
|
||||
this.onChangesDetected = this.mapChangeDetectorRef.changesDetected.subscribe(() => {
|
||||
if (this.isReady) {
|
||||
if (this.mapChangeDetectorRef.hasBeenDrawn) {
|
||||
this.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public createGraph(domElement: HTMLElement) {
|
||||
const rootElement = this.d3.select(domElement);
|
||||
const rootElement = select(domElement);
|
||||
this.svg = rootElement.select<SVGSVGElement>('svg');
|
||||
this.graphLayout.connect(this.svg, this.context);
|
||||
this.graphLayout.draw(this.svg, this.context);
|
||||
this.isReady = true;
|
||||
this.mapChangeDetectorRef.hasBeenDrawn = true;
|
||||
}
|
||||
|
||||
public getSize(): Size {
|
||||
|
@ -5,6 +5,8 @@ import { Injectable, EventEmitter } from "@angular/core";
|
||||
export class MapChangeDetectorRef {
|
||||
public changesDetected = new EventEmitter<boolean>();
|
||||
|
||||
public hasBeenDrawn = false;
|
||||
|
||||
public detectChanges() {
|
||||
this.changesDetected.emit(true);
|
||||
}
|
||||
|
@ -22,9 +22,7 @@ export class GraphLayout implements Widget {
|
||||
private drawings: Drawing[] = [];
|
||||
|
||||
constructor(
|
||||
private linksWidget: LinksWidget,
|
||||
private nodesWidget: NodesWidget,
|
||||
private drawingsWidget: DrawingsWidget,
|
||||
private drawingLineTool: DrawingLineWidget,
|
||||
private selectionTool: SelectionTool,
|
||||
private movingTool: MovingTool,
|
||||
|
Loading…
x
Reference in New Issue
Block a user