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' });
});