ts-graphviz 1.2.4-dev.23479be87 → 1.2.4-dev.ebf0c074c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-graphviz",
3
- "version": "1.2.4-dev.23479be87",
3
+ "version": "1.2.4-dev.ebf0c074c",
4
4
  "author": "kamiazya <yuki@kamiazya.tech>",
5
5
  "description": "Graphviz library for TypeScript.",
6
6
  "homepage": "https://ts-graphviz.github.io/ts-graphviz/",
@@ -1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`class base 1`] = `
4
- digraph {
5
- subgraph "A" {
6
- "node1" [
7
- color = "red";
8
- ];
9
- "node2" [
10
- color = "blue";
11
- ];
12
- "node1" -> "node2" [
13
- label = "Edge Label";
14
- color = "pink";
15
- ];
16
- }
17
- }
18
- `;
@@ -1,200 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`function digraph callback style 1`] = `
4
- digraph "G" {
5
- "aa";
6
- "bb";
7
- "cc";
8
- subgraph "A" {
9
- "Aaa" [
10
- color = "pink";
11
- ];
12
- "Abb" [
13
- color = "violet";
14
- ];
15
- "Acc";
16
- "Aaa":"a" -> "Abb" -> "Acc" -> "E" [
17
- color = "red";
18
- ];
19
- }
20
- "aa" -> "bb" -> "cc" [
21
- color = "red";
22
- ];
23
- }
24
- `;
25
-
26
- exports[`function digraph callback style, set attributes by attributes object 1`] = `
27
- digraph "G" {
28
- "aa";
29
- "bb";
30
- "cc";
31
- subgraph "A" {
32
- "Aaa" [
33
- color = "pink";
34
- ];
35
- "Abb" [
36
- color = "violet";
37
- ];
38
- "Acc";
39
- "Aaa":"a" -> "Abb" -> "Acc" -> "E" [
40
- color = "red";
41
- ];
42
- }
43
- "aa" -> "bb" -> "cc" [
44
- color = "red";
45
- ];
46
- }
47
- `;
48
-
49
- exports[`function digraph comment 1`] = `
50
- // This is directed graph.
51
- digraph "G" {
52
- // This is node a.
53
- "aa";
54
- // This is node b.
55
- "bb";
56
- // This is node c.
57
- "cc";
58
- // It is subgraph A.
59
- // It is not cluster
60
- subgraph "A" {
61
- // This is node Aaa in subgraph A.
62
- "Aaa" [
63
- // It will be filled by pink.
64
- color = "pink";
65
- ];
66
- }
67
- // This is edge.
68
- // It connects a, b and c.
69
- "aa" -> "bb" -> "cc" [
70
- // Edge line will draw with red.
71
- color = "red";
72
- ];
73
- }
74
- `;
75
-
76
- exports[`function digraph root create function id 1`] = `digraph "id" {}`;
77
-
78
- exports[`function digraph root create function id with attributes 1`] = `
79
- digraph "id" {
80
- label = "Label";
81
- }
82
- `;
83
-
84
- exports[`function digraph root create function no id with attributes 1`] = `
85
- digraph {
86
- label = "Label";
87
- }
88
- `;
89
-
90
- exports[`function digraph root create function no parameters 1`] = `digraph {}`;
91
-
92
- exports[`function digraph root create function strict id with attributes 1`] = `
93
- strict digraph "id" {
94
- label = "Label";
95
- }
96
- `;
97
-
98
- exports[`function digraph root create function strict no id with attributes 1`] = `
99
- strict digraph {
100
- label = "Label";
101
- }
102
- `;
103
-
104
- exports[`function digraph root create function strict no parameters 1`] = `strict digraph {}`;
105
-
106
- exports[`function digraph root create function strict with attributes 1`] = `
107
- strict digraph {
108
- label = "Label";
109
- }
110
- `;
111
-
112
- exports[`function graph callback style 1`] = `
113
- graph "G" {
114
- "aa";
115
- "bb";
116
- "cc";
117
- subgraph "A" {
118
- "Aaa" [
119
- color = "pink";
120
- ];
121
- "Abb" [
122
- color = "violet";
123
- ];
124
- "Acc";
125
- "hoge";
126
- "Aaa" -- "Abb" -- "Acc" -- "hoge":"fuga" [
127
- color = "red";
128
- ];
129
- "Aaa":"a":"w" -- "Abb":"w" -- "Aaa":"e" -- "Acc":"r":"e" [
130
- color = "red";
131
- ];
132
- }
133
- "aa" -- "bb" -- "cc" [
134
- color = "red";
135
- ];
136
- }
137
- `;
138
-
139
- exports[`function graph callback style, set attributes by attributes object 1`] = `
140
- graph "G" {
141
- "aa";
142
- "bb";
143
- "cc";
144
- subgraph "A" {
145
- "Aaa" [
146
- color = "pink";
147
- ];
148
- "Abb" [
149
- color = "violet";
150
- ];
151
- "Acc";
152
- "Aaa":"a" -- "Abb" -- "Acc" -- "E" [
153
- color = "red";
154
- ];
155
- }
156
- "aa" -- "bb" -- "cc" [
157
- color = "red";
158
- ];
159
- }
160
- `;
161
-
162
- exports[`function graph escape characters 1`] = `
163
- graph "G\\n\\"" {
164
- "a\\na" [
165
- label = "1\\n2\\n\\"\\n3";
166
- ];
167
- "b\\"b";
168
- "c\\nc\\"";
169
- subgraph "graph.name" {
170
- "node.name" [
171
- label = "node";
172
- ];
173
- "another.name" [
174
- label = "words with space and \\"quote\\"";
175
- ];
176
- "node.name" -- "another.name";
177
- }
178
- "a\\na" -- "b\\"b" -- "c\\nc\\"" [
179
- color = "red";
180
- ];
181
- }
182
- `;
183
-
184
- exports[`function graph script style 1`] = `
185
- digraph "G" {
186
- "node1";
187
- "node2";
188
- subgraph "A" {
189
- "A_node1";
190
- "A_node2";
191
- "A_node1" -> "A_node2";
192
- "B_node1" -> "B_node2";
193
- }
194
- subgraph "B" {
195
- "B_node1";
196
- "B_node2";
197
- }
198
- "node1" -> "node2";
199
- }
200
- `;
@@ -1,229 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Digraph renders correctly by toDot method digraph with comment multi line comment 1`] = `
4
- // this is comment.
5
- // second line.
6
- digraph {}
7
- `;
8
-
9
- exports[`Digraph renders correctly by toDot method digraph with comment single line comment 1`] = `
10
- // this is comment.
11
- digraph {}
12
- `;
13
-
14
- exports[`Digraph renders correctly by toDot method has some attributes 1`] = `
15
- digraph {
16
- graph [
17
- color = "red";
18
- ];
19
- edge [
20
- label = "edge label";
21
- ];
22
- node [
23
- xlabel = "node xlabel";
24
- ];
25
- }
26
- `;
27
-
28
- exports[`Digraph renders correctly by toDot method label attribute behavior html like 1`] = `
29
- digraph {
30
- graph [
31
- label = <<B>this is test for graph label</B>>;
32
- ];
33
- edge [
34
- label = <<U>this is test for edge label</U>>;
35
- ];
36
- node [
37
- label = <<I>this is test for node label</I>>;
38
- ];
39
- }
40
- `;
41
-
42
- exports[`Digraph renders correctly by toDot method label attribute behavior plain text label to be quoted by double quotation 1`] = `
43
- digraph {
44
- graph [
45
- label = "this is test for graph label";
46
- ];
47
- edge [
48
- label = "this is test for edge label";
49
- ];
50
- node [
51
- label = "this is test for node label";
52
- ];
53
- }
54
- `;
55
-
56
- exports[`Digraph renders correctly by toDot method nodes and edge 1`] = `
57
- digraph {
58
- "node1";
59
- "node2";
60
- "node1" -> "node2";
61
- }
62
- `;
63
-
64
- exports[`Digraph renders correctly by toDot method set attributes 1`] = `
65
- digraph {
66
- dpi = 360;
67
- }
68
- `;
69
-
70
- exports[`Digraph renders correctly by toDot method set attributes by apply 1`] = `
71
- digraph {
72
- layout = "dot";
73
- dpi = 360;
74
- }
75
- `;
76
-
77
- exports[`Digraph renders correctly by toDot method simple g 1`] = `digraph {}`;
78
-
79
- exports[`Digraph renders correctly by toDot method strict graph 1`] = `strict digraph {}`;
80
-
81
- exports[`Digraph renders correctly by toDot method subgraphs 1`] = `
82
- digraph {
83
- "node1";
84
- "node2";
85
- subgraph "A" {
86
- "A_node1";
87
- "A_node2";
88
- "A_node1" -> "A_node2";
89
- "B_node1" -> "B_node2";
90
- }
91
- subgraph "B" {
92
- "B_node1";
93
- "B_node2";
94
- }
95
- "node1" -> "node2";
96
- }
97
- `;
98
-
99
- exports[`Digraph renders correctly by toDot method subgraphs, depth 2 1`] = `
100
- digraph {
101
- "node1";
102
- "node2";
103
- subgraph "depth1" {
104
- "depth1_node1";
105
- "depth1_node2";
106
- subgraph "depth2" {
107
- "depth2_node1";
108
- "depth2_node2";
109
- "depth2_node1" -> "depth2_node2";
110
- }
111
- "depth1_node1" -> "depth1_node2";
112
- }
113
- "node1" -> "node2";
114
- }
115
- `;
116
-
117
- exports[`Graph renders correctly by toDot method digraph with comment multi line comment 1`] = `
118
- // this is comment.
119
- // second line.
120
- graph {}
121
- `;
122
-
123
- exports[`Graph renders correctly by toDot method digraph with comment single line comment 1`] = `
124
- // this is comment.
125
- graph {}
126
- `;
127
-
128
- exports[`Graph renders correctly by toDot method has some attributes 1`] = `
129
- graph {
130
- graph [
131
- color = "red";
132
- ];
133
- edge [
134
- label = "edge label";
135
- ];
136
- node [
137
- xlabel = "node xlabel";
138
- ];
139
- }
140
- `;
141
-
142
- exports[`Graph renders correctly by toDot method label attribute behavior html like 1`] = `
143
- graph {
144
- graph [
145
- label = <<B>this is test for graph label</B>>;
146
- ];
147
- edge [
148
- label = <<U>this is test for edge label</U>>;
149
- ];
150
- node [
151
- label = <<I>this is test for node label</I>>;
152
- ];
153
- }
154
- `;
155
-
156
- exports[`Graph renders correctly by toDot method label attribute behavior plain text label to be quoted by double quotation 1`] = `
157
- graph {
158
- graph [
159
- label = "this is test for graph label";
160
- ];
161
- edge [
162
- label = "this is test for edge label";
163
- ];
164
- node [
165
- label = "this is test for node label";
166
- ];
167
- }
168
- `;
169
-
170
- exports[`Graph renders correctly by toDot method nodes and edge 1`] = `
171
- graph {
172
- "node1";
173
- "node2";
174
- "node1" -- "node2";
175
- }
176
- `;
177
-
178
- exports[`Graph renders correctly by toDot method set attributes 1`] = `
179
- graph {
180
- dpi = 360;
181
- }
182
- `;
183
-
184
- exports[`Graph renders correctly by toDot method set attributes by apply 1`] = `
185
- graph {
186
- layout = "dot";
187
- dpi = 360;
188
- }
189
- `;
190
-
191
- exports[`Graph renders correctly by toDot method simple g 1`] = `graph {}`;
192
-
193
- exports[`Graph renders correctly by toDot method strict graph 1`] = `strict graph {}`;
194
-
195
- exports[`Graph renders correctly by toDot method subgraphs 1`] = `
196
- graph {
197
- "node1";
198
- "node2";
199
- subgraph "A" {
200
- "A_node1";
201
- "A_node2";
202
- "A_node1" -- "A_node2";
203
- "B_node1" -- "B_node2";
204
- }
205
- subgraph "B" {
206
- "B_node1";
207
- "B_node2";
208
- }
209
- "node1" -- "node2";
210
- }
211
- `;
212
-
213
- exports[`Graph renders correctly by toDot method subgraphs, depth 2 1`] = `
214
- graph {
215
- "node1";
216
- "node2";
217
- subgraph "depth1" {
218
- "depth1_node1";
219
- "depth1_node2";
220
- subgraph "depth2" {
221
- "depth2_node1";
222
- "depth2_node2";
223
- "depth2_node1" -- "depth2_node2";
224
- }
225
- "depth1_node1" -- "depth1_node2";
226
- }
227
- "node1" -- "node2";
228
- }
229
- `;
@@ -1,131 +0,0 @@
1
- import { Digraph, Edge, Node, Subgraph, attribute as _, EdgeTargetTuple, withContext } from 'ts-graphviz';
2
- import { toDot } from '#test/utils';
3
-
4
- test('class base', () => {
5
- const G = new Digraph();
6
- const A = new Subgraph('A');
7
- const node1 = new Node('node1', {
8
- [_.color]: 'red',
9
- });
10
- const node2 = new Node('node2', {
11
- [_.color]: 'blue',
12
- });
13
- const edge = new Edge([node1, node2], {
14
- [_.label]: 'Edge Label',
15
- [_.color]: 'pink',
16
- });
17
- G.addSubgraph(A);
18
- A.addNode(node1);
19
- A.addNode(node2);
20
- A.addEdge(edge);
21
- const dot = toDot(G);
22
- expect(dot).toMatchSnapshot();
23
- });
24
-
25
- describe('Custom Class', () => {
26
- class MyCustomDigraph extends Digraph {
27
- constructor() {
28
- super('G', {
29
- [_.label]: 'This is Custom Digraph',
30
- });
31
- }
32
- }
33
- class MyCustomNode extends Node {
34
- constructor(id: string) {
35
- super(`node_${id}`, {
36
- [_.label]: `This is Custom Node ${id}`,
37
- });
38
- }
39
- }
40
-
41
- class MyCustomEdge extends Edge {
42
- constructor(targets: EdgeTargetTuple) {
43
- super(targets, {
44
- [_.label]: 'This is Custom Edge',
45
- });
46
- }
47
- }
48
-
49
- test('OOP', () => {
50
- const digraph = new MyCustomDigraph();
51
- const node1 = new MyCustomNode('A');
52
- const node2 = new MyCustomNode('B');
53
- const edge = new MyCustomEdge([node1, node2]);
54
- digraph.addNode(node1);
55
- digraph.addNode(node2);
56
- digraph.addEdge(edge);
57
- const dot = toDot(digraph);
58
- expect(dot).toMatchInlineSnapshot(`
59
- digraph "G" {
60
- label = "This is Custom Digraph";
61
- "node_A" [
62
- label = "This is Custom Node A";
63
- ];
64
- "node_B" [
65
- label = "This is Custom Node B";
66
- ];
67
- "node_A" -> "node_B" [
68
- label = "This is Custom Edge";
69
- ];
70
- }
71
- `);
72
- });
73
-
74
- describe('Models Context API', () => {
75
- test('with method', () => {
76
- const g = new Digraph();
77
- g.with({
78
- Node: MyCustomNode,
79
- Edge: MyCustomEdge,
80
- });
81
- const a = g.createNode('A');
82
- const b = g.createNode('B');
83
- expect(a).toBeInstanceOf(MyCustomNode);
84
- expect(g.createEdge([a, b])).toBeInstanceOf(MyCustomEdge);
85
- const dot = toDot(g);
86
- expect(dot).toMatchInlineSnapshot(`
87
- digraph {
88
- "node_A" [
89
- label = "This is Custom Node A";
90
- ];
91
- "node_B" [
92
- label = "This is Custom Node B";
93
- ];
94
- "node_A" -> "node_B" [
95
- label = "This is Custom Edge";
96
- ];
97
- }
98
- `);
99
- });
100
-
101
- test('createContext', () => {
102
- const { digraph } = withContext({
103
- Digraph: MyCustomDigraph,
104
- Node: MyCustomNode,
105
- Edge: MyCustomEdge,
106
- });
107
-
108
- const G = digraph((g) => {
109
- const a = g.node('A'); // MyCustomNode
110
- const b = g.node('B'); // MyCustomNode
111
- g.edge([a, b]); // MyCustomEdge
112
- });
113
-
114
- const dot = toDot(G);
115
- expect(dot).toMatchInlineSnapshot(`
116
- digraph "G" {
117
- label = "This is Custom Digraph";
118
- "node_A" [
119
- label = "This is Custom Node A";
120
- ];
121
- "node_B" [
122
- label = "This is Custom Node B";
123
- ];
124
- "node_A" -> "node_B" [
125
- label = "This is Custom Edge";
126
- ];
127
- }
128
- `);
129
- });
130
- });
131
- });
@@ -1,292 +0,0 @@
1
- import { digraph, graph, strict, Graph, Digraph, attribute as _ } from 'ts-graphviz';
2
- import { toDot } from '#test/utils';
3
-
4
- describe('function digraph', () => {
5
- it('should return Graph object, when execute digraph()', () => {
6
- const g = digraph();
7
- expect(g).toBeInstanceOf(Digraph);
8
- expect(g.strict).toBe(false);
9
- expect(g.directed).toBe(true);
10
- });
11
-
12
- describe('root create function', () => {
13
- test.each([
14
- ['id', { size: 0, id: 'id', strictMode: false, g: digraph('id') }],
15
- [
16
- 'id with attributes',
17
- {
18
- size: 1,
19
- id: 'id',
20
- strictMode: false,
21
- g: digraph('id', {
22
- [_.label]: 'Label',
23
- }),
24
- },
25
- ],
26
- [
27
- 'no parameters',
28
- {
29
- size: 0,
30
- id: undefined,
31
- strictMode: false,
32
- g: digraph(),
33
- },
34
- ],
35
- [
36
- 'strict no parameters',
37
- {
38
- size: 0,
39
- id: undefined,
40
- strictMode: true,
41
- g: strict.digraph(),
42
- },
43
- ],
44
- [
45
- 'no id with attributes',
46
- {
47
- size: 1,
48
- id: undefined,
49
- strictMode: false,
50
- g: digraph({
51
- [_.label]: 'Label',
52
- }),
53
- },
54
- ],
55
- [
56
- 'strict with attributes',
57
- {
58
- size: 1,
59
- id: undefined,
60
- strictMode: true,
61
- g: strict.digraph({
62
- [_.label]: 'Label',
63
- }),
64
- },
65
- ],
66
- [
67
- 'strict id with attributes',
68
- {
69
- size: 1,
70
- id: 'id',
71
- strictMode: true,
72
- g: strict.digraph('id', {
73
- [_.label]: 'Label',
74
- }),
75
- },
76
- ],
77
- [
78
- 'strict no id with attributes',
79
- {
80
- size: 1,
81
- id: undefined,
82
- strictMode: true,
83
- g: strict.digraph({
84
- [_.label]: 'Label',
85
- }),
86
- },
87
- ],
88
- ])('%s', (_, { id, size, strictMode, g }) => {
89
- expect(g.id).toBe(id);
90
- expect(g.size).toBe(size);
91
- expect(g.strict).toBe(strictMode);
92
- expect(toDot(g)).toMatchSnapshot();
93
- });
94
- });
95
-
96
- test('callback style', () => {
97
- const G = digraph('G', (g) => {
98
- const a = g.node('aa');
99
- const b = g.node('bb');
100
- const c = g.node('cc');
101
- g.edge([a, b, c], (e) => {
102
- e.attributes.set('color', 'red');
103
- });
104
- g.subgraph('A', (A) => {
105
- const Aa = A.node('Aaa', (n) => {
106
- n.attributes.set('color', 'pink');
107
- });
108
- const Ab = A.node('Abb', (n) => {
109
- n.attributes.set('color', 'violet');
110
- });
111
- const Ac = A.node('Acc');
112
- A.edge([Aa.port('a'), Ab, Ac, 'E'], (e) => {
113
- e.attributes.set('color', 'red');
114
- });
115
- });
116
- });
117
- const dot = toDot(G);
118
- expect(dot).toMatchSnapshot();
119
- });
120
-
121
- test('callback style, set attributes by attributes object', () => {
122
- const G = digraph('G', (g) => {
123
- const a = g.node('aa');
124
- const b = g.node('bb');
125
- const c = g.node('cc');
126
- g.edge([a, b, c], {
127
- [_.color]: 'red',
128
- });
129
- g.subgraph('A', (A) => {
130
- const Aa = A.node('Aaa', {
131
- [_.color]: 'pink',
132
- });
133
-
134
- const Ab = A.node('Abb', {
135
- [_.color]: 'violet',
136
- });
137
- const Ac = A.node('Acc');
138
- A.edge([Aa.port('a'), Ab, Ac, 'E'], {
139
- [_.color]: 'red',
140
- });
141
- });
142
- });
143
- const dot = toDot(G);
144
- expect(dot).toMatchSnapshot();
145
- });
146
-
147
- test('comment', () => {
148
- const G = digraph('G', (g) => {
149
- g.comment = 'This is directed graph.';
150
- const a = g.node('aa');
151
- a.comment = 'This is node a.';
152
- const b = g.node('bb');
153
- b.comment = 'This is node b.';
154
- const c = g.node('cc');
155
- c.comment = 'This is node c.';
156
- g.edge([a, b, c], (e) => {
157
- e.comment = 'This is edge.\nIt connects a, b and c.';
158
-
159
- e.attributes.set('color', 'red');
160
- e.attributes.comment = 'Edge line will draw with red.';
161
- });
162
- g.subgraph('A', (A) => {
163
- A.comment = 'It is subgraph A.\nIt is not cluster';
164
- A.node('Aaa', (n) => {
165
- n.comment = 'This is node Aaa in subgraph A.';
166
- n.attributes.comment = 'It will be filled by pink.';
167
- n.attributes.set('color', 'pink');
168
- });
169
- });
170
- });
171
- const dot = toDot(G);
172
- expect(dot).toMatchSnapshot();
173
- });
174
- });
175
-
176
- describe('function graph', () => {
177
- it('should return Graph object, when execute graph()', () => {
178
- const g = graph();
179
- expect(g).toBeInstanceOf(Graph);
180
- });
181
-
182
- it('script style', () => {
183
- const g = digraph('G');
184
- const subgraphA = g.createSubgraph('A');
185
- const nodeA1 = subgraphA.createNode('A_node1');
186
- const nodeA2 = subgraphA.createNode('A_node2');
187
- subgraphA.createEdge([nodeA1, nodeA2]);
188
-
189
- const subgraphB = g.createSubgraph('B');
190
- const nodeB1 = subgraphB.createNode('B_node1');
191
- const nodeB2 = subgraphB.createNode('B_node2');
192
- subgraphA.createEdge([nodeB1, nodeB2]);
193
-
194
- const node1 = g.createNode('node1');
195
- const node2 = g.createNode('node2');
196
- g.createEdge([node1, node2]);
197
- const dot = toDot(g);
198
- expect(dot).toMatchSnapshot();
199
- });
200
-
201
- test('callback style', () => {
202
- const G = graph('G', (g) => {
203
- const a = g.node('aa');
204
- const b = g.node('bb');
205
- const c = g.node('cc');
206
- g.edge([a, b, c], (e) => {
207
- e.attributes.set('color', 'red');
208
- });
209
- g.subgraph('A', (A) => {
210
- const Aa = A.node('Aaa', (n) => {
211
- n.attributes.set('color', 'pink');
212
- });
213
- const Ab = A.node('Abb', (n) => {
214
- n.attributes.set('color', 'violet');
215
- });
216
- const Ac = A.node('Acc');
217
- A.edge([Aa, Ab, Ac, A.node('hoge').port('fuga')], (e) => {
218
- e.attributes.set('color', 'red');
219
- });
220
-
221
- A.edge([Aa.port({ port: 'a', compass: 'w' }), Ab.port({ compass: 'w' }), 'Aaa:e', 'Acc:r:e'], (e) => {
222
- e.attributes.set('color', 'red');
223
- });
224
- });
225
- });
226
- const dot = toDot(G);
227
- expect(dot).toMatchSnapshot();
228
- });
229
-
230
- test('callback style, set attributes by attributes object', () => {
231
- const G = graph('G', (g) => {
232
- const a = g.node('aa');
233
- const b = g.node('bb');
234
- const c = g.node('cc');
235
- g.edge([a, b, c], {
236
- [_.color]: 'red',
237
- });
238
- g.subgraph('A', (A) => {
239
- const Aa = A.node('Aaa', {
240
- [_.color]: 'pink',
241
- });
242
-
243
- const Ab = A.node('Abb', {
244
- [_.color]: 'violet',
245
- });
246
- const Ac = A.node('Acc');
247
- A.edge([Aa.port('a'), Ab, Ac, 'E'], {
248
- [_.color]: 'red',
249
- });
250
- });
251
- });
252
- const dot = toDot(G);
253
- expect(dot).toMatchSnapshot();
254
- });
255
-
256
- test('escape characters', () => {
257
- const G = graph('G\n"', (g) => {
258
- const a = g.node('a\na');
259
- a.attributes.set('label', '1\n2\n"\n3');
260
- const b = g.node('b"b');
261
- const c = g.node('c\nc"');
262
- g.edge([a, b, c], (e) => {
263
- e.attributes.set('color', 'red');
264
- });
265
-
266
- g.subgraph('graph.name', (s) => {
267
- const innerA = s.node('node.name');
268
- innerA.attributes.set('label', 'node');
269
- const innerB = s.node('another.name');
270
- innerB.attributes.set('label', 'words with space and "quote"');
271
- s.edge([innerA, innerB]);
272
- });
273
- });
274
- const dot = toDot(G);
275
- expect(dot).toMatchSnapshot();
276
- });
277
- });
278
-
279
- describe('strict mode', () => {
280
- it('should return Digraph object, when execute digraph()', () => {
281
- const g = strict.digraph();
282
- expect(g).toBeInstanceOf(Digraph);
283
- expect(g.strict).toBe(true);
284
- expect(g.directed).toBe(true);
285
- });
286
-
287
- it('should return Graph object, when execute graph()', () => {
288
- const g = strict.graph();
289
- expect(g).toBeInstanceOf(Graph);
290
- expect(g.strict).toBe(true);
291
- });
292
- });
@@ -1,96 +0,0 @@
1
- import { digraph } from 'ts-graphviz';
2
- import { fromModel } from 'ts-graphviz/ast';
3
-
4
- import { toDot } from '#test/utils';
5
-
6
- test('edge group', () => {
7
- expect(
8
- fromModel(
9
- digraph((g) => {
10
- g.edge(['a', ['b', 'c']]);
11
- }),
12
- ),
13
- ).toMatchInlineSnapshot(`
14
- Object {
15
- "children": Array [
16
- Object {
17
- "children": Array [
18
- Object {
19
- "children": Array [],
20
- "location": null,
21
- "targets": Array [
22
- Object {
23
- "children": Array [],
24
- "compass": undefined,
25
- "id": Object {
26
- "children": Array [],
27
- "location": null,
28
- "quoted": true,
29
- "type": "Literal",
30
- "value": "a",
31
- },
32
- "location": null,
33
- "port": undefined,
34
- "type": "NodeRef",
35
- },
36
- Object {
37
- "children": Array [
38
- Object {
39
- "children": Array [],
40
- "compass": undefined,
41
- "id": Object {
42
- "children": Array [],
43
- "location": null,
44
- "quoted": true,
45
- "type": "Literal",
46
- "value": "b",
47
- },
48
- "location": null,
49
- "port": undefined,
50
- "type": "NodeRef",
51
- },
52
- Object {
53
- "children": Array [],
54
- "compass": undefined,
55
- "id": Object {
56
- "children": Array [],
57
- "location": null,
58
- "quoted": true,
59
- "type": "Literal",
60
- "value": "c",
61
- },
62
- "location": null,
63
- "port": undefined,
64
- "type": "NodeRef",
65
- },
66
- ],
67
- "location": null,
68
- "type": "NodeRefGroup",
69
- },
70
- ],
71
- "type": "Edge",
72
- },
73
- ],
74
- "directed": true,
75
- "id": undefined,
76
- "location": null,
77
- "strict": false,
78
- "type": "Graph",
79
- },
80
- ],
81
- "location": null,
82
- "type": "Dot",
83
- }
84
- `);
85
- expect(
86
- toDot(
87
- digraph((g) => {
88
- g.edge(['a', ['b', 'c']]);
89
- }),
90
- ),
91
- ).toMatchInlineSnapshot(`
92
- digraph {
93
- "a" -> {"b" "c"};
94
- }
95
- `);
96
- });
@@ -1,58 +0,0 @@
1
- import { Digraph, Edge, Node, RootGraph, Subgraph, fromDot } from 'ts-graphviz';
2
- import { toDot } from '#test/utils';
3
-
4
- describe('fromDot function', () => {
5
- test('RootGraph', () => {
6
- const G = fromDot('digraph {}');
7
- expect(G).toBeInstanceOf(RootGraph);
8
- expect(G).toBeInstanceOf(Digraph);
9
- expect(G.strict).toStrictEqual(false);
10
- });
11
-
12
- test('Node', () => {
13
- const node = fromDot('a[ label = hoge]', { parse: { startRule: 'Node' } });
14
- expect(node).toBeInstanceOf(Node);
15
- expect(node.id).toStrictEqual('a');
16
- expect(node.attributes.get('label')).toStrictEqual('hoge');
17
- });
18
-
19
- test('Edge', () => {
20
- const edge = fromDot('a -> b [ label = hoge]', { parse: { startRule: 'Edge' } });
21
- expect(edge).toBeInstanceOf(Edge);
22
- expect(edge.targets).toMatchObject([{ id: 'a' }, { id: 'b' }]);
23
- expect(edge.attributes.get('label')).toStrictEqual('hoge');
24
- });
25
-
26
- test('Subgraph', () => {
27
- const subgraph = fromDot(
28
- `subgraph sub {
29
- label = hoge;
30
- }`,
31
- { parse: { startRule: 'Subgraph' } },
32
- );
33
- expect(subgraph).toBeInstanceOf(Subgraph);
34
- expect(subgraph.id).toStrictEqual('sub');
35
- expect(subgraph.get('label')).toStrictEqual('hoge');
36
- });
37
- });
38
-
39
- test('partially described by DOT', () => {
40
- const G = fromDot(
41
- `digraph {
42
- node_A [
43
- label = "This is a Label of Node A";
44
- ];
45
- }`,
46
- );
47
-
48
- G.edge(['node_A', 'node_B']);
49
-
50
- expect(toDot(G)).toMatchInlineSnapshot(`
51
- digraph {
52
- "node_A" [
53
- label = "This is a Label of Node A";
54
- ];
55
- "node_A" -> "node_B";
56
- }
57
- `);
58
- });
@@ -1,112 +0,0 @@
1
- import { RootGraphModel, Digraph, Graph, attribute as _ } from 'ts-graphviz';
2
- import { toDot } from '#test/utils';
3
-
4
- describe.each([
5
- ['Digraph', () => new Digraph()],
6
- ['Graph', () => new Graph()],
7
- ])('%s', (__, rootClusterFactory) => {
8
- let g: RootGraphModel;
9
- beforeEach(() => {
10
- g = rootClusterFactory();
11
- });
12
-
13
- describe('renders correctly by toDot method', () => {
14
- it('simple g', () => {
15
- expect(toDot(g)).toMatchSnapshot();
16
- });
17
-
18
- it('strict graph', () => {
19
- g.strict = true;
20
- expect(toDot(g)).toMatchSnapshot();
21
- });
22
-
23
- test('set attributes', () => {
24
- g.set(_.dpi, 360);
25
- expect(toDot(g)).toMatchSnapshot();
26
- });
27
-
28
- test('set attributes by apply', () => {
29
- g.apply({
30
- [_.layout]: 'dot',
31
- [_.dpi]: 360,
32
- });
33
- expect(toDot(g)).toMatchSnapshot();
34
- });
35
-
36
- describe('digraph with comment', () => {
37
- test('single line comment', () => {
38
- g.comment = 'this is comment.';
39
- expect(toDot(g)).toMatchSnapshot();
40
- });
41
-
42
- test('multi line comment', () => {
43
- g.comment = 'this is comment.\nsecond line.';
44
- expect(toDot(g)).toMatchSnapshot();
45
- });
46
- });
47
-
48
- it('has some attributes', () => {
49
- g.attributes.edge.set(_.label, 'edge label');
50
- g.attributes.graph.set(_.color, 'red');
51
- g.attributes.node.set(_.xlabel, 'node xlabel');
52
- expect(toDot(g)).toMatchSnapshot();
53
- });
54
-
55
- it('nodes and edge', () => {
56
- const node1 = g.createNode('node1');
57
- const node2 = g.createNode('node2');
58
- g.createEdge([node1, node2]);
59
- expect(toDot(g)).toMatchSnapshot();
60
- });
61
-
62
- it('subgraphs', () => {
63
- const subgraphA = g.createSubgraph('A');
64
- const nodeA1 = subgraphA.createNode('A_node1');
65
- const nodeA2 = subgraphA.createNode('A_node2');
66
- subgraphA.createEdge([nodeA1, nodeA2]);
67
-
68
- const subgraphB = g.createSubgraph('B');
69
- const nodeB1 = subgraphB.createNode('B_node1');
70
- const nodeB2 = subgraphB.createNode('B_node2');
71
- subgraphA.createEdge([nodeB1, nodeB2]);
72
-
73
- const node1 = g.createNode('node1');
74
- const node2 = g.createNode('node2');
75
- g.createEdge([node1, node2]);
76
- expect(toDot(g)).toMatchSnapshot();
77
- });
78
-
79
- it('subgraphs, depth 2', () => {
80
- const subgraphDepth1 = g.createSubgraph('depth1');
81
- const nodeA1 = subgraphDepth1.createNode('depth1_node1');
82
- const nodeA2 = subgraphDepth1.createNode('depth1_node2');
83
- subgraphDepth1.createEdge([nodeA1, nodeA2]);
84
-
85
- const subgraphDepth2 = subgraphDepth1.createSubgraph('depth2');
86
- const nodeB1 = subgraphDepth2.createNode('depth2_node1');
87
- const nodeB2 = subgraphDepth2.createNode('depth2_node2');
88
- subgraphDepth2.createEdge([nodeB1, nodeB2]);
89
-
90
- const node1 = g.createNode('node1');
91
- const node2 = g.createNode('node2');
92
- g.createEdge([node1, node2]);
93
- expect(toDot(g)).toMatchSnapshot();
94
- });
95
-
96
- describe('label attribute behavior', () => {
97
- it('plain text label to be quoted by double quotation', () => {
98
- g.attributes.graph.set(_.label, 'this is test for graph label');
99
- g.attributes.edge.set(_.label, 'this is test for edge label');
100
- g.attributes.node.set(_.label, 'this is test for node label');
101
- expect(toDot(g)).toMatchSnapshot();
102
- });
103
-
104
- it('html like', () => {
105
- g.attributes.graph.set(_.label, '<<B>this is test for graph label</B>>');
106
- g.attributes.edge.set(_.label, '<<U>this is test for edge label</U>>');
107
- g.attributes.node.set(_.label, '<<I>this is test for node label</I>>');
108
- expect(toDot(g)).toMatchSnapshot();
109
- });
110
- });
111
- });
112
- });
@@ -1 +0,0 @@
1
- export * from './to-dot.js';
@@ -1,5 +0,0 @@
1
- import { pipe } from '../../src/utils/index.js';
2
- import { wrap } from 'jest-snapshot-serializer-raw';
3
- import { toDot as _toDot } from 'ts-graphviz';
4
-
5
- export const toDot = pipe(_toDot, wrap);