Clean code

This commit is contained in:
ziajka
2018-11-06 14:45:32 +01:00
parent 467d6b6851
commit cf62f3634b
3 changed files with 6 additions and 12 deletions

View File

@ -1,8 +1,7 @@
import { import {
Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange, EventEmitter, Output Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange, EventEmitter, Output
} from '@angular/core'; } from '@angular/core';
import { D3, D3Service } from 'd3-ng2-service'; import { Selection, select } from 'd3-selection';
import { Selection } from 'd3-selection';
import { Node } from "../../models/node"; import { Node } from "../../models/node";
import { Link } from "../../../models/link"; import { Link } from "../../../models/link";
@ -39,12 +38,9 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
@Output() onNodeDragged: EventEmitter<NodeDragged>; @Output() onNodeDragged: EventEmitter<NodeDragged>;
@Output() onLinkCreated = new EventEmitter<LinkCreated>(); @Output() onLinkCreated = new EventEmitter<LinkCreated>();
private d3: D3;
private parentNativeElement: any; private parentNativeElement: any;
private svg: Selection<SVGSVGElement, any, null, undefined>; private svg: Selection<SVGSVGElement, any, null, undefined>;
private isReady = false;
private onNodeDraggingSubscription: Subscription; private onNodeDraggingSubscription: Subscription;
private onChangesDetected: Subscription; private onChangesDetected: Subscription;
@ -56,7 +52,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
private context: Context, private context: Context,
private mapChangeDetectorRef: MapChangeDetectorRef, private mapChangeDetectorRef: MapChangeDetectorRef,
protected element: ElementRef, protected element: ElementRef,
protected d3Service: D3Service,
protected nodesWidget: NodesWidget, protected nodesWidget: NodesWidget,
protected linksWidget: LinksWidget, protected linksWidget: LinksWidget,
protected interfaceLabelWidget: InterfaceLabelWidget, protected interfaceLabelWidget: InterfaceLabelWidget,
@ -64,7 +59,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
protected movingToolWidget: MovingTool, protected movingToolWidget: MovingTool,
public graphLayout: GraphLayout public graphLayout: GraphLayout
) { ) {
this.d3 = d3Service.getD3();
this.parentNativeElement = element.nativeElement; this.parentNativeElement = element.nativeElement;
this.onNodeDragged = nodesWidget.onNodeDragged; this.onNodeDragged = nodesWidget.onNodeDragged;
} }
@ -135,18 +129,18 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
}); });
this.onChangesDetected = this.mapChangeDetectorRef.changesDetected.subscribe(() => { this.onChangesDetected = this.mapChangeDetectorRef.changesDetected.subscribe(() => {
if (this.isReady) { if (this.mapChangeDetectorRef.hasBeenDrawn) {
this.reload(); this.reload();
} }
}); });
} }
public createGraph(domElement: HTMLElement) { public createGraph(domElement: HTMLElement) {
const rootElement = this.d3.select(domElement); const rootElement = select(domElement);
this.svg = rootElement.select<SVGSVGElement>('svg'); this.svg = rootElement.select<SVGSVGElement>('svg');
this.graphLayout.connect(this.svg, this.context); this.graphLayout.connect(this.svg, this.context);
this.graphLayout.draw(this.svg, this.context); this.graphLayout.draw(this.svg, this.context);
this.isReady = true; this.mapChangeDetectorRef.hasBeenDrawn = true;
} }
public getSize(): Size { public getSize(): Size {

View File

@ -5,6 +5,8 @@ import { Injectable, EventEmitter } from "@angular/core";
export class MapChangeDetectorRef { export class MapChangeDetectorRef {
public changesDetected = new EventEmitter<boolean>(); public changesDetected = new EventEmitter<boolean>();
public hasBeenDrawn = false;
public detectChanges() { public detectChanges() {
this.changesDetected.emit(true); this.changesDetected.emit(true);
} }

View File

@ -22,9 +22,7 @@ export class GraphLayout implements Widget {
private drawings: Drawing[] = []; private drawings: Drawing[] = [];
constructor( constructor(
private linksWidget: LinksWidget,
private nodesWidget: NodesWidget, private nodesWidget: NodesWidget,
private drawingsWidget: DrawingsWidget,
private drawingLineTool: DrawingLineWidget, private drawingLineTool: DrawingLineWidget,
private selectionTool: SelectionTool, private selectionTool: SelectionTool,
private movingTool: MovingTool, private movingTool: MovingTool,