separate createGraph

This commit is contained in:
ziajka 2018-10-18 12:54:24 +02:00
parent 01586f500f
commit 778efff79a
3 changed files with 28 additions and 25 deletions

View File

@ -10,7 +10,7 @@ import { GraphLayout } from "../../widgets/graph-layout";
import { Context } from "../../models/context";
import { Size } from "../../models/size";
import { Drawing } from "../../models/drawing";
import { Symbol } from "../../models/symbol";
import { Symbol } from '../../../models/symbol';
@Component({
@ -72,34 +72,35 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() {
const d3 = this.d3;
let rootElement: Selection<HTMLElement, any, null, undefined>;
if (this.parentNativeElement !== null) {
rootElement = d3.select(this.parentNativeElement);
this.svg = rootElement.select<SVGSVGElement>('svg');
this.graphContext = new Context(true);
this.graphContext.size = this.getSize();
this.graphLayout = new GraphLayout();
this.graphLayout.connect(this.svg, this.graphContext);
this.graphLayout.getNodesWidget().addOnNodeDraggingCallback((event: any, n: Node) => {
const linksWidget = this.graphLayout.getLinksWidget();
linksWidget.select(this.svg).each(function(this: SVGGElement, link: Link) {
if (link.target.node_id === n.node_id || link.source.node_id === n.node_id) {
const selection = select<SVGElement, Link>(this);
linksWidget.revise(selection);
}
});
});
this.graphLayout.draw(this.svg, this.graphContext);
this.createGraph(this.parentNativeElement);
}
}
public createGraph(domElement: HTMLElement) {
const rootElement = this.d3.select(domElement);
this.svg = rootElement.select<SVGSVGElement>('svg');
this.graphContext = new Context(true);
this.graphContext.size = this.getSize();
this.graphLayout = new GraphLayout();
this.graphLayout.connect(this.svg, this.graphContext);
this.graphLayout.getNodesWidget().addOnNodeDraggingCallback((event: any, n: Node) => {
const linksWidget = this.graphLayout.getLinksWidget();
linksWidget.select(this.svg).each(function(this: SVGGElement, link: Link) {
if (link.target.node_id === n.node_id || link.source.node_id === n.node_id) {
const selection = select<SVGElement, Link>(this);
linksWidget.revise(selection);
}
});
});
this.graphLayout.draw(this.svg, this.graphContext);
}
public getSize(): Size {
let width = document.documentElement.clientWidth;
let height = document.documentElement.clientHeight;

View File

@ -105,6 +105,7 @@ export class GraphLayout implements Widget {
return `translate(${xTrans}, ${yTrans}) scale(${kTrans})`;
});
// @fix me
const layersManager = new LayersManager();
layersManager.setNodes(this.nodes);
layersManager.setDrawings(this.drawings);

View File

@ -53,6 +53,7 @@ export class LayersWidget implements Widget {
.exit()
.remove();
// @FixMe
this.graphLayout
.getLinksWidget()
.draw(links_container);