ts-graphviz 0.15.1 → 1.0.0-1
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/LICENSE +1 -1
- package/README.ja.md +379 -0
- package/README.md +280 -174
- package/lib/ast/index.cjs +5543 -0
- package/lib/ast/index.d.ts +387 -0
- package/lib/ast/index.js +5527 -0
- package/lib/common/index.cjs +47 -0
- package/lib/common/index.d.ts +2092 -0
- package/lib/common/index.js +45 -0
- package/lib/core/index.cjs +446 -0
- package/lib/core/index.d.ts +3027 -0
- package/lib/core/index.js +444 -0
- package/lib/index.cjs +25 -0
- package/lib/index.d.ts +2 -3456
- package/lib/index.js +2 -16
- package/lib/utils/index.cjs +43 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +37 -0
- package/media/state-machine.dot +10 -0
- package/media/state-machine.svg +1 -0
- package/media/ts-graphviz.dot +20 -0
- package/media/ts-graphviz.svg +1 -0
- package/package.json +58 -35
- package/tsconfig.build.json +8 -0
- package/lib/bundle.min.js +0 -16
- package/lib/index.mjs +0 -16
- package/scripts/build.ts +0 -42
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
The MIT License (MIT)
|
|
3
3
|
|
|
4
|
-
Copyright (c) 2019-
|
|
4
|
+
Copyright (c) 2019-2022 Yuki Yamazaki
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
[](https://github.com/kamiazya/ts-graphviz/actions?workflow=NodeCI)
|
|
2
|
+
[](https://badge.fury.io/js/ts-graphviz)
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
 <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
7
|
+
[](#contributors)
|
|
8
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
9
|
+
|
|
10
|
+
[English](https://github.com/ts-graphviz/ts-graphviz/blob/main/README.md) | [日本語](https://github.com/ts-graphviz/ts-graphviz/blob/main/README.ja.md)
|
|
11
|
+
|
|
12
|
+
# ts-graphviz
|
|
13
|
+
|
|
14
|
+
TypeScriptの ための [Graphviz](https://graphviz.gitlab.io/) ライブラリ
|
|
15
|
+
|
|
16
|
+
## 主な機能 ✨
|
|
17
|
+
|
|
18
|
+
TypeScript に完全に統合された Graphviz DOT言語のモデルとASTを提供します。
|
|
19
|
+
|
|
20
|
+
- **TypeScript フレンドリーな API**
|
|
21
|
+
- DOT言語のモデルを提供しています。また属性と属性の型まで TypeScript の型定義が用意されています。
|
|
22
|
+
- **パラダイムからの開放**
|
|
23
|
+
- オブジェクト指向で設計され、命令的 API と 宣言的 API のどちらにも適合できるAPI提供しています。 プロジェクトにあったパラダイムを選択できます。
|
|
24
|
+
- **あらゆるユースケースに対応**
|
|
25
|
+
- モデルを提供する高レイヤーの API と ASTを取り扱う低レイヤーの API をどちらも提供し、あらゆるユースケースに対応します。
|
|
26
|
+
|
|
27
|
+
## インストール方法 💽
|
|
28
|
+
|
|
29
|
+
[npm](https://www.npmjs.com/) からインストールできます。
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# yarn
|
|
33
|
+
$ yarn add ts-graphviz
|
|
34
|
+
# or npm
|
|
35
|
+
$ npm install -S ts-graphviz
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 使い方 📑
|
|
39
|
+
|
|
40
|
+
### `ts-graphviz` モジュール 🚩
|
|
41
|
+
|
|
42
|
+
DOT 言語をJavaScript/TypeScriptで扱うためのインターフェースである Model を提供します。
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
#### オブジェクト指向 ❤️
|
|
47
|
+
|
|
48
|
+
**Model** はオブジェクト指向に設計されており、 `Digraph`, `Graph`, `Subgraph`, `Node`, `Edge` のクラスを提供しています。
|
|
49
|
+
|
|
50
|
+
**Model** を **DOT** (DOT言語の文字列)に変換する`toDot` 関数を提供しています。
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { attribute as _, Digraph, Subgraph, Node, Edge, toDot } from 'ts-graphviz';
|
|
54
|
+
|
|
55
|
+
const G = new Digraph();
|
|
56
|
+
const A = new Subgraph('A');
|
|
57
|
+
const node1 = new Node('node1', {
|
|
58
|
+
[_.color]: 'red'
|
|
59
|
+
});
|
|
60
|
+
const node2 = new Node('node2', {
|
|
61
|
+
[_.color]: 'blue'
|
|
62
|
+
});
|
|
63
|
+
const edge = new Edge([node1, node2], {
|
|
64
|
+
[_.label]: 'Edge Label',
|
|
65
|
+
[_.color]: 'pink'
|
|
66
|
+
});
|
|
67
|
+
G.addSubgraph(A);
|
|
68
|
+
A.addNode(node1);
|
|
69
|
+
A.addNode(node2);
|
|
70
|
+
A.addEdge(edge);
|
|
71
|
+
const dot = toDot(G);
|
|
72
|
+
// digraph {
|
|
73
|
+
// subgraph "A" {
|
|
74
|
+
// "node1" [
|
|
75
|
+
// color = "red",
|
|
76
|
+
// ];
|
|
77
|
+
// "node2" [
|
|
78
|
+
// color = "blue",
|
|
79
|
+
// ];
|
|
80
|
+
// "node1" -> "node2" [
|
|
81
|
+
// label = "Edge Label",
|
|
82
|
+
// color = "pink",
|
|
83
|
+
// ];
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
<details>
|
|
89
|
+
<summary>高度な使い方</summary>
|
|
90
|
+
|
|
91
|
+
クラスを継承することで独自の実装を加えることもできます。
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { Digraph, Node, Edge, EdgeTargetTuple, attribute as _, toDot } from 'ts-graphviz';
|
|
95
|
+
|
|
96
|
+
class MyCustomDigraph extends Digraph {
|
|
97
|
+
constructor() {
|
|
98
|
+
super('G', {
|
|
99
|
+
[_.label]: 'This is Custom Digraph',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class MyCustomNode extends Node {
|
|
104
|
+
constructor(id: number) {
|
|
105
|
+
super(`node${id}`, {
|
|
106
|
+
[_.label]: `This is Custom Node ${id}`
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class MyCustomEdge extends Edge {
|
|
112
|
+
constructor(targets: EdgeTargetTuple) {
|
|
113
|
+
super(targets, {
|
|
114
|
+
[_.label]: 'This is Custom Edge'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const digraph = new MyCustomDigraph();
|
|
120
|
+
const node1 = new MyCustomNode(1);
|
|
121
|
+
const node2 = new MyCustomNode(2);
|
|
122
|
+
const edge = new MyCustomEdge([node1, node2]);
|
|
123
|
+
digraph.addNode(node1);
|
|
124
|
+
digraph.addNode(node2);
|
|
125
|
+
digraph.addEdge(edge);
|
|
126
|
+
const dot = toDot(g);
|
|
127
|
+
// digraph "G" {
|
|
128
|
+
// label = "This is Custom Digraph";
|
|
129
|
+
// "node1" [
|
|
130
|
+
// label = "This is Custom Node 1",
|
|
131
|
+
// ];
|
|
132
|
+
// "node2" [
|
|
133
|
+
// label = "This is Custom Node 2",
|
|
134
|
+
// ];
|
|
135
|
+
// "node1" -> "node2" [
|
|
136
|
+
// label = "This is Custom Edge",
|
|
137
|
+
// ];
|
|
138
|
+
// }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
</details>
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
#### 宣言的な API 😎
|
|
145
|
+
|
|
146
|
+
`Graph` や `Digraph` を作成する際に、より **DOT** 言語に近い記法を提供するために _Builder Functuion_ を使うことができます。
|
|
147
|
+
|
|
148
|
+
**Model** にも宣言的な API を用意しており、一貫して宣言的なパラダイムを選択することもできます。
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { attribute as _, digraph, toDot } from 'ts-graphviz';
|
|
152
|
+
|
|
153
|
+
const G = digraph('G', (g) => {
|
|
154
|
+
const a = g.node('aa');
|
|
155
|
+
const b = g.node('bb');
|
|
156
|
+
const c = g.node('cc');
|
|
157
|
+
g.edge([a, b, c], {
|
|
158
|
+
[_.color]: 'red'
|
|
159
|
+
});
|
|
160
|
+
g.subgraph('A', (A) => {
|
|
161
|
+
const Aa = A.node('Aaa', {
|
|
162
|
+
[_.color]: 'pink'
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const Ab = A.node('Abb', {
|
|
166
|
+
[_.color]: 'violet'
|
|
167
|
+
});
|
|
168
|
+
const Ac = A.node('Acc');
|
|
169
|
+
A.edge([Aa.port('a'), Ab, Ac, 'E'], {
|
|
170
|
+
[_.color]: 'red'
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const dot = toDot(G);
|
|
176
|
+
// digraph "G" {
|
|
177
|
+
// "aa";
|
|
178
|
+
// "bb";
|
|
179
|
+
// "cc";
|
|
180
|
+
// subgraph "A" {
|
|
181
|
+
// "Aaa" [
|
|
182
|
+
// color = "pink",
|
|
183
|
+
// ];
|
|
184
|
+
// "Abb" [
|
|
185
|
+
// color = "violet",
|
|
186
|
+
// ];
|
|
187
|
+
// "Acc";
|
|
188
|
+
// "Aaa":"a" -> "Abb" -> "Acc" -> "E" [
|
|
189
|
+
// color = "red",
|
|
190
|
+
// ];
|
|
191
|
+
// }
|
|
192
|
+
// "aa" -> "bb" -> "cc" [
|
|
193
|
+
// color = "red",
|
|
194
|
+
// ];
|
|
195
|
+
// }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
> **Note** もちろん、strictモードのグラフを作るAPIも提供しています。
|
|
199
|
+
>
|
|
200
|
+
> ```typescript
|
|
201
|
+
> import { strict, toDot } from 'ts-graphviz';
|
|
202
|
+
>
|
|
203
|
+
> const G = strict.graph(...);
|
|
204
|
+
> const dot = toDot(G);
|
|
205
|
+
> // strict graph {
|
|
206
|
+
> // }
|
|
207
|
+
> ```
|
|
208
|
+
|
|
209
|
+
### `ts-graphviz/ast` モジュール 🔢
|
|
210
|
+
|
|
211
|
+
高度な利用のためにASTを扱うためのAPIを提供しています。
|
|
212
|
+
|
|
213
|
+

|
|
214
|
+
|
|
215
|
+
状態遷移図で記載している通り、下記の関数を提供しています。
|
|
216
|
+
|
|
217
|
+
- **Model** から **AST** に変換する `fromModel` 関数
|
|
218
|
+
- **AST** から **DOT** に変換する `stringify` 関数
|
|
219
|
+
- **DOT** から **AST** に変換する `parse` 関数
|
|
220
|
+
|
|
221
|
+
> **Note** 上記の図からわかるように、`ts-graphviz` パッケージで提供している `toDot` 関数は、 `fromModel` と `stringify` の合成関数です。
|
|
222
|
+
|
|
223
|
+
詳しい利用方法は整備中です。
|
|
224
|
+
TypeScriptの型定義を参考にしてください。
|
|
225
|
+
|
|
226
|
+
<details>
|
|
227
|
+
<summary>parse 関数とAST</summary>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { parse } from 'ts-graphviz/ast';
|
|
232
|
+
|
|
233
|
+
const ast = parse(`
|
|
234
|
+
digraph example {
|
|
235
|
+
node1 [
|
|
236
|
+
label = "My Node",
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
`);
|
|
240
|
+
// {
|
|
241
|
+
// type: 'Dot',
|
|
242
|
+
// location: {
|
|
243
|
+
// start: { offset: 3, line: 2, column: 3 },
|
|
244
|
+
// end: { offset: 68, line: 7, column: 1 }
|
|
245
|
+
// },
|
|
246
|
+
// children: [
|
|
247
|
+
// {
|
|
248
|
+
// id: {
|
|
249
|
+
// value: 'example',
|
|
250
|
+
// quoted: false,
|
|
251
|
+
// type: 'Literal',
|
|
252
|
+
// location: {
|
|
253
|
+
// start: { offset: 11, line: 2, column: 11 },
|
|
254
|
+
// end: { offset: 18, line: 2, column: 18 }
|
|
255
|
+
// },
|
|
256
|
+
// children: []
|
|
257
|
+
// },
|
|
258
|
+
// directed: true,
|
|
259
|
+
// strict: false,
|
|
260
|
+
// type: 'Graph',
|
|
261
|
+
// location: {
|
|
262
|
+
// start: { offset: 3, line: 2, column: 3 },
|
|
263
|
+
// end: { offset: 67, line: 6, column: 4 }
|
|
264
|
+
// },
|
|
265
|
+
// children: [
|
|
266
|
+
// {
|
|
267
|
+
// id: {
|
|
268
|
+
// value: 'node1',
|
|
269
|
+
// quoted: false,
|
|
270
|
+
// type: 'Literal',
|
|
271
|
+
// location: {
|
|
272
|
+
// start: { offset: 25, line: 3, column: 5 },
|
|
273
|
+
// end: { offset: 30, line: 3, column: 10 }
|
|
274
|
+
// },
|
|
275
|
+
// children: []
|
|
276
|
+
// },
|
|
277
|
+
// type: 'Node',
|
|
278
|
+
// location: {
|
|
279
|
+
// start: { offset: 25, line: 3, column: 5 },
|
|
280
|
+
// end: { offset: 63, line: 5, column: 6 }
|
|
281
|
+
// },
|
|
282
|
+
// children: [
|
|
283
|
+
// {
|
|
284
|
+
// key: {
|
|
285
|
+
// value: 'label',
|
|
286
|
+
// quoted: false,
|
|
287
|
+
// type: 'Literal',
|
|
288
|
+
// location: {
|
|
289
|
+
// start: { offset: 39, line: 4, column: 7 },
|
|
290
|
+
// end: { offset: 44, line: 4, column: 12 }
|
|
291
|
+
// },
|
|
292
|
+
// children: []
|
|
293
|
+
// },
|
|
294
|
+
// value: {
|
|
295
|
+
// value: 'My Node',
|
|
296
|
+
// quoted: true,
|
|
297
|
+
// type: 'Literal',
|
|
298
|
+
// location: {
|
|
299
|
+
// start: { offset: 47, line: 4, column: 15 },
|
|
300
|
+
// end: { offset: 56, line: 4, column: 24 }
|
|
301
|
+
// },
|
|
302
|
+
// children: []
|
|
303
|
+
// },
|
|
304
|
+
// location: {
|
|
305
|
+
// start: { offset: 39, line: 4, column: 7 },
|
|
306
|
+
// end: { offset: 57, line: 4, column: 25 }
|
|
307
|
+
// },
|
|
308
|
+
// type: 'Attribute',
|
|
309
|
+
// children: []
|
|
310
|
+
// }
|
|
311
|
+
// ]
|
|
312
|
+
// }
|
|
313
|
+
// ]
|
|
314
|
+
// }
|
|
315
|
+
// ]
|
|
316
|
+
// }
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
</details>
|
|
320
|
+
|
|
321
|
+
## 関連プロジェクト 💫
|
|
322
|
+
|
|
323
|
+
関連するプロジェクトは [**ts-graphviz** GitHub Organization](https://github.com/ts-graphviz) で確認することができます。
|
|
324
|
+
|
|
325
|
+
TypeScript/JavaScript エコシステムで Graphviz との結合度を高め、より使いやすくすることを目的に様々な OSS を提供しています。
|
|
326
|
+
|
|
327
|
+
## コントリビュータ 👥
|
|
328
|
+
|
|
329
|
+
この素晴らしい人たち([emoji key](https://allcontributors.org/docs/en/emoji-key))に感謝します。
|
|
330
|
+
|
|
331
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
332
|
+
<!-- prettier-ignore-start -->
|
|
333
|
+
<!-- markdownlint-disable -->
|
|
334
|
+
<table>
|
|
335
|
+
<tbody>
|
|
336
|
+
<tr>
|
|
337
|
+
<td align="center"><a href="http://blog.kamiazya.tech/"><img src="https://avatars0.githubusercontent.com/u/35218186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yuki Yamazaki</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Code">💻</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Tests">⚠️</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Documentation">📖</a> <a href="#ideas-kamiazya" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
338
|
+
<td align="center"><a href="https://laysent.com"><img src="https://avatars2.githubusercontent.com/u/1191606?v=4?s=100" width="100px;" alt=""/><br /><sub><b>LaySent</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Alaysent" title="Bug reports">🐛</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=laysent" title="Tests">⚠️</a></td>
|
|
339
|
+
<td align="center"><a href="https://github.com/elasticdotventures"><img src="https://avatars0.githubusercontent.com/u/35611074?v=4?s=100" width="100px;" alt=""/><br /><sub><b>elasticdotventures</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=elasticdotventures" title="Documentation">📖</a></td>
|
|
340
|
+
<td align="center"><a href="https://github.com/ChristianMurphy"><img src="https://avatars.githubusercontent.com/u/3107513?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christian Murphy</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Code">💻</a> <a href="#ideas-ChristianMurphy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Documentation">📖</a></td>
|
|
341
|
+
</tr>
|
|
342
|
+
</tobdy>
|
|
343
|
+
</table>
|
|
344
|
+
|
|
345
|
+
<!-- markdownlint-restore -->
|
|
346
|
+
<!-- prettier-ignore-end -->
|
|
347
|
+
|
|
348
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
349
|
+
|
|
350
|
+
このプロジェクトは、[all-contributors](https://github.com/all-contributors/all-contributors) の仕様に準拠しています。
|
|
351
|
+
|
|
352
|
+
どのような種類の貢献でも歓迎します。
|
|
353
|
+
|
|
354
|
+
## 貢献の方法 💪
|
|
355
|
+
|
|
356
|
+
一番簡単な貢献の方法は、ライブラリを使っていただくことと、 [リポジトリ](https://github.com/ts-graphviz/ts-graphviz) にスターをつけることです。
|
|
357
|
+
|
|
358
|
+
### 質問 💭
|
|
359
|
+
|
|
360
|
+
[GitHub Discussions](https://github.com/ts-graphviz/ts-graphviz/discussions) で気軽に質問してください。
|
|
361
|
+
|
|
362
|
+
### バグの報告/追加機能の要望 💡
|
|
363
|
+
|
|
364
|
+
[GitHub Issues](https://github.com/ts-graphviz/ts-graphviz/issues/new/choose) から登録してください。
|
|
365
|
+
|
|
366
|
+
### 機能開発/バグ修正 🧑💻
|
|
367
|
+
|
|
368
|
+
[CONTRIBUTING.md](https://github.com/ts-graphviz/ts-graphviz/blob/main/CONTRIBUTING.md) を参照してください。
|
|
369
|
+
|
|
370
|
+
### 金銭的支援 💸
|
|
371
|
+
|
|
372
|
+
コアメンバーの [kamiazya](https://github.com/sponsors/kamiazya) を支援してください。
|
|
373
|
+
|
|
374
|
+
> **Note** たった1ドルでも、私には十分な開発のモチベーションになります 😊
|
|
375
|
+
|
|
376
|
+
## ライセンス ⚖️
|
|
377
|
+
|
|
378
|
+
本ソフトウェアはMITライセンスのもとで公開されています。
|
|
379
|
+
[LICENSE](https://github.com/ts-graphviz/ts-graphviz/blob/main/LICENSE)を参照してください。
|