Code clean

This commit is contained in:
ziajka 2018-11-05 14:28:42 +01:00
parent 1d1cf149bb
commit e279a1403f
3 changed files with 22 additions and 36 deletions

View File

@ -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<SVGSVGElement, any, null, undefined>;
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<SVGSVGElement>('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;
}

View File

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

View File

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