@hpcc-js/wasm-graphviz 1.22.2 → 1.24.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.
@@ -1,9 +1,25 @@
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
- * 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.
4
+ * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/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";
5
7
  /**
6
- * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.gitlab.io/docs/layouts/) for more details.
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
+ }
21
+ /**
22
+ * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
7
23
  */
8
24
  export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
9
25
  /**
@@ -40,6 +56,455 @@ 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"`). See the official Graphviz
114
+ * [attribute reference](https://graphviz.org/docs/attrs/) for supported
115
+ * attributes and values.
116
+ *
117
+ * When `attr` is a known cluster attribute the value type is inferred
118
+ * automatically. A generic `string | number | boolean` fallback is
119
+ * provided for custom or less-common attributes. Omit `value` to reset
120
+ * the attribute to Graphviz's default empty value. `defaultValue` is
121
+ * passed to Graphviz as the default for this attribute if it has not
122
+ * already been declared.
123
+ */
124
+ setAttr<K extends ClusterDotAttr>(attr: K, value?: NonNullable<ClusterAttrs[K]>, defaultValue?: string | number | boolean): this;
125
+ setAttr(attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
126
+ setHtmlAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>, defaultValue?: string | number | boolean): this;
127
+ setHtmlAttr(attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
128
+ setDefaultAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>): this;
129
+ setDefaultAttr(attr: string, value: string | number | boolean): this;
130
+ setDefaultHtmlAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>): this;
131
+ setDefaultHtmlAttr(attr: string, value: string | number | boolean): this;
132
+ /**
133
+ * Clear a subgraph-level attribute by resetting it to its default (empty)
134
+ * value. Equivalent to `setAttr(attr, "")`.
135
+ */
136
+ removeAttr(attr: string): this;
137
+ /**
138
+ * Set an attribute on a node inside this subgraph.
139
+ *
140
+ * When `attr` is a known node attribute the value type is inferred
141
+ * automatically. A generic `string | number | boolean` fallback is
142
+ * provided for custom attributes. Omit `value` to reset the attribute to
143
+ * Graphviz's default empty value. `defaultValue` is passed to Graphviz as
144
+ * the default for this attribute if it has not already been declared.
145
+ */
146
+ setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value?: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
147
+ setNodeAttr(node: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
148
+ setNodeHtmlAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
149
+ setNodeHtmlAttr(node: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
150
+ setDefaultNodeAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
151
+ setDefaultNodeAttr(attr: string, value: string | number | boolean): this;
152
+ setDefaultNodeHtmlAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
153
+ setDefaultNodeHtmlAttr(attr: string, value: string | number | boolean): this;
154
+ /**
155
+ * Clear a node attribute inside this subgraph by resetting it to its
156
+ * default (empty) value. Equivalent to `setNodeAttr(node, attr, "")`.
157
+ */
158
+ removeNodeAttr(node: string, attr: string): this;
159
+ /**
160
+ * Set an attribute on an edge inside this subgraph (identified by
161
+ * `tail`, `head`, and `key`).
162
+ *
163
+ * When `attr` is a known edge attribute the value type is inferred
164
+ * automatically. A generic `string | number | boolean` fallback is
165
+ * provided for custom attributes. Omit `value` to reset the attribute to
166
+ * Graphviz's default empty value. `defaultValue` is passed to Graphviz as
167
+ * the default for this attribute if it has not already been declared.
168
+ */
169
+ setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value?: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
170
+ setEdgeAttr(tail: string, head: string, key: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
171
+ setEdgeHtmlAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
172
+ setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
173
+ setDefaultEdgeAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
174
+ setDefaultEdgeAttr(attr: string, value: string | number | boolean): this;
175
+ setDefaultEdgeHtmlAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
176
+ setDefaultEdgeHtmlAttr(attr: string, value: string | number | boolean): this;
177
+ /**
178
+ * Clear an edge attribute inside this subgraph by resetting it to its
179
+ * default (empty) value. Equivalent to `setEdgeAttr(tail, head, key, attr, "")`.
180
+ */
181
+ removeEdgeAttr(tail: string, head: string, key: string, attr: string): this;
182
+ /**
183
+ * Returns `true` if a node with the given name exists in this subgraph.
184
+ */
185
+ hasNode(name: string): boolean;
186
+ /**
187
+ * Returns `true` if an edge from `tail` to `head` exists in this subgraph.
188
+ * Pass `key` to check for a specific parallel edge; omit (or pass `""`) to
189
+ * check for any edge between the two nodes.
190
+ */
191
+ hasEdge(tail: string, head: string, key?: string): boolean;
192
+ /** Returns the number of nodes in this subgraph. */
193
+ nodeCount(): number;
194
+ /** Returns the number of edges in this subgraph. */
195
+ edgeCount(): number;
196
+ /** Returns the degree of a named node in this subgraph. */
197
+ nodeDegree(node: string, inDegree?: number, outDegree?: number): number;
198
+ /**
199
+ * Returns the current value of a subgraph-level attribute, or `""` if
200
+ * the attribute has not been set.
201
+ */
202
+ getAttr(attr: string): string;
203
+ /**
204
+ * Returns the current value of the named attribute on a node in this
205
+ * subgraph, or `""` if the node or attribute does not exist.
206
+ */
207
+ getNodeAttr(node: string, attr: string): string;
208
+ /**
209
+ * Returns the current value of the named attribute on an edge in this
210
+ * subgraph, or `""` if the edge or attribute does not exist.
211
+ * Pass `key = ""` for the first (or only) edge between `tail` and `head`.
212
+ */
213
+ getEdgeAttr(tail: string, head: string, key: string, attr: string): string;
214
+ /**
215
+ * Returns the names of all nodes in this subgraph (in internal iteration
216
+ * order).
217
+ */
218
+ nodeNames(): string[];
219
+ /**
220
+ * Returns all edges in this subgraph. Each unique edge is listed exactly
221
+ * once.
222
+ */
223
+ edges(): EdgeInfo[];
224
+ /**
225
+ * Returns the out-edges of the named node in this subgraph. Returns `[]`
226
+ * if the node does not exist.
227
+ */
228
+ outEdges(node: string): EdgeInfo[];
229
+ /**
230
+ * Returns the in-edges of the named node in this subgraph. Returns `[]`
231
+ * if the node does not exist.
232
+ */
233
+ inEdges(node: string): EdgeInfo[];
234
+ /**
235
+ * Returns all edges incident to the named node in this subgraph (both in
236
+ * and out). Returns `[]` if the node does not exist.
237
+ */
238
+ nodeEdges(node: string): EdgeInfo[];
239
+ /**
240
+ * Release the WASM wrapper. The subgraph data itself is freed when the
241
+ * parent {@link Graph} is deleted.
242
+ */
243
+ delete(): void;
244
+ /** @internal – supports the `using` keyword (explicit resource management). */
245
+ [Symbol.dispose](): void;
246
+ }
247
+ /**
248
+ * A programmatic graph builder backed by the cgraph library.
249
+ *
250
+ * Obtain an instance via {@link Graphviz.createGraph} and call
251
+ * {@link Graph.toDot} to serialise to a DOT string that can be passed to
252
+ * {@link Graphviz.layout} (or any of its convenience wrappers).
253
+ *
254
+ * **Always call {@link Graph.delete} (or use the `using` keyword) when
255
+ * finished** to release the underlying WASM memory.
256
+ *
257
+ * ```ts
258
+ * const graphviz = await Graphviz.load();
259
+ *
260
+ * using graph = graphviz.createGraph("G");
261
+ * graph.addNode("a");
262
+ * graph.addNode("b");
263
+ * graph.addEdge("a", "b");
264
+ * graph.setNodeAttr("a", "color", "red");
265
+ * graph.setEdgeAttr("a", "b", "", "label", "hello");
266
+ * graph.setGraphAttr("rankdir", "LR");
267
+ *
268
+ * const svg = graphviz.dot(graph.toDot());
269
+ * ```
270
+ */
271
+ export declare class Graph {
272
+ private _graph;
273
+ private _module;
274
+ /** @internal */
275
+ constructor(g: CGraphWasm, module: MainModule);
276
+ /**
277
+ * Create a node. If a node with this name already exists it is returned
278
+ * unchanged.
279
+ */
280
+ addNode(name: string): this;
281
+ /**
282
+ * Create an edge from `tail` to `head`. Both nodes are created
283
+ * automatically if they do not already exist. `key` distinguishes
284
+ * parallel edges between the same pair of nodes; omit (or pass `""`) for
285
+ * an anonymous edge.
286
+ */
287
+ addEdge(tail: string, head: string, key?: string): this;
288
+ /**
289
+ * Replace this graph with one parsed from DOT source using Graphviz cgraph
290
+ * reading support.
291
+ */
292
+ read(dotSource: string): this;
293
+ /**
294
+ * Set a graph-level attribute (e.g. `"rankdir"`, `"label"`, `"bgcolor"`).
295
+ * See the official Graphviz [attribute reference](https://graphviz.org/docs/attrs/)
296
+ * for supported attributes and values.
297
+ *
298
+ * When `attr` is a known graph attribute the value type is inferred
299
+ * automatically. A generic `string | number | boolean` fallback is
300
+ * provided for custom or less-common attributes. Omit `value` to reset
301
+ * the attribute to Graphviz's default empty value. `defaultValue` is
302
+ * passed to Graphviz as the default for this attribute if it has not
303
+ * already been declared.
304
+ */
305
+ setGraphAttr<K extends GraphDotAttr>(attr: K, value?: NonNullable<GraphAttrs[K]>, defaultValue?: string | number | boolean): this;
306
+ setGraphAttr(attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
307
+ setGraphHtmlAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>, defaultValue?: string | number | boolean): this;
308
+ setGraphHtmlAttr(attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
309
+ setDefaultGraphAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>): this;
310
+ setDefaultGraphAttr(attr: string, value: string | number | boolean): this;
311
+ setDefaultGraphHtmlAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>): this;
312
+ setDefaultGraphHtmlAttr(attr: string, value: string | number | boolean): this;
313
+ /**
314
+ * Set an attribute on a named node (e.g. `"color"`, `"label"`, `"shape"`).
315
+ * The node must exist; call {@link addNode} first if needed.
316
+ *
317
+ * When `attr` is a known node attribute the value type is inferred
318
+ * automatically. A generic `string | number | boolean` fallback is
319
+ * provided for custom attributes. Omit `value` to reset the attribute to
320
+ * Graphviz's default empty value. `defaultValue` is passed to Graphviz as
321
+ * the default for this attribute if it has not already been declared.
322
+ */
323
+ setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value?: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
324
+ setNodeAttr(node: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
325
+ setNodeHtmlAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
326
+ setNodeHtmlAttr(node: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
327
+ setDefaultNodeAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
328
+ setDefaultNodeAttr(attr: string, value: string | number | boolean): this;
329
+ setDefaultNodeHtmlAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
330
+ setDefaultNodeHtmlAttr(attr: string, value: string | number | boolean): this;
331
+ /**
332
+ * Set an attribute on an edge identified by `(tail, head, key)`.
333
+ * Use the same `key` that was passed to {@link addEdge}; pass `""` for
334
+ * anonymous edges.
335
+ *
336
+ * When `attr` is a known edge attribute the value type is inferred
337
+ * automatically. A generic `string | number | boolean` fallback is
338
+ * provided for custom attributes. Omit `value` to reset the attribute to
339
+ * Graphviz's default empty value. `defaultValue` is passed to Graphviz as
340
+ * the default for this attribute if it has not already been declared.
341
+ */
342
+ setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value?: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
343
+ setEdgeAttr(tail: string, head: string, key: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
344
+ setEdgeHtmlAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
345
+ setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
346
+ setDefaultEdgeAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
347
+ setDefaultEdgeAttr(attr: string, value: string | number | boolean): this;
348
+ setDefaultEdgeHtmlAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
349
+ setDefaultEdgeHtmlAttr(attr: string, value: string | number | boolean): this;
350
+ /**
351
+ * Remove a node and all its edges from the graph. Removing from the root
352
+ * graph also removes the node from every subgraph.
353
+ * No-op if the node does not exist.
354
+ */
355
+ removeNode(name: string): this;
356
+ /**
357
+ * Remove a single edge identified by `(tail, head, key)`.
358
+ * Pass `""` for `key` on anonymous edges.
359
+ * No-op if the edge does not exist.
360
+ */
361
+ removeEdge(tail: string, head: string, key?: string): this;
362
+ /**
363
+ * Dissolve a subgraph / cluster boundary. Nodes and edges that belonged
364
+ * to the subgraph remain in the parent graph.
365
+ * No-op if no subgraph with that name exists.
366
+ */
367
+ removeSubgraph(name: string): this;
368
+ /**
369
+ * Clear a graph-level attribute by resetting it to its default (empty)
370
+ * value. Equivalent to `setGraphAttr(attr, "")`.
371
+ */
372
+ removeGraphAttr(attr: string): this;
373
+ /**
374
+ * Clear a node attribute by resetting it to its default (empty) value.
375
+ * Equivalent to `setNodeAttr(node, attr, "")`.
376
+ */
377
+ removeNodeAttr(node: string, attr: string): this;
378
+ /**
379
+ * Clear an edge attribute by resetting it to its default (empty) value.
380
+ * Equivalent to `setEdgeAttr(tail, head, key, attr, "")`.
381
+ */
382
+ removeEdgeAttr(tail: string, head: string, key: string, attr: string): this;
383
+ /**
384
+ * Returns `true` if a node with the given name exists in the graph.
385
+ */
386
+ hasNode(name: string): boolean;
387
+ /**
388
+ * Returns `true` if an edge from `tail` to `head` exists in the graph.
389
+ * Pass `key` to check for a specific parallel edge; omit (or pass `""`) to
390
+ * check for any edge between the two nodes.
391
+ */
392
+ hasEdge(tail: string, head: string, key?: string): boolean;
393
+ /**
394
+ * Returns `true` if a subgraph with the given name exists.
395
+ */
396
+ hasSubgraph(name: string): boolean;
397
+ /** Returns the number of nodes in the graph. */
398
+ nodeCount(): number;
399
+ /** Returns the number of edges in the graph. */
400
+ edgeCount(): number;
401
+ /** Returns the number of direct subgraphs of this graph. */
402
+ subgraphCount(): number;
403
+ /** Returns the degree of a named node in the graph. */
404
+ nodeDegree(node: string, inDegree?: number, outDegree?: number): number;
405
+ /**
406
+ * Returns the current value of a graph-level attribute, or `""` if the
407
+ * attribute has not been set.
408
+ */
409
+ getGraphAttr(attr: string): string;
410
+ /**
411
+ * Returns the current value of the named attribute on a node, or `""` if
412
+ * the node or attribute does not exist.
413
+ */
414
+ getNodeAttr(node: string, attr: string): string;
415
+ /**
416
+ * Returns the current value of the named attribute on an edge, or `""` if
417
+ * the edge or attribute does not exist.
418
+ * Pass `key = ""` for the first (or only) edge between `tail` and `head`.
419
+ */
420
+ getEdgeAttr(tail: string, head: string, key: string, attr: string): string;
421
+ /**
422
+ * Returns the names of all nodes in the graph (in internal iteration
423
+ * order).
424
+ */
425
+ nodeNames(): string[];
426
+ /**
427
+ * Returns the names of all direct subgraphs.
428
+ */
429
+ subgraphNames(): string[];
430
+ /**
431
+ * Returns all edges in the graph. Each unique edge is listed exactly
432
+ * once.
433
+ */
434
+ edges(): EdgeInfo[];
435
+ /**
436
+ * Returns the out-edges of the named node. Returns `[]` if the node does
437
+ * not exist.
438
+ */
439
+ outEdges(node: string): EdgeInfo[];
440
+ /**
441
+ * Returns the in-edges of the named node. Returns `[]` if the node does
442
+ * not exist.
443
+ */
444
+ inEdges(node: string): EdgeInfo[];
445
+ /**
446
+ * Returns all edges incident to the named node (both in and out).
447
+ * Returns `[]` if the node does not exist.
448
+ */
449
+ nodeEdges(node: string): EdgeInfo[];
450
+ /**
451
+ * Create (or return an existing) named subgraph. Use a name beginning
452
+ * with `"cluster"` to have layout engines render it as a bounded cluster.
453
+ *
454
+ * Returns a {@link Subgraph} wrapper. **Call {@link Subgraph.delete} (or
455
+ * use the `using` keyword) when finished** to free the WASM wrapper. The
456
+ * subgraph data itself is owned by this graph.
457
+ *
458
+ * ```ts
459
+ * using cluster = graph.addSubgraph("cluster_0");
460
+ * cluster.setAttr("label", "My Cluster").addEdge("a", "b");
461
+ * ```
462
+ */
463
+ addSubgraph(name: string): Subgraph;
464
+ /**
465
+ * Look up an existing subgraph by name without creating a new one.
466
+ * Returns a {@link Subgraph} wrapper if a subgraph with that name exists,
467
+ * or `null` if it does not. **Call {@link Subgraph.delete} (or use the
468
+ * `using` keyword) when finished** to free the WASM wrapper.
469
+ *
470
+ * ```ts
471
+ * using sg = graph.getSubgraph("cluster_0");
472
+ * if (sg) {
473
+ * console.log(sg.nodeNames());
474
+ * }
475
+ * ```
476
+ */
477
+ getSubgraph(name: string): Subgraph | null;
478
+ /**
479
+ * Render the graph directly to the specified format without first
480
+ * serialising to DOT. Equivalent to:
481
+ * ```ts
482
+ * graphviz.layout(graph.toDot(), outputFormat, layoutEngine, options)
483
+ * ```
484
+ * but avoids the DOT round-trip.
485
+ *
486
+ * @param outputFormat The output format (default `"svg"`).
487
+ * @param layoutEngine The layout engine to use (default `"dot"`).
488
+ * @param options Optional images / extra files for the renderer.
489
+ * @returns The rendered output as a string.
490
+ */
491
+ layout(outputFormat?: Format, layoutEngine?: Engine, options?: Options): string;
492
+ /**
493
+ * Serialise the graph to a DOT-language string.
494
+ */
495
+ write(): string;
496
+ /**
497
+ * Serialise the graph to a DOT-language string.
498
+ */
499
+ toDot(): string;
500
+ /**
501
+ * Release the underlying WASM object. Must be called when the graph is
502
+ * no longer needed (or use the `using` keyword with TypeScript ≥ 5.2).
503
+ */
504
+ delete(): void;
505
+ /** @internal – supports the `using` keyword (explicit resource management). */
506
+ [Symbol.dispose](): void;
507
+ }
43
508
  /**
44
509
  * 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
510
  *
@@ -47,6 +512,7 @@ export interface Options {
47
512
  *
48
513
  * See [graphviz.org](https://graphviz.org/) for more details.
49
514
  *
515
+ * ### Rendering from a DOT string
50
516
  * ```ts
51
517
  * import { Graphviz } from "@hpcc-js/wasm/graphviz";
52
518
  *
@@ -56,6 +522,23 @@ export interface Options {
56
522
  * const svg = graphviz.dot(dot);
57
523
  * ```
58
524
  *
525
+ * ### Programmatic graph construction
526
+ * ```ts
527
+ * import { Graphviz } from "@hpcc-js/wasm/graphviz";
528
+ *
529
+ * const graphviz = await Graphviz.load();
530
+ *
531
+ * using graph = graphviz.createGraph("G");
532
+ * graph
533
+ * .addNode("a")
534
+ * .addNode("b")
535
+ * .addEdge("a", "b")
536
+ * .setNodeAttr("a", "color", "red")
537
+ * .setGraphAttr("rankdir", "LR");
538
+ *
539
+ * const svg = graph.layout(); // render without a DOT round-trip
540
+ * ```
541
+ *
59
542
  * ### Online Demos
60
543
  * * https://raw.githack.com/hpcc-systems/hpcc-js-wasm/main/index.html
61
544
  * * https://observablehq.com/@gordonsmith/graphviz
@@ -212,4 +695,37 @@ export declare class Graphviz {
212
695
  * @returns A string containing the "pretty printed" dotSource.
213
696
  */
214
697
  nop2(dotSource: string): string;
698
+ /**
699
+ * Programmatically create a graph using the cgraph library.
700
+ *
701
+ * Returns a {@link Graph} builder that lets you add nodes, edges, and
702
+ * attributes without writing DOT source by hand. Call
703
+ * {@link Graph.toDot} to get the DOT string and pass it to
704
+ * {@link layout} (or any convenience wrapper).
705
+ *
706
+ * **You must call {@link Graph.delete} when finished** to free the
707
+ * underlying WASM memory, or use the `using` keyword (TypeScript ≥ 5.2).
708
+ *
709
+ * @param name The graph name (default `"G"`).
710
+ * @param type The graph type (default `"directed"`).
711
+ *
712
+ * ```ts
713
+ * using graph = graphviz.createGraph("G");
714
+ * graph
715
+ * .addNode("a")
716
+ * .addNode("b")
717
+ * .addEdge("a", "b")
718
+ * .setNodeAttr("a", "color", "red")
719
+ * .setGraphAttr("rankdir", "LR");
720
+ *
721
+ * const svg = graphviz.dot(graph.toDot());
722
+ * ```
723
+ */
724
+ createGraph(name?: string, type?: GraphType): Graph;
725
+ /**
726
+ * Parse DOT source into a mutable {@link Graph}. The returned graph can
727
+ * be queried, modified, rendered directly, or serialised back to DOT with
728
+ * {@link Graph.toDot}.
729
+ */
730
+ read(dotSource: string): Graph;
215
731
  }
@@ -47,18 +47,133 @@ export interface CGraphviz extends ClassHandle {
47
47
  set unflatten_out(value: EmbindString);
48
48
  createFile(_0: EmbindString, _1: EmbindString): void;
49
49
  layout(_0: EmbindString, _1: EmbindString, _2: EmbindString): string;
50
+ acyclic(_0: EmbindString): boolean;
51
+ acyclic(_0: EmbindString, _1: boolean): boolean;
50
52
  acyclic(_0: EmbindString, _1: boolean, _2: boolean): boolean;
53
+ tred(_0: EmbindString): void;
54
+ tred(_0: EmbindString, _1: boolean): void;
51
55
  tred(_0: EmbindString, _1: boolean, _2: boolean): void;
56
+ unflatten(_0: EmbindString): string;
57
+ unflatten(_0: EmbindString, _1: number): string;
58
+ unflatten(_0: EmbindString, _1: number, _2: boolean): string;
52
59
  unflatten(_0: EmbindString, _1: number, _2: boolean, _3: number): string;
53
60
  }
54
61
 
62
+ export interface CGraph extends ClassHandle {
63
+ get dot_out(): string;
64
+ set dot_out(value: EmbindString);
65
+ get layout_result(): string;
66
+ set layout_result(value: EmbindString);
67
+ nodeCount(): number;
68
+ edgeCount(): number;
69
+ subgraphCount(): number;
70
+ addNode(_0: EmbindString): void;
71
+ addEdge(_0: EmbindString, _1: EmbindString): void;
72
+ addEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
73
+ setGraphAttr(_0: EmbindString, _1: EmbindString): void;
74
+ setGraphAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
75
+ setGraphHtmlAttr(_0: EmbindString, _1: EmbindString): void;
76
+ setGraphHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
77
+ setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
78
+ setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): void;
79
+ setNodeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
80
+ setNodeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): void;
81
+ setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
82
+ setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString, _5: EmbindString): void;
83
+ setEdgeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
84
+ setEdgeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString, _5: EmbindString): void;
85
+ setDefaultGraphAttr(_0: EmbindString, _1: EmbindString): void;
86
+ setDefaultGraphHtmlAttr(_0: EmbindString, _1: EmbindString): void;
87
+ setDefaultNodeAttr(_0: EmbindString, _1: EmbindString): void;
88
+ setDefaultNodeHtmlAttr(_0: EmbindString, _1: EmbindString): void;
89
+ setDefaultEdgeAttr(_0: EmbindString, _1: EmbindString): void;
90
+ setDefaultEdgeHtmlAttr(_0: EmbindString, _1: EmbindString): void;
91
+ read(_0: EmbindString): boolean;
92
+ addSubgraph(_0: EmbindString): CSubgraph | null;
93
+ getSubgraph(_0: EmbindString): CSubgraph | null;
94
+ removeNode(_0: EmbindString): void;
95
+ removeEdge(_0: EmbindString, _1: EmbindString): void;
96
+ removeEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
97
+ removeSubgraph(_0: EmbindString): void;
98
+ hasNode(_0: EmbindString): boolean;
99
+ hasEdge(_0: EmbindString, _1: EmbindString): boolean;
100
+ hasEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): boolean;
101
+ hasSubgraph(_0: EmbindString): boolean;
102
+ nodeDegree(_0: EmbindString): number;
103
+ nodeDegree(_0: EmbindString, _1: number): number;
104
+ nodeDegree(_0: EmbindString, _1: number, _2: number): number;
105
+ getGraphAttr(_0: EmbindString): string;
106
+ getNodeAttr(_0: EmbindString, _1: EmbindString): string;
107
+ getEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): string;
108
+ nodeNames(): string;
109
+ subgraphNames(): string;
110
+ edges(): string;
111
+ outEdges(_0: EmbindString): string;
112
+ inEdges(_0: EmbindString): string;
113
+ nodeEdges(_0: EmbindString): string;
114
+ write(): string;
115
+ toDot(): string;
116
+ layout(_0: EmbindString, _1: EmbindString): string;
117
+ }
118
+
119
+ export interface CSubgraph extends ClassHandle {
120
+ nodeCount(): number;
121
+ edgeCount(): number;
122
+ addNode(_0: EmbindString): void;
123
+ addEdge(_0: EmbindString, _1: EmbindString): void;
124
+ addEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
125
+ setAttr(_0: EmbindString, _1: EmbindString): void;
126
+ setAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
127
+ setHtmlAttr(_0: EmbindString, _1: EmbindString): void;
128
+ setHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
129
+ setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
130
+ setNodeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): void;
131
+ setNodeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
132
+ setNodeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): void;
133
+ setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
134
+ setEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString, _5: EmbindString): void;
135
+ setEdgeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString): void;
136
+ setEdgeHtmlAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString, _4: EmbindString, _5: EmbindString): void;
137
+ setDefaultAttr(_0: EmbindString, _1: EmbindString): void;
138
+ setDefaultHtmlAttr(_0: EmbindString, _1: EmbindString): void;
139
+ setDefaultNodeAttr(_0: EmbindString, _1: EmbindString): void;
140
+ setDefaultNodeHtmlAttr(_0: EmbindString, _1: EmbindString): void;
141
+ setDefaultEdgeAttr(_0: EmbindString, _1: EmbindString): void;
142
+ setDefaultEdgeHtmlAttr(_0: EmbindString, _1: EmbindString): void;
143
+ removeNode(_0: EmbindString): void;
144
+ removeEdge(_0: EmbindString, _1: EmbindString): void;
145
+ removeEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
146
+ hasNode(_0: EmbindString): boolean;
147
+ hasEdge(_0: EmbindString, _1: EmbindString): boolean;
148
+ hasEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): boolean;
149
+ nodeDegree(_0: EmbindString): number;
150
+ nodeDegree(_0: EmbindString, _1: number): number;
151
+ nodeDegree(_0: EmbindString, _1: number, _2: number): number;
152
+ getAttr(_0: EmbindString): string;
153
+ getNodeAttr(_0: EmbindString, _1: EmbindString): string;
154
+ getEdgeAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString, _3: EmbindString): string;
155
+ nodeNames(): string;
156
+ edges(): string;
157
+ outEdges(_0: EmbindString): string;
158
+ inEdges(_0: EmbindString): string;
159
+ nodeEdges(_0: EmbindString): string;
160
+ }
161
+
55
162
  interface EmbindModule {
56
163
  CGraphviz: {
57
164
  new(): CGraphviz;
165
+ new(_0: number): CGraphviz;
58
166
  new(_0: number, _1: number): CGraphviz;
59
167
  version(): string;
60
168
  lastError(): string;
61
169
  };
170
+ CGraph: {
171
+ new(): CGraph;
172
+ new(_0: EmbindString): CGraph;
173
+ new(_0: EmbindString, _1: number): CGraph;
174
+ new(_0: EmbindString, _1: number, _2: number): CGraph;
175
+ };
176
+ CSubgraph: {};
62
177
  }
63
178
 
64
179
  export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;