return graph and node names

This commit is contained in:
Timo Hocker 2020-04-27 16:03:48 +02:00
parent 430314c9a4
commit 2e34757a1a

View File

@ -46,24 +46,26 @@ export class Graph extends Element {
.replace (/^\s+$/gmu, '');
}
public add_node (constructor: ((g: Node) => void) | string): void {
public add_node (constructor: ((g: Node) => void) | string): string {
if (typeof constructor === 'string') {
this.nodes.push (new Node (constructor, this.full_name, constructor));
return;
return this.nodes[this.nodes.length - 1].full_name;
}
const node = new Node ('unnamed', this.full_name);
constructor (node);
this.nodes.push (node);
return node.full_name;
}
public add_graph (constructor: ((g: Graph) => void) | string): void {
public add_graph (constructor: ((g: Graph) => void) | string): string {
if (typeof constructor === 'string') {
this.children.push (new Graph (constructor, this.full_name));
return;
return this.children[this.children.length - 1].full_name;
}
const graph = new Graph ('unnamed', this.full_name);
constructor (graph);
this.children.push (graph);
return graph.full_name;
}
public add_edge (origin: string, target: string): void {