GraphStream

This commit is contained in:
2020-05-06 20:24:37 +02:00
parent acf8004497
commit 8d6d91e562
21 changed files with 357 additions and 81 deletions

View File

@ -1,11 +1,11 @@
import test from 'ava';
import { Edge, Color, EdgeStyles } from '../lib';
import { Edge, Color } from '../lib';
test ('serialize', (t) => {
const e = new Edge ('foo', 'bar', false);
e.color = Color.white;
e.style = EdgeStyles.dashed;
e.style = 'dashed';
const serialized = e.toString ();
t.is (serialized, 'foo -- bar [style="dashed",color="#ffffff"]');
@ -15,7 +15,7 @@ test ('serialize directional', (t) => {
const e = new Edge ('foo', 'bar', true);
e.color = Color.white;
e.style = EdgeStyles.dashed;
e.style = 'dashed';
const serialized = e.toString ();
t.is (serialized, 'foo -> bar [style="dashed",color="#ffffff"]');

View File

@ -1,5 +1,5 @@
import test from 'ava';
import { Graph, GraphStyles, Color, NodeStyles, GraphLayouts } from '../lib';
import { Graph, Color } from '../lib';
const result = `digraph foo {
subgraph cluster_foo_baz {
@ -56,23 +56,23 @@ test ('serialize', (t) => {
graph.add_node ('asd');
graph.add_node ((n) => {
n.name = 'test';
n.style = NodeStyles.bold;
n.style = 'bold';
n.color = Color.gray;
});
// eslint-disable-next-line no-shadow
graph.add_graph ((g) => {
g.style = GraphStyles.dotted;
g.style = 'dotted';
g.color = Color.gray;
g.name = 'nested';
// eslint-disable-next-line no-shadow, max-nested-callbacks
g.add_graph ((g) => {
g.style = GraphStyles.dotted;
g.style = 'dotted';
g.color = Color.gray;
});
});
graph.style = GraphStyles.bold;
graph.style = 'bold';
graph.color = Color.red;
});
@ -111,11 +111,11 @@ test ('non directional', (t) => {
test ('attributes', (t) => {
const g = new Graph ('attr');
g.layout = GraphLayouts.neato;
g.layout = 'neato';
g.overlap = false;
g.splines = true;
g.color = Color.black;
g.style = GraphStyles.bold;
g.style = 'bold';
t.is (g.toString (), attributes);
});

View File

@ -1,5 +1,5 @@
import test from 'ava';
import { NodeStyles, Node, Color } from '../lib';
import { Node, Color } from '../lib';
const serialized_simple
= 'bar_foo [label="baz", style="dashed", color="#00ff00"]';
@ -13,7 +13,7 @@ test ('serialize simple', (t) => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = NodeStyles.dashed;
g.style = 'dashed';
const serialized = g.toString ();
@ -25,7 +25,7 @@ test ('serialize table', (t) => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = NodeStyles.invisible;
g.style = 'invis';
g.table_contents = [
[

89
test/Stream.ts Normal file
View File

@ -0,0 +1,89 @@
import test from 'ava';
import { GraphStream, Color } from '../lib/index';
const simple = `graph foo {
}
`;
const complex = `digraph foo {
subgraph cluster_foo_baz {
color = #ff0000
style = bold
subgraph cluster_foo_baz_nested {
color = #808080
style = dotted
subgraph cluster_foo_baz_nested_unnamed {
color = #808080
style = dotted
}
}
foo_baz_asd [label = "asd"]
foo_baz_test [style = "bold", color = "#808080"]
}
foo_baz [label = "baz"]
foo_foo [label = "foo"]
foo_foo -> foo_baz
}
`;
test ('stream graph', (t) => new Promise ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {
output += data;
});
stream.on ('end', () => {
t.is (output, simple);
resolve ();
});
stream.create_graph ('foo', 'u');
stream.end_graph ();
stream.end ();
}));
// eslint-disable-next-line max-statements
test ('complex stream graph', (t) => new Promise ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {
output += data;
});
stream.on ('end', () => {
t.is (output, complex);
t.log (output);
resolve ();
});
stream.create_graph ('foo', 'd');
stream.create_graph ('baz');
stream.attributes ({ color: Color.red, style: 'bold' });
stream.create_graph ('nested');
stream.attributes ({ color: Color.gray, style: 'dotted' });
stream.create_graph ('unnamed');
stream.attributes ({ color: Color.gray, style: 'dotted' });
stream.end_graph ();
stream.end_graph ();
stream.create_node ('asd');
stream.attributes ({ label: 'asd' });
stream.end_node ();
stream.create_node ('test');
stream.attributes ({ style: 'bold', color: Color.gray });
stream.end_node ();
stream.end_graph ();
stream.create_node ('baz');
stream.attributes ({ label: 'baz' });
stream.end_node ();
stream.create_node ('foo');
stream.attributes ({ label: 'foo' });
stream.end_node ();
stream.create_edge (`${stream.path}_foo`, `${stream.path}_baz`);
stream.end_graph ();
stream.end ();
}));