fix spacing
This commit is contained in:
		@@ -2,7 +2,9 @@ export class Element {
 | 
				
			|||||||
  public name: string;
 | 
					  public name: string;
 | 
				
			||||||
  public parent: string;
 | 
					  public parent: string;
 | 
				
			||||||
  public get full_name (): string {
 | 
					  public get full_name (): string {
 | 
				
			||||||
 | 
					    if (this.parent)
 | 
				
			||||||
      return `${this.parent}_${this.name}`;
 | 
					      return `${this.parent}_${this.name}`;
 | 
				
			||||||
 | 
					    return this.name;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public constructor (name: string, parent = '') {
 | 
					  public constructor (name: string, parent = '') {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								lib/Graph.ts
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								lib/Graph.ts
									
									
									
									
									
								
							@@ -10,16 +10,25 @@ export class Graph extends Element {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // eslint-disable-next-line @typescript-eslint/naming-convention
 | 
					  // eslint-disable-next-line @typescript-eslint/naming-convention
 | 
				
			||||||
  public toString (level = 0): string {
 | 
					  public toString (level = 0): string {
 | 
				
			||||||
    return `subgraph cluster_${this.full_name} {
 | 
					    const header = this.parent
 | 
				
			||||||
  ${this.children.map ((c) => c.toString (level + 1))
 | 
					      ? `subgraph cluster_${this.full_name}`
 | 
				
			||||||
    .join ('\n  ')}
 | 
					      : `digraph ${this.full_name}`;
 | 
				
			||||||
 | 
					    let children = `\n  ${this.children.map ((c) => c.toString (level + 1))
 | 
				
			||||||
 | 
					      .join ('\n  ')}\n`;
 | 
				
			||||||
 | 
					    let nodes = `\n  ${this.nodes.map ((c) => c.toString ())
 | 
				
			||||||
 | 
					      .join ('\n  ')}\n`;
 | 
				
			||||||
 | 
					    let edges = `\n  ${this.edges.map ((c) => c.toString ())
 | 
				
			||||||
 | 
					      .join ('\n  ')}\n`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ${this.nodes.map ((c) => c.toString ())
 | 
					    if (children === '\n  \n')
 | 
				
			||||||
    .join ('\n  ')}
 | 
					      children = '';
 | 
				
			||||||
 | 
					    if (nodes === '\n  \n')
 | 
				
			||||||
 | 
					      nodes = '';
 | 
				
			||||||
 | 
					    if (edges === '\n  \n')
 | 
				
			||||||
 | 
					      edges = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ${this.edges.map ((c) => c.toString ())
 | 
					    return `${header} {${children}${nodes}${edges}}`
 | 
				
			||||||
    .join ('\n  ')}
 | 
					      .replace (/\n/gu, `\n${'  '.repeat (level)}`)
 | 
				
			||||||
}`.replace (/\n/gu, `\n${'  '.repeat (level)}`)
 | 
					 | 
				
			||||||
      .replace (/^\s+$/gmu, '');
 | 
					      .replace (/^\s+$/gmu, '');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +1,21 @@
 | 
				
			|||||||
import test from 'ava';
 | 
					import test from 'ava';
 | 
				
			||||||
import { Graph, Node } from '../lib';
 | 
					import { Graph, Node } from '../lib';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const result = `subgraph cluster_bar_foo {
 | 
					const result = `digraph foo {
 | 
				
			||||||
  subgraph cluster_bar_foo_baz {
 | 
					  subgraph cluster_foo_baz {
 | 
				
			||||||
 | 
					    foo_baz_asd
 | 
				
			||||||
    bar_foo_baz_asd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bar_foo_baz
 | 
					  foo_baz
 | 
				
			||||||
  bar_foo_foo
 | 
					  foo_foo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bar_foo_foo -> bar_foo_baz
 | 
					  foo_foo -> foo_baz
 | 
				
			||||||
}`;
 | 
					}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test ('serialize', (t) => {
 | 
					test ('serialize', (t) => {
 | 
				
			||||||
  const g = new Graph ('foo', 'bar');
 | 
					  const g = new Graph ('foo');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  t.is (g.full_name, 'bar_foo');
 | 
					  t.is (g.full_name, 'foo');
 | 
				
			||||||
  g.add_graph (() => {
 | 
					  g.add_graph (() => {
 | 
				
			||||||
    const graph = new Graph ('baz');
 | 
					    const graph = new Graph ('baz');
 | 
				
			||||||
    graph.add_node (() => new Node ('asd'));
 | 
					    graph.add_node (() => new Node ('asd'));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user