easier formatting

This commit is contained in:
Timo Hocker
2020-04-24 14:05:58 +02:00
parent 3c00d4f4af
commit c57af9bf57
3 changed files with 32 additions and 31 deletions

View File

@ -1,15 +1,20 @@
export class Element {
public name: string;
public parent: string;
protected parent_name: string;
public get full_name (): string {
if (this.parent)
return `${this.parent}_${this.name}`;
if (this.parent_name)
return `${this.parent_name}_${this.name}`;
return this.name;
}
public get parent (): string {
return this.parent_name;
}
public constructor (name: string, parent = '') {
this.name = name;
this.parent = parent;
this.parent_name = parent;
}
// eslint-disable-next-line @typescript-eslint/naming-convention

View File

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