From cbedf36d8eedaa799bbdc68f36df337808794604 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Sat, 25 Apr 2020 17:34:05 +0200 Subject: [PATCH] complete styling --- lib/Node.ts | 11 ++++++++++- lib/Styles.ts | 3 ++- test/Node.ts | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Node.ts b/lib/Node.ts index 7574fa5..b04e136 100644 --- a/lib/Node.ts +++ b/lib/Node.ts @@ -27,10 +27,19 @@ export class Node extends Element { // 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) + attributes.push ({ name: 'color', value: this.color.toString () }); + + const attrs = attributes.map ((v) => `${v.name}="${v.value}"`) + .join (','); + if (this.is_table || typeof this.label !== 'undefined') { return `${this.full_name} [label=<${this.is_table ? this.serialized_table - : this.label}>]`; + : this.label}>${attributes.length > 0 ? `,${attrs}` : ''}]`; } return `${this.full_name}`; } diff --git a/lib/Styles.ts b/lib/Styles.ts index fa40799..262f653 100644 --- a/lib/Styles.ts +++ b/lib/Styles.ts @@ -16,7 +16,8 @@ enum NodeStyles { diagonals='diagonals', filled='filled', striped='striped', - wedged='wedged' + wedged='wedged', + invisible='invis' } enum GraphStyles { diff --git a/test/Node.ts b/test/Node.ts index f3f0cb9..e897fca 100644 --- a/test/Node.ts +++ b/test/Node.ts @@ -22,7 +22,7 @@ test ('serialize simple', (t) => { test ('serialize table', (t) => { const g = new Node ('foo', 'bar', 'baz'); g.color = Color.green; - g.style = NodeStyles.dashed; + g.style = NodeStyles.invisible; g.table_contents = [ [