From 5b9b23935013ee68fc3c3dd551ee05f11cbda35f Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 07:59:37 +0200 Subject: [PATCH 1/8] update-scanner: automatic update @scode/encoding-helper: 1.0.25 ==> 1.0.26 minor @scode/eslint-config-ts: 1.0.23 ==> 1.0.26 minor --- yarn.lock | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/yarn.lock b/yarn.lock index b641695..c81220b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -228,31 +228,31 @@ fastq "^1.6.0" "@scode/encoding-helper@^1.0.21": - version "1.0.25" - resolved "https://npm.scode.ovh/@scode%2fencoding-helper/-/encoding-helper-1.0.25.tgz#a6e1fe47525d99fe24b0f9df554d688c8d9e5ab0" - integrity sha512-cMLfuCKhawpqasdkG8DuYMKmh1p2WzB7MuCiiFTglSU6zseISBCmEPmX1UduELY5+qt42KxmXiwgkC4/xK3MHQ== + version "1.0.26" + resolved "https://npm.scode.ovh/@scode%2fencoding-helper/-/encoding-helper-1.0.26.tgz#d0e4627e16885ecb10bdc3b1b87b5bb9aae39455" + integrity sha512-f7hJzrHjI5D+yC8KnwGV1q/vARE0ZOUHe0f3fybCmzU38wobs0Jm+XgYi98ViXqFmvt18cz1NI1c4q9sdrcsQQ== "@scode/eslint-config-es6@^1.0.1": - version "1.0.22" - resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.22.tgz#be1a200c821137e74b829ec0029acc81734f1fca" - integrity sha512-/BnuycrNMFm4KKk2rz7JF0DBAN/JvWKpE0uK2fLz8m4o88TX5AKrlUg/w4c6ctPTzhD9t9tS9tuZFn/Vs0J3mg== + version "1.0.23" + resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.23.tgz#9e1cf74350217c202aaa8dfc46838416715fbf60" + integrity sha512-Ux1BOuKa9W7MoKID8VyWzJZo3je5k8h2lnc66KmBedDSruTwMhUqx2JzALoO2MeUFkvjtoVvdKXbSPvFPc54YQ== dependencies: "@scode/eslint-config" "^2.0.1" eslint-plugin-import "^2.20.1" "@scode/eslint-config-ts@^1.0.22": - version "1.0.23" - resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.23.tgz#fc29e278fffd3737657a1acdf69ade81cd0736c5" - integrity sha512-V+wzFQvl5sypixhTeNxO0lTaCDp6TSNMvbNfpFsNUl4kEZVNtlPY9+9Bf7Xnn7GY0qoA5d/fdqn4Qkxo96UhTA== + version "1.0.26" + resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.26.tgz#fd980c8e1dcd8bc52e182643487af9e40393ee82" + integrity sha512-PLfaNdPXyz7V4PRDsUpcqY+l9yP3d1aRf93U55aAmA3NXmpucA8twoFgB1Li9pE8NTHbEC612gUD/pdQ+1/cQg== dependencies: "@scode/eslint-config-es6" "^1.0.1" "@typescript-eslint/eslint-plugin" "^2.26.0" "@typescript-eslint/parser" "^2.26.0" "@scode/eslint-config@^2.0.1": - version "2.0.11" - resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.11.tgz#3cc3cd71f3bc3ac39868bf608e0517bee09da58f" - integrity sha512-K8DpFdmepU1FNp0QJn5gbXS45g7k04rFUJp2OKQDqSa+3iywBvi44pMzJNOdZjkj+t3dGcOdeWcYOngz2MjdlA== + version "2.0.12" + resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.12.tgz#eccd5205541fd63cbb84f72427d58873850224b0" + integrity sha512-llgvCpThp6ZDWzPPw1zmXMNwWp3oIndwX/FLigeyPQx/T1ucrbadf3iyTo0ZReJiUobGTiVBta6N13qGyzQsjA== dependencies: eslint-plugin-jsdoc "^24.0.0" eslint-plugin-node "^11.0.0" @@ -315,39 +315,39 @@ integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== "@typescript-eslint/eslint-plugin@^2.26.0": - version "2.29.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.29.0.tgz#c9efab7624e3dd6d144a0e4577a541d1bd42c2ac" - integrity sha512-X/YAY7azKirENm4QRpT7OVmzok02cSkqeIcLmdz6gXUQG4Hk0Fi9oBAynSAyNXeGdMRuZvjBa0c1Lu0dn/u6VA== + version "2.30.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.30.0.tgz#312a37e80542a764d96e8ad88a105316cdcd7b05" + integrity sha512-PGejii0qIZ9Q40RB2jIHyUpRWs1GJuHP1pkoCiaeicfwO9z7Fx03NQzupuyzAmv+q9/gFNHu7lo1ByMXe8PNyg== dependencies: - "@typescript-eslint/experimental-utils" "2.29.0" + "@typescript-eslint/experimental-utils" "2.30.0" functional-red-black-tree "^1.0.1" regexpp "^3.0.0" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@2.29.0": - version "2.29.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.29.0.tgz#3cb8060de9265ba131625a96bbfec31ba6d4a0fe" - integrity sha512-H/6VJr6eWYstyqjWXBP2Nn1hQJyvJoFdDtsHxGiD+lEP7piGnGpb/ZQd+z1ZSB1F7dN+WsxUDh8+S4LwI+f3jw== +"@typescript-eslint/experimental-utils@2.30.0": + version "2.30.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.30.0.tgz#9845e868c01f3aed66472c561d4b6bac44809dd0" + integrity sha512-L3/tS9t+hAHksy8xuorhOzhdefN0ERPDWmR9CclsIGOUqGKy6tqc/P+SoXeJRye5gazkuPO0cK9MQRnolykzkA== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/typescript-estree" "2.29.0" + "@typescript-eslint/typescript-estree" "2.30.0" eslint-scope "^5.0.0" eslint-utils "^2.0.0" "@typescript-eslint/parser@^2.26.0": - version "2.29.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.29.0.tgz#6e3c4e21ed6393dc05b9d8b47f0b7e731ef21c9c" - integrity sha512-H78M+jcu5Tf6m/5N8iiFblUUv+HJDguMSdFfzwa6vSg9lKR8Mk9BsgeSjO8l2EshKnJKcbv0e8IDDOvSNjl0EA== + version "2.30.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.30.0.tgz#7681c305a6f4341ae2579f5e3a75846c29eee9ce" + integrity sha512-9kDOxzp0K85UnpmPJqUzdWaCNorYYgk1yZmf4IKzpeTlSAclnFsrLjfwD9mQExctLoLoGAUXq1co+fbr+3HeFw== dependencies: "@types/eslint-visitor-keys" "^1.0.0" - "@typescript-eslint/experimental-utils" "2.29.0" - "@typescript-eslint/typescript-estree" "2.29.0" + "@typescript-eslint/experimental-utils" "2.30.0" + "@typescript-eslint/typescript-estree" "2.30.0" eslint-visitor-keys "^1.1.0" -"@typescript-eslint/typescript-estree@2.29.0": - version "2.29.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.29.0.tgz#1be6612bb02fc37ac9f466521c1459a4744e8d3a" - integrity sha512-3YGbtnWy4az16Egy5Fj5CckkVlpIh0MADtAQza+jiMADRSKkjdpzZp/5WuvwK/Qib3Z0HtzrDFeWanS99dNhnA== +"@typescript-eslint/typescript-estree@2.30.0": + version "2.30.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.30.0.tgz#1b8e848b55144270255ffbfe4c63291f8f766615" + integrity sha512-nI5WOechrA0qAhnr+DzqwmqHsx7Ulr/+0H7bWCcClDhhWkSyZR5BmTvnBEyONwJCTWHfc5PAQExX24VD26IAVw== dependencies: debug "^4.1.1" eslint-visitor-keys "^1.1.0" From 6bdbda9e30d3838d96584e23a9dd110e92224a3d Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 08:06:08 +0200 Subject: [PATCH 2/8] reduce unnecessary files --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 84e6669..53b8f27 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "compile": "tsc" }, "files": [ - "/dist/", + "/dist/lib/", "LICENSE" ], "dependencies": { From 373285ec46d277cc02dc99d11e4d1ca393184462 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 08:39:57 +0200 Subject: [PATCH 3/8] allow directional / undirectional --- lib/Edge.ts | 8 ++++++-- lib/Graph.ts | 5 +++-- test/Edge.ts | 10 +++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Edge.ts b/lib/Edge.ts index 2ba92ca..638b293 100644 --- a/lib/Edge.ts +++ b/lib/Edge.ts @@ -6,10 +6,12 @@ export class Edge { public target: string; public style?: EdgeStyles; public color?: Color; + private _directional: boolean; - public constructor (origin: string, target: string) { + public constructor (origin: string, target: string, directional: boolean) { this.origin = origin; this.target = target; + this._directional = directional; } // eslint-disable-next-line @typescript-eslint/naming-convention @@ -23,7 +25,9 @@ export class Edge { const attr_string = ` [${attributes.map ((v) => `${v.name}="${v.value}"`) .join (',')}]`; - return `${this.origin} -> ${this.target}${attributes.length > 0 + return `${this.origin} -${ + this._directional ? '>' : '-' + } ${this.target}${attributes.length > 0 ? attr_string : ''}`; } diff --git a/lib/Graph.ts b/lib/Graph.ts index 6582c77..43707e8 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -18,12 +18,13 @@ export class Graph extends Element { public edges: Array = []; public style?: GraphStyles; public color?: Color; + public directional = true; // eslint-disable-next-line @typescript-eslint/naming-convention public toString (): string { const header = this.parent ? `subgraph cluster_${this.full_name}` - : `digraph ${this.full_name}`; + : `${this.directional ? 'di' : ''}graph ${this.full_name}`; const attributes = []; if (this.color) attributes.push ({ name: 'color', value: this.color.toString () }); @@ -85,6 +86,6 @@ export class Graph extends Element { } public add_edge (origin: string, target: string): void { - this.edges.push (new Edge (origin, target)); + this.edges.push (new Edge (origin, target, this.directional)); } } diff --git a/test/Edge.ts b/test/Edge.ts index 9cd51c9..0daa371 100644 --- a/test/Edge.ts +++ b/test/Edge.ts @@ -2,7 +2,15 @@ import test from 'ava'; import { Edge, Color, EdgeStyles } from '../lib'; test ('serialize', (t) => { - const e = new Edge ('foo', 'bar'); + const e = new Edge ('foo', 'bar', false); + e.color = Color.white; + e.style = EdgeStyles.dashed; + const serialized = e.toString (); + t.is (serialized, 'foo -- bar [style="dashed",color="#ffffff"]'); +}); + +test ('serialize directional', (t) => { + const e = new Edge ('foo', 'bar', true); e.color = Color.white; e.style = EdgeStyles.dashed; const serialized = e.toString (); From 8af030e54f9a9d341542eee46a8df349d4b78435 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 09:59:24 +0200 Subject: [PATCH 4/8] fix --- lib/Graph.ts | 1 + test/Graph.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/Graph.ts b/lib/Graph.ts index 43707e8..5b53124 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -75,6 +75,7 @@ export class Graph extends Element { public add_graph (constructor: ((g: Graph) => void) | string): string { const graph = new Graph ('unnamed', this.full_name); + graph.directional = this.directional; if (typeof constructor === 'string') graph.name = constructor; diff --git a/test/Graph.ts b/test/Graph.ts index e591755..2826a56 100644 --- a/test/Graph.ts +++ b/test/Graph.ts @@ -26,6 +26,19 @@ const result = `digraph foo { foo_foo -> foo_baz }`; +const non_directional = `graph foo { + subgraph cluster_foo_bar { + foo_bar_baz [label="baz"] + foo_bar_asd [label="asd"] + + foo_bar_baz -- foo_bar_asd + } + + foo_foo [label="foo"] + + foo_bar_baz -- foo_foo +}`; + test ('serialize', (t) => { const g = new Graph ('foo'); @@ -63,3 +76,23 @@ test ('serialize', (t) => { t.is (serialized, result); }); + +test ('non directional', (t) => { + const g = new Graph ('foo'); + g.directional = false; + + let n = ''; + + g.add_graph ((sub) => { + sub.name = 'bar'; + n = sub.add_node ('baz'); + const n2 = sub.add_node ('asd'); + + sub.add_edge (n, n2); + }); + + const f = g.add_node ('foo'); + g.add_edge (n, f); + + t.is (g.toString (), non_directional); +}); From 4328d3a78ffe36be3e0772478a276f1021be80cf Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 10:52:02 +0200 Subject: [PATCH 5/8] more graph attributes --- lib/Graph.ts | 29 +++++++++++++++++++++++------ lib/GraphLayouts.ts | 4 ++++ lib/index.ts | 1 + yarn.lock | 18 +++++++++--------- 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 lib/GraphLayouts.ts diff --git a/lib/Graph.ts b/lib/Graph.ts index 5b53124..a61693a 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -3,6 +3,7 @@ import { Edge } from './Edge'; import { Node } from './Node'; import { GraphStyles, NodeStyles } from './Styles'; import { Color } from './Color'; +import { GraphLayouts } from './GraphLayouts'; interface NodeOptions { name: string; @@ -19,19 +20,34 @@ export class Graph extends Element { public style?: GraphStyles; public color?: Color; public directional = true; + public overlap?: boolean; + public splines?: boolean; + public layout?: GraphLayouts; + + private get attributes (): Array<{name: string; value: string}> { + const attributes = []; + + if (this.color) + attributes.push ({ name: 'color', value: this.color.toString () }); + if (this.style) + attributes.push ({ name: 'style', value: this.style.toString () }); + if (this.overlap) + attributes.push ({ name: 'overlap', value: this.overlap.toString () }); + if (this.splines) + attributes.push ({ name: 'splines', value: this.splines.toString () }); + if (this.layout) + attributes.push ({ name: 'layout', value: this.layout.toString () }); + + return attributes; + } // eslint-disable-next-line @typescript-eslint/naming-convention public toString (): string { const header = this.parent ? `subgraph cluster_${this.full_name}` : `${this.directional ? 'di' : ''}graph ${this.full_name}`; - const attributes = []; - if (this.color) - attributes.push ({ name: 'color', value: this.color.toString () }); - if (this.style) - attributes.push ({ name: 'style', value: this.style.toString () }); - let attrs = `\n${attributes.map ((v) => `${v.name} = ${v.value}`) + let attrs = `\n${this.attributes.map ((v) => `${v.name} = ${v.value}`) .join ('\n')}\n`; let children = `\n${this.children.map ((c) => c.toString ()) .join ('\n')}\n`; @@ -75,6 +91,7 @@ export class Graph extends Element { public add_graph (constructor: ((g: Graph) => void) | string): string { const graph = new Graph ('unnamed', this.full_name); + graph.directional = this.directional; if (typeof constructor === 'string') diff --git a/lib/GraphLayouts.ts b/lib/GraphLayouts.ts new file mode 100644 index 0000000..a856eef --- /dev/null +++ b/lib/GraphLayouts.ts @@ -0,0 +1,4 @@ +export enum GraphLayouts { + neato= 'neato', + dot= 'dot' +} diff --git a/lib/index.ts b/lib/index.ts index d1f0946..e029ed0 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -4,3 +4,4 @@ export { Element } from './Element'; export { Edge } from './Edge'; export { Color } from './Color'; export { EdgeStyles, NodeStyles, GraphStyles } from './Styles'; +export { GraphLayouts } from './GraphLayouts'; diff --git a/yarn.lock b/yarn.lock index c81220b..3b27672 100644 --- a/yarn.lock +++ b/yarn.lock @@ -233,26 +233,26 @@ integrity sha512-f7hJzrHjI5D+yC8KnwGV1q/vARE0ZOUHe0f3fybCmzU38wobs0Jm+XgYi98ViXqFmvt18cz1NI1c4q9sdrcsQQ== "@scode/eslint-config-es6@^1.0.1": - version "1.0.23" - resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.23.tgz#9e1cf74350217c202aaa8dfc46838416715fbf60" - integrity sha512-Ux1BOuKa9W7MoKID8VyWzJZo3je5k8h2lnc66KmBedDSruTwMhUqx2JzALoO2MeUFkvjtoVvdKXbSPvFPc54YQ== + version "1.0.24" + resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.24.tgz#c3c88ac98beb9dc73da7812f614e8f289cec763b" + integrity sha512-FyMzNbI6ZgGTr7bG1av+VSuYYWZIRbUp+ZvjVwtZduKkijXotOTg3jw0vMWi09IEq7esusQQZ/lZInAjvXJWKA== dependencies: "@scode/eslint-config" "^2.0.1" eslint-plugin-import "^2.20.1" "@scode/eslint-config-ts@^1.0.22": - version "1.0.26" - resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.26.tgz#fd980c8e1dcd8bc52e182643487af9e40393ee82" - integrity sha512-PLfaNdPXyz7V4PRDsUpcqY+l9yP3d1aRf93U55aAmA3NXmpucA8twoFgB1Li9pE8NTHbEC612gUD/pdQ+1/cQg== + version "1.0.27" + resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.27.tgz#d3d068df6f287273041029f4549378ecaa17972b" + integrity sha512-KapsP1enFNw4kBjI4L3WKBnwKeKp6Ka9ml3OoT7zpGZZLd9nzvyD1SpGks9PQ1ZJse9nBy2HVuRVPAHzfIBvmw== dependencies: "@scode/eslint-config-es6" "^1.0.1" "@typescript-eslint/eslint-plugin" "^2.26.0" "@typescript-eslint/parser" "^2.26.0" "@scode/eslint-config@^2.0.1": - version "2.0.12" - resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.12.tgz#eccd5205541fd63cbb84f72427d58873850224b0" - integrity sha512-llgvCpThp6ZDWzPPw1zmXMNwWp3oIndwX/FLigeyPQx/T1ucrbadf3iyTo0ZReJiUobGTiVBta6N13qGyzQsjA== + version "2.0.13" + resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.13.tgz#e7e4d3c9185449de7a7d810f3ee783459b779e8a" + integrity sha512-ans0dulrnReK+9+XD5nw04kKEdveEVbRL9AKH3PTr8jUQJBY/pzeDznkf6oWnLPBKqbDn/MEKlS5MOExAgooWw== dependencies: eslint-plugin-jsdoc "^24.0.0" eslint-plugin-node "^11.0.0" From 6eb3dac397506a3f0e2710c408635118557cf62e Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 10:58:37 +0200 Subject: [PATCH 6/8] fix --- lib/Graph.ts | 10 +++++----- test/Graph.ts | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/Graph.ts b/lib/Graph.ts index a61693a..4d2c53d 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -27,15 +27,15 @@ export class Graph extends Element { private get attributes (): Array<{name: string; value: string}> { const attributes = []; - if (this.color) + if (typeof this.color !== 'undefined') attributes.push ({ name: 'color', value: this.color.toString () }); - if (this.style) + if (typeof this.style !== 'undefined') attributes.push ({ name: 'style', value: this.style.toString () }); - if (this.overlap) + if (typeof this.overlap !== 'undefined') attributes.push ({ name: 'overlap', value: this.overlap.toString () }); - if (this.splines) + if (typeof this.splines !== 'undefined') attributes.push ({ name: 'splines', value: this.splines.toString () }); - if (this.layout) + if (typeof this.layout !== 'undefined') attributes.push ({ name: 'layout', value: this.layout.toString () }); return attributes; diff --git a/test/Graph.ts b/test/Graph.ts index 2826a56..4208017 100644 --- a/test/Graph.ts +++ b/test/Graph.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import { Graph, GraphStyles, Color, NodeStyles } from '../lib'; +import { Graph, GraphStyles, Color, NodeStyles, GraphLayouts } from '../lib'; const result = `digraph foo { subgraph cluster_foo_baz { @@ -39,6 +39,14 @@ const non_directional = `graph foo { foo_bar_baz -- foo_foo }`; +const attributes = `digraph attr { + color = #000000 + style = bold + overlap = false + splines = true + layout = neato +}`; + test ('serialize', (t) => { const g = new Graph ('foo'); @@ -70,6 +78,7 @@ test ('serialize', (t) => { const baz = g.add_node ('baz'); const foo = g.add_node ('foo'); + g.add_edge (foo, baz); const serialized = g.toString (); @@ -79,6 +88,7 @@ test ('serialize', (t) => { test ('non directional', (t) => { const g = new Graph ('foo'); + g.directional = false; let n = ''; @@ -92,7 +102,20 @@ test ('non directional', (t) => { }); const f = g.add_node ('foo'); + g.add_edge (n, f); t.is (g.toString (), non_directional); }); + +test ('attributes', (t) => { + const g = new Graph ('attr'); + + g.layout = GraphLayouts.neato; + g.overlap = false; + g.splines = true; + g.color = Color.black; + g.style = GraphStyles.bold; + + t.is (g.toString (), attributes); +}); From da6c26e8e0ee0646c076885616ce57ca9633025a Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 11:26:21 +0200 Subject: [PATCH 7/8] more layout engines --- jenkins.js | 1 + lib/Edge.ts | 1 + lib/Element.ts | 1 + lib/GraphLayouts.ts | 10 ++++++++-- lib/Node.ts | 3 +++ test/Color.ts | 1 + test/Edge.ts | 4 ++++ test/Node.ts | 5 +++++ 8 files changed, 24 insertions(+), 2 deletions(-) diff --git a/jenkins.js b/jenkins.js index 0a0c545..0c9ab17 100644 --- a/jenkins.js +++ b/jenkins.js @@ -7,6 +7,7 @@ const fs = require ('fs'); const child_process = require ('child_process'); const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8')); + [ ,, pkg.version ] = process.argv; diff --git a/lib/Edge.ts b/lib/Edge.ts index 638b293..3709f04 100644 --- a/lib/Edge.ts +++ b/lib/Edge.ts @@ -17,6 +17,7 @@ export class Edge { // eslint-disable-next-line @typescript-eslint/naming-convention public toString (): string { const attributes = []; + if (this.style) attributes.push ({ name: 'style', value: this.style.toString () }); if (this.color) diff --git a/lib/Element.ts b/lib/Element.ts index 160c16c..6079683 100644 --- a/lib/Element.ts +++ b/lib/Element.ts @@ -14,6 +14,7 @@ export class Element { public constructor (name: string, parent = '') { const regex = /^[a-z_][a-z_0-9]+$/iu; + if (!regex.test (name)) throw new Error ('invalid name specified'); this.name = name; diff --git a/lib/GraphLayouts.ts b/lib/GraphLayouts.ts index a856eef..29ae2ba 100644 --- a/lib/GraphLayouts.ts +++ b/lib/GraphLayouts.ts @@ -1,4 +1,10 @@ export enum GraphLayouts { - neato= 'neato', - dot= 'dot' + neato = 'neato', + dot = 'dot', + circo = 'circo', + fdp = 'fdp', + sfdp = 'sfdp', + osage = 'osage', + twopi = 'twopi', + patchwork = 'patchwork' } diff --git a/lib/Node.ts b/lib/Node.ts index 815712e..0f72262 100644 --- a/lib/Node.ts +++ b/lib/Node.ts @@ -20,6 +20,7 @@ export class Node extends Element { const mapped_columns = this.table_contents .map ((val) => `${val.join ('')}`); + return `\n ${ mapped_columns.join ('\n ') }\n
`; @@ -28,6 +29,7 @@ export class Node extends Element { // eslint-disable-next-line @typescript-eslint/naming-convention public toString (): string { const attributes = []; + if (this.label || this.is_table) { attributes.push ({ name: 'label', @@ -51,6 +53,7 @@ export class Node extends Element { '"', '"' ]; + return `${v.name}=${d[0]}${v.value}${d[1]}`; }) .join (', '); diff --git a/test/Color.ts b/test/Color.ts index 5a77f1f..75b020a 100644 --- a/test/Color.ts +++ b/test/Color.ts @@ -4,6 +4,7 @@ import { Color } from '../lib'; test ('serialize', (t) => { const wh = Color.white; const tr = Color.transparent; + t.is (wh.toString (), '#ffffff'); t.is (tr.toString (), '#00000000'); }); diff --git a/test/Edge.ts b/test/Edge.ts index 0daa371..faa2610 100644 --- a/test/Edge.ts +++ b/test/Edge.ts @@ -3,16 +3,20 @@ import { Edge, Color, EdgeStyles } from '../lib'; test ('serialize', (t) => { const e = new Edge ('foo', 'bar', false); + e.color = Color.white; e.style = EdgeStyles.dashed; const serialized = e.toString (); + t.is (serialized, 'foo -- bar [style="dashed",color="#ffffff"]'); }); test ('serialize directional', (t) => { const e = new Edge ('foo', 'bar', true); + e.color = Color.white; e.style = EdgeStyles.dashed; const serialized = e.toString (); + t.is (serialized, 'foo -> bar [style="dashed",color="#ffffff"]'); }); diff --git a/test/Node.ts b/test/Node.ts index 829cace..aaca102 100644 --- a/test/Node.ts +++ b/test/Node.ts @@ -11,16 +11,19 @@ const serialized_table = `bar_foo [label=< test ('serialize simple', (t) => { const g = new Node ('foo', 'bar', 'baz'); + g.color = Color.green; g.style = NodeStyles.dashed; const serialized = g.toString (); + t.is (g.full_name, 'bar_foo'); t.is (serialized, serialized_simple); }); test ('serialize table', (t) => { const g = new Node ('foo', 'bar', 'baz'); + g.color = Color.green; g.style = NodeStyles.invisible; @@ -44,6 +47,7 @@ test ('serialize table', (t) => { g.is_table = true; const serialized = g.toString (); + t.is (g.full_name, 'bar_foo'); t.is (serialized, serialized_table); }); @@ -51,6 +55,7 @@ test ('serialize table', (t) => { test ('adhere to naming convention', (t) => { t.throws (() => { const n = new Node ('invalid.name', 'parent'); + return n.toString (); }, { message: 'invalid name specified' }); }); From f553396eee29e1e0820624345e5d23dc3471a4a4 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 28 Apr 2020 12:30:45 +0200 Subject: [PATCH 8/8] allow strings for overlap and splines --- lib/Graph.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Graph.ts b/lib/Graph.ts index 4d2c53d..24beed0 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -20,8 +20,8 @@ export class Graph extends Element { public style?: GraphStyles; public color?: Color; public directional = true; - public overlap?: boolean; - public splines?: boolean; + public overlap?: boolean | string; + public splines?: boolean | string; public layout?: GraphLayouts; private get attributes (): Array<{name: string; value: string}> {