@hpcc-js/wasm-graphviz 1.22.2 → 1.24.0
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/README.md +176 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/src/graphviz.ts +696 -1
- package/src/index.ts +1 -1
- package/src/types.ts +607 -0
- package/types/graphviz.d.ts +443 -0
- package/types/graphvizlib.d.ts +63 -0
- package/types/types.d.ts +299 -0
package/types/graphviz.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
import type { MainModule, CGraph as CGraphWasm, CSubgraph as CSubgraphWasm } from "../types/graphvizlib.js";
|
|
2
|
+
import type { NodeDotAttr, NodeAttrs, EdgeDotAttr, EdgeAttrs, ClusterDotAttr, ClusterAttrs, GraphDotAttr, GraphAttrs as GraphAttrs } from "./types.ts";
|
|
1
3
|
/**
|
|
2
4
|
* Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.gitlab.io/docs/outputs/) for more information.
|
|
3
5
|
*/
|
|
4
6
|
export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
|
|
7
|
+
/**
|
|
8
|
+
* An edge returned by graph-traversal methods.
|
|
9
|
+
*/
|
|
10
|
+
export interface EdgeInfo {
|
|
11
|
+
/** The tail (source) node name. */
|
|
12
|
+
tail: string;
|
|
13
|
+
/** The head (target) node name. */
|
|
14
|
+
head: string;
|
|
15
|
+
/**
|
|
16
|
+
* The cgraph edge key that distinguishes parallel edges.
|
|
17
|
+
* Typically `""` for single (non-keyed) edges.
|
|
18
|
+
*/
|
|
19
|
+
key: string;
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.gitlab.io/docs/layouts/) for more details.
|
|
7
23
|
*/
|
|
@@ -40,6 +56,388 @@ export interface Options {
|
|
|
40
56
|
yInvert?: boolean;
|
|
41
57
|
nop?: number;
|
|
42
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The type of graph to create.
|
|
61
|
+
* - `"directed"` – directed graph (`digraph`)
|
|
62
|
+
* - `"undirected"` – undirected graph (`graph`)
|
|
63
|
+
* - `"strict directed"` – directed graph that disallows parallel edges and self-loops
|
|
64
|
+
* - `"strict undirected"` – undirected graph that disallows parallel edges and self-loops
|
|
65
|
+
*/
|
|
66
|
+
export type GraphType = "directed" | "undirected" | "strict directed" | "strict undirected";
|
|
67
|
+
/**
|
|
68
|
+
* A subgraph (or cluster) inside a {@link Graph}.
|
|
69
|
+
*
|
|
70
|
+
* Obtain via {@link Graph.addSubgraph}. All mutation methods return `this`
|
|
71
|
+
* for chaining. **Call {@link Subgraph.delete} (or use the `using` keyword)
|
|
72
|
+
* when finished** to free the underlying WASM wrapper — the actual subgraph
|
|
73
|
+
* data is owned by the parent {@link Graph} and is freed with it.
|
|
74
|
+
*
|
|
75
|
+
* Clusters are subgraphs whose name starts with `"cluster"`. Layout engines
|
|
76
|
+
* draw them as a bounded rectangle:
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* using cluster = graph.addSubgraph("cluster_0");
|
|
80
|
+
* cluster
|
|
81
|
+
* .setAttr("label", "My Cluster")
|
|
82
|
+
* .setAttr("style", "filled")
|
|
83
|
+
* .setAttr("color", "lightblue")
|
|
84
|
+
* .addEdge("a", "b");
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare class Subgraph {
|
|
88
|
+
private _sg;
|
|
89
|
+
/** @internal */
|
|
90
|
+
constructor(sg: CSubgraphWasm);
|
|
91
|
+
/**
|
|
92
|
+
* Create (or find) a node and add it to this subgraph.
|
|
93
|
+
*/
|
|
94
|
+
addNode(name: string): this;
|
|
95
|
+
/**
|
|
96
|
+
* Create an edge inside this subgraph. Both endpoints are created
|
|
97
|
+
* automatically if they do not already exist.
|
|
98
|
+
*/
|
|
99
|
+
addEdge(tail: string, head: string, key?: string): this;
|
|
100
|
+
/**
|
|
101
|
+
* Remove a node from this subgraph only. The node (and any edges
|
|
102
|
+
* connecting it) remains in the root graph and all other subgraphs.
|
|
103
|
+
* No-op if the node is not in this subgraph.
|
|
104
|
+
*/
|
|
105
|
+
removeNode(name: string): this;
|
|
106
|
+
/**
|
|
107
|
+
* Remove a single edge from this subgraph only. The edge remains in the
|
|
108
|
+
* root graph and all other subgraphs. No-op if the edge is not present.
|
|
109
|
+
*/
|
|
110
|
+
removeEdge(tail: string, head: string, key?: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set an attribute on the subgraph itself (e.g. `"label"`, `"style"`,
|
|
113
|
+
* `"color"`, `"bgcolor"`).
|
|
114
|
+
*
|
|
115
|
+
* When `attr` is a known cluster attribute the value type is inferred
|
|
116
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
117
|
+
* provided for custom or less-common attributes.
|
|
118
|
+
*/
|
|
119
|
+
setAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>): this;
|
|
120
|
+
setAttr(attr: string, value: string | number | boolean): this;
|
|
121
|
+
/**
|
|
122
|
+
* Clear a subgraph-level attribute by resetting it to its default (empty)
|
|
123
|
+
* value. Equivalent to `setAttr(attr, "")`.
|
|
124
|
+
*/
|
|
125
|
+
removeAttr(attr: string): this;
|
|
126
|
+
/**
|
|
127
|
+
* Set an attribute on a node inside this subgraph.
|
|
128
|
+
*
|
|
129
|
+
* When `attr` is a known node attribute the value type is inferred
|
|
130
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
131
|
+
* provided for custom attributes.
|
|
132
|
+
*/
|
|
133
|
+
setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
134
|
+
setNodeAttr(node: string, attr: string, value: string | number | boolean): this;
|
|
135
|
+
/**
|
|
136
|
+
* Clear a node attribute inside this subgraph by resetting it to its
|
|
137
|
+
* default (empty) value. Equivalent to `setNodeAttr(node, attr, "")`.
|
|
138
|
+
*/
|
|
139
|
+
removeNodeAttr(node: string, attr: string): this;
|
|
140
|
+
/**
|
|
141
|
+
* Set an attribute on an edge inside this subgraph (identified by
|
|
142
|
+
* `tail`, `head`, and `key`).
|
|
143
|
+
*
|
|
144
|
+
* When `attr` is a known edge attribute the value type is inferred
|
|
145
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
146
|
+
* provided for custom attributes.
|
|
147
|
+
*/
|
|
148
|
+
setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
149
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean): this;
|
|
150
|
+
/**
|
|
151
|
+
* Clear an edge attribute inside this subgraph by resetting it to its
|
|
152
|
+
* default (empty) value. Equivalent to `setEdgeAttr(tail, head, key, attr, "")`.
|
|
153
|
+
*/
|
|
154
|
+
removeEdgeAttr(tail: string, head: string, key: string, attr: string): this;
|
|
155
|
+
/**
|
|
156
|
+
* Returns `true` if a node with the given name exists in this subgraph.
|
|
157
|
+
*/
|
|
158
|
+
hasNode(name: string): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Returns `true` if an edge from `tail` to `head` exists in this subgraph.
|
|
161
|
+
* Pass `key` to check for a specific parallel edge; omit (or pass `""`) to
|
|
162
|
+
* check for any edge between the two nodes.
|
|
163
|
+
*/
|
|
164
|
+
hasEdge(tail: string, head: string, key?: string): boolean;
|
|
165
|
+
/** Returns the number of nodes in this subgraph. */
|
|
166
|
+
nodeCount(): number;
|
|
167
|
+
/** Returns the number of edges in this subgraph. */
|
|
168
|
+
edgeCount(): number;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the current value of a subgraph-level attribute, or `""` if
|
|
171
|
+
* the attribute has not been set.
|
|
172
|
+
*/
|
|
173
|
+
getAttr(attr: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* Returns the current value of the named attribute on a node in this
|
|
176
|
+
* subgraph, or `""` if the node or attribute does not exist.
|
|
177
|
+
*/
|
|
178
|
+
getNodeAttr(node: string, attr: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the current value of the named attribute on an edge in this
|
|
181
|
+
* subgraph, or `""` if the edge or attribute does not exist.
|
|
182
|
+
* Pass `key = ""` for the first (or only) edge between `tail` and `head`.
|
|
183
|
+
*/
|
|
184
|
+
getEdgeAttr(tail: string, head: string, key: string, attr: string): string;
|
|
185
|
+
/**
|
|
186
|
+
* Returns the names of all nodes in this subgraph (in internal iteration
|
|
187
|
+
* order).
|
|
188
|
+
*/
|
|
189
|
+
nodeNames(): string[];
|
|
190
|
+
/**
|
|
191
|
+
* Returns all edges in this subgraph. Each unique edge is listed exactly
|
|
192
|
+
* once.
|
|
193
|
+
*/
|
|
194
|
+
edges(): EdgeInfo[];
|
|
195
|
+
/**
|
|
196
|
+
* Returns the out-edges of the named node in this subgraph. Returns `[]`
|
|
197
|
+
* if the node does not exist.
|
|
198
|
+
*/
|
|
199
|
+
outEdges(node: string): EdgeInfo[];
|
|
200
|
+
/**
|
|
201
|
+
* Returns the in-edges of the named node in this subgraph. Returns `[]`
|
|
202
|
+
* if the node does not exist.
|
|
203
|
+
*/
|
|
204
|
+
inEdges(node: string): EdgeInfo[];
|
|
205
|
+
/**
|
|
206
|
+
* Returns all edges incident to the named node in this subgraph (both in
|
|
207
|
+
* and out). Returns `[]` if the node does not exist.
|
|
208
|
+
*/
|
|
209
|
+
nodeEdges(node: string): EdgeInfo[];
|
|
210
|
+
/**
|
|
211
|
+
* Release the WASM wrapper. The subgraph data itself is freed when the
|
|
212
|
+
* parent {@link Graph} is deleted.
|
|
213
|
+
*/
|
|
214
|
+
delete(): void;
|
|
215
|
+
/** @internal – supports the `using` keyword (explicit resource management). */
|
|
216
|
+
[Symbol.dispose](): void;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A programmatic graph builder backed by the cgraph library.
|
|
220
|
+
*
|
|
221
|
+
* Obtain an instance via {@link Graphviz.createGraph} and call
|
|
222
|
+
* {@link Graph.toDot} to serialise to a DOT string that can be passed to
|
|
223
|
+
* {@link Graphviz.layout} (or any of its convenience wrappers).
|
|
224
|
+
*
|
|
225
|
+
* **Always call {@link Graph.delete} (or use the `using` keyword) when
|
|
226
|
+
* finished** to release the underlying WASM memory.
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* const graphviz = await Graphviz.load();
|
|
230
|
+
*
|
|
231
|
+
* using graph = graphviz.createGraph("G");
|
|
232
|
+
* graph.addNode("a");
|
|
233
|
+
* graph.addNode("b");
|
|
234
|
+
* graph.addEdge("a", "b");
|
|
235
|
+
* graph.setNodeAttr("a", "color", "red");
|
|
236
|
+
* graph.setEdgeAttr("a", "b", "", "label", "hello");
|
|
237
|
+
* graph.setGraphAttr("rankdir", "LR");
|
|
238
|
+
*
|
|
239
|
+
* const svg = graphviz.dot(graph.toDot());
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare class Graph {
|
|
243
|
+
private _graph;
|
|
244
|
+
private _module;
|
|
245
|
+
/** @internal */
|
|
246
|
+
constructor(g: CGraphWasm, module: MainModule);
|
|
247
|
+
/**
|
|
248
|
+
* Create a node. If a node with this name already exists it is returned
|
|
249
|
+
* unchanged.
|
|
250
|
+
*/
|
|
251
|
+
addNode(name: string): this;
|
|
252
|
+
/**
|
|
253
|
+
* Create an edge from `tail` to `head`. Both nodes are created
|
|
254
|
+
* automatically if they do not already exist. `key` distinguishes
|
|
255
|
+
* parallel edges between the same pair of nodes; omit (or pass `""`) for
|
|
256
|
+
* an anonymous edge.
|
|
257
|
+
*/
|
|
258
|
+
addEdge(tail: string, head: string, key?: string): this;
|
|
259
|
+
/**
|
|
260
|
+
* Set a graph-level attribute (e.g. `"rankdir"`, `"label"`, `"bgcolor"`).
|
|
261
|
+
*
|
|
262
|
+
* When `attr` is a known graph attribute the value type is inferred
|
|
263
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
264
|
+
* provided for custom or less-common attributes.
|
|
265
|
+
*/
|
|
266
|
+
setGraphAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>): this;
|
|
267
|
+
setGraphAttr(attr: string, value: string | number | boolean): this;
|
|
268
|
+
/**
|
|
269
|
+
* Set an attribute on a named node (e.g. `"color"`, `"label"`, `"shape"`).
|
|
270
|
+
* The node must exist; call {@link addNode} first if needed.
|
|
271
|
+
*
|
|
272
|
+
* When `attr` is a known node attribute the value type is inferred
|
|
273
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
274
|
+
* provided for custom attributes.
|
|
275
|
+
*/
|
|
276
|
+
setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
277
|
+
setNodeAttr(node: string, attr: string, value: string | number | boolean): this;
|
|
278
|
+
/**
|
|
279
|
+
* Set an attribute on an edge identified by `(tail, head, key)`.
|
|
280
|
+
* Use the same `key` that was passed to {@link addEdge}; pass `""` for
|
|
281
|
+
* anonymous edges.
|
|
282
|
+
*
|
|
283
|
+
* When `attr` is a known edge attribute the value type is inferred
|
|
284
|
+
* automatically. A generic `string | number | boolean` fallback is
|
|
285
|
+
* provided for custom attributes.
|
|
286
|
+
*/
|
|
287
|
+
setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
288
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean): this;
|
|
289
|
+
/**
|
|
290
|
+
* Remove a node and all its edges from the graph. Removing from the root
|
|
291
|
+
* graph also removes the node from every subgraph.
|
|
292
|
+
* No-op if the node does not exist.
|
|
293
|
+
*/
|
|
294
|
+
removeNode(name: string): this;
|
|
295
|
+
/**
|
|
296
|
+
* Remove a single edge identified by `(tail, head, key)`.
|
|
297
|
+
* Pass `""` for `key` on anonymous edges.
|
|
298
|
+
* No-op if the edge does not exist.
|
|
299
|
+
*/
|
|
300
|
+
removeEdge(tail: string, head: string, key?: string): this;
|
|
301
|
+
/**
|
|
302
|
+
* Dissolve a subgraph / cluster boundary. Nodes and edges that belonged
|
|
303
|
+
* to the subgraph remain in the parent graph.
|
|
304
|
+
* No-op if no subgraph with that name exists.
|
|
305
|
+
*/
|
|
306
|
+
removeSubgraph(name: string): this;
|
|
307
|
+
/**
|
|
308
|
+
* Clear a graph-level attribute by resetting it to its default (empty)
|
|
309
|
+
* value. Equivalent to `setGraphAttr(attr, "")`.
|
|
310
|
+
*/
|
|
311
|
+
removeGraphAttr(attr: string): this;
|
|
312
|
+
/**
|
|
313
|
+
* Clear a node attribute by resetting it to its default (empty) value.
|
|
314
|
+
* Equivalent to `setNodeAttr(node, attr, "")`.
|
|
315
|
+
*/
|
|
316
|
+
removeNodeAttr(node: string, attr: string): this;
|
|
317
|
+
/**
|
|
318
|
+
* Clear an edge attribute by resetting it to its default (empty) value.
|
|
319
|
+
* Equivalent to `setEdgeAttr(tail, head, key, attr, "")`.
|
|
320
|
+
*/
|
|
321
|
+
removeEdgeAttr(tail: string, head: string, key: string, attr: string): this;
|
|
322
|
+
/**
|
|
323
|
+
* Returns `true` if a node with the given name exists in the graph.
|
|
324
|
+
*/
|
|
325
|
+
hasNode(name: string): boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Returns `true` if an edge from `tail` to `head` exists in the graph.
|
|
328
|
+
* Pass `key` to check for a specific parallel edge; omit (or pass `""`) to
|
|
329
|
+
* check for any edge between the two nodes.
|
|
330
|
+
*/
|
|
331
|
+
hasEdge(tail: string, head: string, key?: string): boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Returns `true` if a subgraph with the given name exists.
|
|
334
|
+
*/
|
|
335
|
+
hasSubgraph(name: string): boolean;
|
|
336
|
+
/** Returns the number of nodes in the graph. */
|
|
337
|
+
nodeCount(): number;
|
|
338
|
+
/** Returns the number of edges in the graph. */
|
|
339
|
+
edgeCount(): number;
|
|
340
|
+
/** Returns the number of direct subgraphs of this graph. */
|
|
341
|
+
subgraphCount(): number;
|
|
342
|
+
/**
|
|
343
|
+
* Returns the current value of a graph-level attribute, or `""` if the
|
|
344
|
+
* attribute has not been set.
|
|
345
|
+
*/
|
|
346
|
+
getGraphAttr(attr: string): string;
|
|
347
|
+
/**
|
|
348
|
+
* Returns the current value of the named attribute on a node, or `""` if
|
|
349
|
+
* the node or attribute does not exist.
|
|
350
|
+
*/
|
|
351
|
+
getNodeAttr(node: string, attr: string): string;
|
|
352
|
+
/**
|
|
353
|
+
* Returns the current value of the named attribute on an edge, or `""` if
|
|
354
|
+
* the edge or attribute does not exist.
|
|
355
|
+
* Pass `key = ""` for the first (or only) edge between `tail` and `head`.
|
|
356
|
+
*/
|
|
357
|
+
getEdgeAttr(tail: string, head: string, key: string, attr: string): string;
|
|
358
|
+
/**
|
|
359
|
+
* Returns the names of all nodes in the graph (in internal iteration
|
|
360
|
+
* order).
|
|
361
|
+
*/
|
|
362
|
+
nodeNames(): string[];
|
|
363
|
+
/**
|
|
364
|
+
* Returns the names of all direct subgraphs.
|
|
365
|
+
*/
|
|
366
|
+
subgraphNames(): string[];
|
|
367
|
+
/**
|
|
368
|
+
* Returns all edges in the graph. Each unique edge is listed exactly
|
|
369
|
+
* once.
|
|
370
|
+
*/
|
|
371
|
+
edges(): EdgeInfo[];
|
|
372
|
+
/**
|
|
373
|
+
* Returns the out-edges of the named node. Returns `[]` if the node does
|
|
374
|
+
* not exist.
|
|
375
|
+
*/
|
|
376
|
+
outEdges(node: string): EdgeInfo[];
|
|
377
|
+
/**
|
|
378
|
+
* Returns the in-edges of the named node. Returns `[]` if the node does
|
|
379
|
+
* not exist.
|
|
380
|
+
*/
|
|
381
|
+
inEdges(node: string): EdgeInfo[];
|
|
382
|
+
/**
|
|
383
|
+
* Returns all edges incident to the named node (both in and out).
|
|
384
|
+
* Returns `[]` if the node does not exist.
|
|
385
|
+
*/
|
|
386
|
+
nodeEdges(node: string): EdgeInfo[];
|
|
387
|
+
/**
|
|
388
|
+
* Create (or return an existing) named subgraph. Use a name beginning
|
|
389
|
+
* with `"cluster"` to have layout engines render it as a bounded cluster.
|
|
390
|
+
*
|
|
391
|
+
* Returns a {@link Subgraph} wrapper. **Call {@link Subgraph.delete} (or
|
|
392
|
+
* use the `using` keyword) when finished** to free the WASM wrapper. The
|
|
393
|
+
* subgraph data itself is owned by this graph.
|
|
394
|
+
*
|
|
395
|
+
* ```ts
|
|
396
|
+
* using cluster = graph.addSubgraph("cluster_0");
|
|
397
|
+
* cluster.setAttr("label", "My Cluster").addEdge("a", "b");
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
addSubgraph(name: string): Subgraph;
|
|
401
|
+
/**
|
|
402
|
+
* Look up an existing subgraph by name without creating a new one.
|
|
403
|
+
* Returns a {@link Subgraph} wrapper if a subgraph with that name exists,
|
|
404
|
+
* or `null` if it does not. **Call {@link Subgraph.delete} (or use the
|
|
405
|
+
* `using` keyword) when finished** to free the WASM wrapper.
|
|
406
|
+
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* using sg = graph.getSubgraph("cluster_0");
|
|
409
|
+
* if (sg) {
|
|
410
|
+
* console.log(sg.nodeNames());
|
|
411
|
+
* }
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
getSubgraph(name: string): Subgraph | null;
|
|
415
|
+
/**
|
|
416
|
+
* Render the graph directly to the specified format without first
|
|
417
|
+
* serialising to DOT. Equivalent to:
|
|
418
|
+
* ```ts
|
|
419
|
+
* graphviz.layout(graph.toDot(), outputFormat, layoutEngine, options)
|
|
420
|
+
* ```
|
|
421
|
+
* but avoids the DOT round-trip.
|
|
422
|
+
*
|
|
423
|
+
* @param outputFormat The output format (default `"svg"`).
|
|
424
|
+
* @param layoutEngine The layout engine to use (default `"dot"`).
|
|
425
|
+
* @param options Optional images / extra files for the renderer.
|
|
426
|
+
* @returns The rendered output as a string.
|
|
427
|
+
*/
|
|
428
|
+
layout(outputFormat?: Format, layoutEngine?: Engine, options?: Options): string;
|
|
429
|
+
/**
|
|
430
|
+
* Serialise the graph to a DOT-language string.
|
|
431
|
+
*/
|
|
432
|
+
toDot(): string;
|
|
433
|
+
/**
|
|
434
|
+
* Release the underlying WASM object. Must be called when the graph is
|
|
435
|
+
* no longer needed (or use the `using` keyword with TypeScript ≥ 5.2).
|
|
436
|
+
*/
|
|
437
|
+
delete(): void;
|
|
438
|
+
/** @internal – supports the `using` keyword (explicit resource management). */
|
|
439
|
+
[Symbol.dispose](): void;
|
|
440
|
+
}
|
|
43
441
|
/**
|
|
44
442
|
* The Graphviz layout algorithms take descriptions of graphs in a simple text language, and make diagrams in useful formats, such as images and SVG for web pages or display in an interactive graph browser.
|
|
45
443
|
*
|
|
@@ -47,6 +445,7 @@ export interface Options {
|
|
|
47
445
|
*
|
|
48
446
|
* See [graphviz.org](https://graphviz.org/) for more details.
|
|
49
447
|
*
|
|
448
|
+
* ### Rendering from a DOT string
|
|
50
449
|
* ```ts
|
|
51
450
|
* import { Graphviz } from "@hpcc-js/wasm/graphviz";
|
|
52
451
|
*
|
|
@@ -56,6 +455,23 @@ export interface Options {
|
|
|
56
455
|
* const svg = graphviz.dot(dot);
|
|
57
456
|
* ```
|
|
58
457
|
*
|
|
458
|
+
* ### Programmatic graph construction
|
|
459
|
+
* ```ts
|
|
460
|
+
* import { Graphviz } from "@hpcc-js/wasm/graphviz";
|
|
461
|
+
*
|
|
462
|
+
* const graphviz = await Graphviz.load();
|
|
463
|
+
*
|
|
464
|
+
* using graph = graphviz.createGraph("G");
|
|
465
|
+
* graph
|
|
466
|
+
* .addNode("a")
|
|
467
|
+
* .addNode("b")
|
|
468
|
+
* .addEdge("a", "b")
|
|
469
|
+
* .setNodeAttr("a", "color", "red")
|
|
470
|
+
* .setGraphAttr("rankdir", "LR");
|
|
471
|
+
*
|
|
472
|
+
* const svg = graph.layout(); // render without a DOT round-trip
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
59
475
|
* ### Online Demos
|
|
60
476
|
* * https://raw.githack.com/hpcc-systems/hpcc-js-wasm/main/index.html
|
|
61
477
|
* * https://observablehq.com/@gordonsmith/graphviz
|
|
@@ -212,4 +628,31 @@ export declare class Graphviz {
|
|
|
212
628
|
* @returns A string containing the "pretty printed" dotSource.
|
|
213
629
|
*/
|
|
214
630
|
nop2(dotSource: string): string;
|
|
631
|
+
/**
|
|
632
|
+
* Programmatically create a graph using the cgraph library.
|
|
633
|
+
*
|
|
634
|
+
* Returns a {@link Graph} builder that lets you add nodes, edges, and
|
|
635
|
+
* attributes without writing DOT source by hand. Call
|
|
636
|
+
* {@link Graph.toDot} to get the DOT string and pass it to
|
|
637
|
+
* {@link layout} (or any convenience wrapper).
|
|
638
|
+
*
|
|
639
|
+
* **You must call {@link Graph.delete} when finished** to free the
|
|
640
|
+
* underlying WASM memory, or use the `using` keyword (TypeScript ≥ 5.2).
|
|
641
|
+
*
|
|
642
|
+
* @param name The graph name (default `"G"`).
|
|
643
|
+
* @param type The graph type (default `"directed"`).
|
|
644
|
+
*
|
|
645
|
+
* ```ts
|
|
646
|
+
* using graph = graphviz.createGraph("G");
|
|
647
|
+
* graph
|
|
648
|
+
* .addNode("a")
|
|
649
|
+
* .addNode("b")
|
|
650
|
+
* .addEdge("a", "b")
|
|
651
|
+
* .setNodeAttr("a", "color", "red")
|
|
652
|
+
* .setGraphAttr("rankdir", "LR");
|
|
653
|
+
*
|
|
654
|
+
* const svg = graphviz.dot(graph.toDot());
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
createGraph(name?: string, type?: GraphType): Graph;
|
|
215
658
|
}
|
package/types/graphvizlib.d.ts
CHANGED
|
@@ -52,6 +52,62 @@ export interface CGraphviz extends ClassHandle {
|
|
|
52
52
|
unflatten(_0: EmbindString, _1: number, _2: boolean, _3: number): string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export interface CGraph extends ClassHandle {
|
|
56
|
+
get dot_out(): string;
|
|
57
|
+
set dot_out(value: EmbindString);
|
|
58
|
+
get layout_result(): string;
|
|
59
|
+
set layout_result(value: EmbindString);
|
|
60
|
+
nodeCount(): number;
|
|
61
|
+
edgeCount(): number;
|
|
62
|
+
subgraphCount(): number;
|
|
63
|
+
addNode(_0: EmbindString): void;
|
|
64
|
+
addEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
65
|
+
setGraphAttr(_0: EmbindString, _1: EmbindString): void;
|
|
66
|
+
setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
67
|
+
setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
|
|
68
|
+
addSubgraph(_0: EmbindString): CSubgraph | null;
|
|
69
|
+
getSubgraph(_0: EmbindString): CSubgraph | null;
|
|
70
|
+
removeNode(_0: EmbindString): void;
|
|
71
|
+
removeEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
72
|
+
removeSubgraph(_0: EmbindString): void;
|
|
73
|
+
hasNode(_0: EmbindString): boolean;
|
|
74
|
+
hasEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): boolean;
|
|
75
|
+
hasSubgraph(_0: EmbindString): boolean;
|
|
76
|
+
getGraphAttr(_0: EmbindString): string;
|
|
77
|
+
getNodeAttr(_0: EmbindString, _1: EmbindString): string;
|
|
78
|
+
getEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): string;
|
|
79
|
+
nodeNames(): string;
|
|
80
|
+
subgraphNames(): string;
|
|
81
|
+
edges(): string;
|
|
82
|
+
outEdges(_0: EmbindString): string;
|
|
83
|
+
inEdges(_0: EmbindString): string;
|
|
84
|
+
nodeEdges(_0: EmbindString): string;
|
|
85
|
+
toDot(): string;
|
|
86
|
+
layout(_0: EmbindString, _1: EmbindString): string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface CSubgraph extends ClassHandle {
|
|
90
|
+
nodeCount(): number;
|
|
91
|
+
edgeCount(): number;
|
|
92
|
+
addNode(_0: EmbindString): void;
|
|
93
|
+
addEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
94
|
+
setAttr(_0: EmbindString, _1: EmbindString): void;
|
|
95
|
+
setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
96
|
+
setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
|
|
97
|
+
removeNode(_0: EmbindString): void;
|
|
98
|
+
removeEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
|
|
99
|
+
hasNode(_0: EmbindString): boolean;
|
|
100
|
+
hasEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): boolean;
|
|
101
|
+
getAttr(_0: EmbindString): string;
|
|
102
|
+
getNodeAttr(_0: EmbindString, _1: EmbindString): string;
|
|
103
|
+
getEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): string;
|
|
104
|
+
nodeNames(): string;
|
|
105
|
+
edges(): string;
|
|
106
|
+
outEdges(_0: EmbindString): string;
|
|
107
|
+
inEdges(_0: EmbindString): string;
|
|
108
|
+
nodeEdges(_0: EmbindString): string;
|
|
109
|
+
}
|
|
110
|
+
|
|
55
111
|
interface EmbindModule {
|
|
56
112
|
CGraphviz: {
|
|
57
113
|
new(): CGraphviz;
|
|
@@ -59,6 +115,13 @@ interface EmbindModule {
|
|
|
59
115
|
version(): string;
|
|
60
116
|
lastError(): string;
|
|
61
117
|
};
|
|
118
|
+
CGraph: {
|
|
119
|
+
new(): CGraph;
|
|
120
|
+
new(_0: EmbindString): CGraph;
|
|
121
|
+
new(_0: EmbindString, _1: number): CGraph;
|
|
122
|
+
new(_0: EmbindString, _1: number, _2: number): CGraph;
|
|
123
|
+
};
|
|
124
|
+
CSubgraph: {};
|
|
62
125
|
}
|
|
63
126
|
|
|
64
127
|
export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
|