more layout engines
This commit is contained in:
parent
6eb3dac397
commit
da6c26e8e0
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,10 @@
|
||||
export enum GraphLayouts {
|
||||
neato = 'neato',
|
||||
dot= 'dot'
|
||||
dot = 'dot',
|
||||
circo = 'circo',
|
||||
fdp = 'fdp',
|
||||
sfdp = 'sfdp',
|
||||
osage = 'osage',
|
||||
twopi = 'twopi',
|
||||
patchwork = 'patchwork'
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ export class Node extends Element {
|
||||
|
||||
const mapped_columns = this.table_contents
|
||||
.map ((val) => `<td>${val.join ('</td><td>')}</td>`);
|
||||
|
||||
return `<table>\n <tr>${
|
||||
mapped_columns.join ('</tr>\n <tr>')
|
||||
}</tr>\n</table>`;
|
||||
@ -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 (', ');
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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"]');
|
||||
});
|
||||
|
@ -11,16 +11,19 @@ const serialized_table = `bar_foo [label=<<table>
|
||||
|
||||
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' });
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user