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 {
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 {

View File

@ -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);
}

View File

@ -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,