stream: node count
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Timo Hocker 2020-07-17 13:29:03 +02:00
parent 040e421d9b
commit de5810d368
4 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 1.3.0
Stream:
- property to read current node count
## 1.2.0 ## 1.2.0
Stream: Stream:

View File

@ -1,6 +1,6 @@
# @sapphirecode/graphviz-builder # @sapphirecode/graphviz-builder
version: 1.2.x version: 1.3.x
constructing graphviz files using an easy typescript interface constructing graphviz files using an easy typescript interface
@ -44,6 +44,10 @@ g.add_graph(sg=>{
sg.add_node('foo'); sg.add_node('foo');
}) })
// get info about current stream state
g.node_count // count of nodes written
g.path // get current path (parent graph names separated by underscores)
``` ```
## License ## License

View File

@ -21,6 +21,7 @@ interface Stringable {
} }
export class GraphStream extends Transform { export class GraphStream extends Transform {
private _node_count = 0;
private _path: string[] = []; private _path: string[] = [];
private _state: (GraphStreamCommand | '')[] = [ private _state: (GraphStreamCommand | '')[] = [
'', '',
@ -33,6 +34,10 @@ export class GraphStream extends Transform {
return this._path.join ('_'); return this._path.join ('_');
} }
public get node_count (): number {
return this._node_count;
}
private get level (): string { private get level (): string {
return ' '.repeat (this._path.length); return ' '.repeat (this._path.length);
} }
@ -114,6 +119,7 @@ export class GraphStream extends Transform {
case 'cn': // create node case 'cn': // create node
this.finish_node (); this.finish_node ();
this.push (`${this.level}${this.path}_${instr.args[0]}`); this.push (`${this.level}${this.path}_${instr.args[0]}`);
this._node_count++;
break; break;
case 'at': // add attributes case 'at': // add attributes
if ([ if ([

View File

@ -1,7 +1,7 @@
{ {
"name": "@sapphirecode/graphviz-builder", "name": "@sapphirecode/graphviz-builder",
"main": "dist/lib/index.js", "main": "dist/lib/index.js",
"version": "1.2.9", "version": "1.3.0",
"author": "Timo Hocker <timo@scode.ovh>", "author": "Timo Hocker <timo@scode.ovh>",
"description": "constructing graphviz files using an easy typescript interface", "description": "constructing graphviz files using an easy typescript interface",
"repository": { "repository": {