fix
This commit is contained in:
parent
4328d3a78f
commit
6eb3dac397
10
lib/Graph.ts
10
lib/Graph.ts
@ -27,15 +27,15 @@ export class Graph extends Element {
|
|||||||
private get attributes (): Array<{name: string; value: string}> {
|
private get attributes (): Array<{name: string; value: string}> {
|
||||||
const attributes = [];
|
const attributes = [];
|
||||||
|
|
||||||
if (this.color)
|
if (typeof this.color !== 'undefined')
|
||||||
attributes.push ({ name: 'color', value: this.color.toString () });
|
attributes.push ({ name: 'color', value: this.color.toString () });
|
||||||
if (this.style)
|
if (typeof this.style !== 'undefined')
|
||||||
attributes.push ({ name: 'style', value: this.style.toString () });
|
attributes.push ({ name: 'style', value: this.style.toString () });
|
||||||
if (this.overlap)
|
if (typeof this.overlap !== 'undefined')
|
||||||
attributes.push ({ name: 'overlap', value: this.overlap.toString () });
|
attributes.push ({ name: 'overlap', value: this.overlap.toString () });
|
||||||
if (this.splines)
|
if (typeof this.splines !== 'undefined')
|
||||||
attributes.push ({ name: 'splines', value: this.splines.toString () });
|
attributes.push ({ name: 'splines', value: this.splines.toString () });
|
||||||
if (this.layout)
|
if (typeof this.layout !== 'undefined')
|
||||||
attributes.push ({ name: 'layout', value: this.layout.toString () });
|
attributes.push ({ name: 'layout', value: this.layout.toString () });
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import test from 'ava';
|
import test from 'ava';
|
||||||
import { Graph, GraphStyles, Color, NodeStyles } from '../lib';
|
import { Graph, GraphStyles, Color, NodeStyles, GraphLayouts } from '../lib';
|
||||||
|
|
||||||
const result = `digraph foo {
|
const result = `digraph foo {
|
||||||
subgraph cluster_foo_baz {
|
subgraph cluster_foo_baz {
|
||||||
@ -39,6 +39,14 @@ const non_directional = `graph foo {
|
|||||||
foo_bar_baz -- foo_foo
|
foo_bar_baz -- foo_foo
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
const attributes = `digraph attr {
|
||||||
|
color = #000000
|
||||||
|
style = bold
|
||||||
|
overlap = false
|
||||||
|
splines = true
|
||||||
|
layout = neato
|
||||||
|
}`;
|
||||||
|
|
||||||
test ('serialize', (t) => {
|
test ('serialize', (t) => {
|
||||||
const g = new Graph ('foo');
|
const g = new Graph ('foo');
|
||||||
|
|
||||||
@ -70,6 +78,7 @@ test ('serialize', (t) => {
|
|||||||
|
|
||||||
const baz = g.add_node ('baz');
|
const baz = g.add_node ('baz');
|
||||||
const foo = g.add_node ('foo');
|
const foo = g.add_node ('foo');
|
||||||
|
|
||||||
g.add_edge (foo, baz);
|
g.add_edge (foo, baz);
|
||||||
|
|
||||||
const serialized = g.toString ();
|
const serialized = g.toString ();
|
||||||
@ -79,6 +88,7 @@ test ('serialize', (t) => {
|
|||||||
|
|
||||||
test ('non directional', (t) => {
|
test ('non directional', (t) => {
|
||||||
const g = new Graph ('foo');
|
const g = new Graph ('foo');
|
||||||
|
|
||||||
g.directional = false;
|
g.directional = false;
|
||||||
|
|
||||||
let n = '';
|
let n = '';
|
||||||
@ -92,7 +102,20 @@ test ('non directional', (t) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const f = g.add_node ('foo');
|
const f = g.add_node ('foo');
|
||||||
|
|
||||||
g.add_edge (n, f);
|
g.add_edge (n, f);
|
||||||
|
|
||||||
t.is (g.toString (), non_directional);
|
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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user