From de5810d368697848fcddf00d1430c634bca00162 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Fri, 17 Jul 2020 13:29:03 +0200 Subject: [PATCH] stream: node count --- CHANGELOG.md | 6 ++++++ README.md | 6 +++++- lib/classes/GraphStream.ts | 6 ++++++ package.json | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd7788..e29a864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.3.0 + +Stream: + +- property to read current node count + ## 1.2.0 Stream: diff --git a/README.md b/README.md index faa23eb..7a640cf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @sapphirecode/graphviz-builder -version: 1.2.x +version: 1.3.x constructing graphviz files using an easy typescript interface @@ -44,6 +44,10 @@ g.add_graph(sg=>{ 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 diff --git a/lib/classes/GraphStream.ts b/lib/classes/GraphStream.ts index fdf8faa..a169e0d 100644 --- a/lib/classes/GraphStream.ts +++ b/lib/classes/GraphStream.ts @@ -21,6 +21,7 @@ interface Stringable { } export class GraphStream extends Transform { + private _node_count = 0; private _path: string[] = []; private _state: (GraphStreamCommand | '')[] = [ '', @@ -33,6 +34,10 @@ export class GraphStream extends Transform { return this._path.join ('_'); } + public get node_count (): number { + return this._node_count; + } + private get level (): string { return ' '.repeat (this._path.length); } @@ -114,6 +119,7 @@ export class GraphStream extends Transform { case 'cn': // create node this.finish_node (); this.push (`${this.level}${this.path}_${instr.args[0]}`); + this._node_count++; break; case 'at': // add attributes if ([ diff --git a/package.json b/package.json index 5258aeb..a96516b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@sapphirecode/graphviz-builder", "main": "dist/lib/index.js", - "version": "1.2.9", + "version": "1.3.0", "author": "Timo Hocker ", "description": "constructing graphviz files using an easy typescript interface", "repository": { @@ -29,4 +29,4 @@ "dependencies": { "@sapphirecode/encoding-helper": "^1.0.38" } -} \ No newline at end of file +}