@hpcc-js/wasm-graphviz 1.24.0 → 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.
- package/README.md +75 -43
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
- package/src/graphviz.ts +276 -40
- package/src/types.ts +6 -0
- package/types/graphviz.d.ts +100 -27
- package/types/graphvizlib.d.ts +52 -0
- package/types/types.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/wasm-graphviz",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.1",
|
|
4
4
|
"description": "hpcc-js - WASM Graphviz",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@hpcc-js/esbuild-plugins": "1.9.
|
|
40
|
+
"@hpcc-js/esbuild-plugins": "1.9.4",
|
|
41
41
|
"@hpcc-js/wasm-util": "1.0.0"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
},
|
|
57
57
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
58
58
|
"license": "Apache-2.0",
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "66515f510e2045ad74b336a52f3ab55974ebed9e"
|
|
60
60
|
}
|
package/src/graphviz.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
} from "./types.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.
|
|
12
|
+
* Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/docs/outputs/) for more information.
|
|
13
13
|
*/
|
|
14
14
|
export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
|
|
15
15
|
|
|
@@ -43,7 +43,7 @@ function parseEdges(json: string): EdgeInfo[] {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.
|
|
46
|
+
* Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
|
|
47
47
|
*/
|
|
48
48
|
export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
|
|
49
49
|
|
|
@@ -183,16 +183,50 @@ export class Subgraph {
|
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* Set an attribute on the subgraph itself (e.g. `"label"`, `"style"`,
|
|
186
|
-
* `"color"`, `"bgcolor"`).
|
|
186
|
+
* `"color"`, `"bgcolor"`). See the official Graphviz
|
|
187
|
+
* [attribute reference](https://graphviz.org/docs/attrs/) for supported
|
|
188
|
+
* attributes and values.
|
|
187
189
|
*
|
|
188
190
|
* When `attr` is a known cluster attribute the value type is inferred
|
|
189
191
|
* automatically. A generic `string | number | boolean` fallback is
|
|
190
|
-
* provided for custom or less-common attributes.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
* provided for custom or less-common attributes. Omit `value` to reset
|
|
193
|
+
* the attribute to Graphviz's default empty value. `defaultValue` is
|
|
194
|
+
* passed to Graphviz as the default for this attribute if it has not
|
|
195
|
+
* already been declared.
|
|
196
|
+
*/
|
|
197
|
+
setAttr<K extends ClusterDotAttr>(attr: K, value?: NonNullable<ClusterAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
198
|
+
setAttr(attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
199
|
+
setAttr(attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
200
|
+
if (defaultValue === undefined) {
|
|
201
|
+
this._sg.setAttr(attr, String(value));
|
|
202
|
+
} else {
|
|
203
|
+
this._sg.setAttr(attr, String(value), String(defaultValue));
|
|
204
|
+
}
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
setHtmlAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
209
|
+
setHtmlAttr(attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
210
|
+
setHtmlAttr(attr: string, value: unknown, defaultValue?: unknown): this {
|
|
211
|
+
if (defaultValue === undefined) {
|
|
212
|
+
this._sg.setHtmlAttr(attr, String(value));
|
|
213
|
+
} else {
|
|
214
|
+
this._sg.setHtmlAttr(attr, String(value), String(defaultValue));
|
|
215
|
+
}
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
setDefaultAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>): this;
|
|
220
|
+
setDefaultAttr(attr: string, value: string | number | boolean): this;
|
|
221
|
+
setDefaultAttr(attr: string, value: unknown): this {
|
|
222
|
+
this._sg.setDefaultAttr(attr, String(value));
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setDefaultHtmlAttr<K extends ClusterDotAttr>(attr: K, value: NonNullable<ClusterAttrs[K]>): this;
|
|
227
|
+
setDefaultHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
228
|
+
setDefaultHtmlAttr(attr: string, value: unknown): this {
|
|
229
|
+
this._sg.setDefaultHtmlAttr(attr, String(value));
|
|
196
230
|
return this;
|
|
197
231
|
}
|
|
198
232
|
|
|
@@ -209,12 +243,43 @@ export class Subgraph {
|
|
|
209
243
|
*
|
|
210
244
|
* When `attr` is a known node attribute the value type is inferred
|
|
211
245
|
* automatically. A generic `string | number | boolean` fallback is
|
|
212
|
-
* provided for custom attributes.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
setNodeAttr(node: string, attr:
|
|
217
|
-
|
|
246
|
+
* provided for custom attributes. Omit `value` to reset the attribute to
|
|
247
|
+
* Graphviz's default empty value. `defaultValue` is passed to Graphviz as
|
|
248
|
+
* the default for this attribute if it has not already been declared.
|
|
249
|
+
*/
|
|
250
|
+
setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value?: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
251
|
+
setNodeAttr(node: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
252
|
+
setNodeAttr(node: string, attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
253
|
+
if (defaultValue === undefined) {
|
|
254
|
+
this._sg.setNodeAttr(node, attr, String(value));
|
|
255
|
+
} else {
|
|
256
|
+
this._sg.setNodeAttr(node, attr, String(value), String(defaultValue));
|
|
257
|
+
}
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
setNodeHtmlAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
262
|
+
setNodeHtmlAttr(node: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
263
|
+
setNodeHtmlAttr(node: string, attr: string, value: unknown, defaultValue?: unknown): this {
|
|
264
|
+
if (defaultValue === undefined) {
|
|
265
|
+
this._sg.setNodeHtmlAttr(node, attr, String(value));
|
|
266
|
+
} else {
|
|
267
|
+
this._sg.setNodeHtmlAttr(node, attr, String(value), String(defaultValue));
|
|
268
|
+
}
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
setDefaultNodeAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
273
|
+
setDefaultNodeAttr(attr: string, value: string | number | boolean): this;
|
|
274
|
+
setDefaultNodeAttr(attr: string, value: unknown): this {
|
|
275
|
+
this._sg.setDefaultNodeAttr(attr, String(value));
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
setDefaultNodeHtmlAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
280
|
+
setDefaultNodeHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
281
|
+
setDefaultNodeHtmlAttr(attr: string, value: unknown): this {
|
|
282
|
+
this._sg.setDefaultNodeHtmlAttr(attr, String(value));
|
|
218
283
|
return this;
|
|
219
284
|
}
|
|
220
285
|
|
|
@@ -232,12 +297,43 @@ export class Subgraph {
|
|
|
232
297
|
*
|
|
233
298
|
* When `attr` is a known edge attribute the value type is inferred
|
|
234
299
|
* automatically. A generic `string | number | boolean` fallback is
|
|
235
|
-
* provided for custom attributes.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
setEdgeAttr(tail: string, head: string, key: string, attr:
|
|
240
|
-
|
|
300
|
+
* provided for custom attributes. Omit `value` to reset the attribute to
|
|
301
|
+
* Graphviz's default empty value. `defaultValue` is passed to Graphviz as
|
|
302
|
+
* the default for this attribute if it has not already been declared.
|
|
303
|
+
*/
|
|
304
|
+
setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value?: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
305
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
306
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
307
|
+
if (defaultValue === undefined) {
|
|
308
|
+
this._sg.setEdgeAttr(tail, head, key, attr, String(value));
|
|
309
|
+
} else {
|
|
310
|
+
this._sg.setEdgeAttr(tail, head, key, attr, String(value), String(defaultValue));
|
|
311
|
+
}
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
setEdgeHtmlAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
316
|
+
setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
317
|
+
setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: unknown, defaultValue?: unknown): this {
|
|
318
|
+
if (defaultValue === undefined) {
|
|
319
|
+
this._sg.setEdgeHtmlAttr(tail, head, key, attr, String(value));
|
|
320
|
+
} else {
|
|
321
|
+
this._sg.setEdgeHtmlAttr(tail, head, key, attr, String(value), String(defaultValue));
|
|
322
|
+
}
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
setDefaultEdgeAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
327
|
+
setDefaultEdgeAttr(attr: string, value: string | number | boolean): this;
|
|
328
|
+
setDefaultEdgeAttr(attr: string, value: unknown): this {
|
|
329
|
+
this._sg.setDefaultEdgeAttr(attr, String(value));
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
setDefaultEdgeHtmlAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
334
|
+
setDefaultEdgeHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
335
|
+
setDefaultEdgeHtmlAttr(attr: string, value: unknown): this {
|
|
336
|
+
this._sg.setDefaultEdgeHtmlAttr(attr, String(value));
|
|
241
337
|
return this;
|
|
242
338
|
}
|
|
243
339
|
|
|
@@ -275,6 +371,11 @@ export class Subgraph {
|
|
|
275
371
|
/** Returns the number of edges in this subgraph. */
|
|
276
372
|
edgeCount(): number { return this._sg.edgeCount(); }
|
|
277
373
|
|
|
374
|
+
/** Returns the degree of a named node in this subgraph. */
|
|
375
|
+
nodeDegree(node: string, inDegree: number = 1, outDegree: number = 1): number {
|
|
376
|
+
return this._sg.nodeDegree(node, inDegree, outDegree);
|
|
377
|
+
}
|
|
378
|
+
|
|
278
379
|
// ---- Attribute reading ----------------------------------------------
|
|
279
380
|
|
|
280
381
|
/**
|
|
@@ -412,17 +513,62 @@ export class Graph {
|
|
|
412
513
|
return this;
|
|
413
514
|
}
|
|
414
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Replace this graph with one parsed from DOT source using Graphviz cgraph
|
|
518
|
+
* reading support.
|
|
519
|
+
*/
|
|
520
|
+
read(dotSource: string): this {
|
|
521
|
+
if (!this._graph.read(dotSource)) {
|
|
522
|
+
throw new Error("Invalid DOT source");
|
|
523
|
+
}
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
|
|
415
527
|
/**
|
|
416
528
|
* Set a graph-level attribute (e.g. `"rankdir"`, `"label"`, `"bgcolor"`).
|
|
529
|
+
* See the official Graphviz [attribute reference](https://graphviz.org/docs/attrs/)
|
|
530
|
+
* for supported attributes and values.
|
|
417
531
|
*
|
|
418
532
|
* When `attr` is a known graph attribute the value type is inferred
|
|
419
533
|
* automatically. A generic `string | number | boolean` fallback is
|
|
420
|
-
* provided for custom or less-common attributes.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
534
|
+
* provided for custom or less-common attributes. Omit `value` to reset
|
|
535
|
+
* the attribute to Graphviz's default empty value. `defaultValue` is
|
|
536
|
+
* passed to Graphviz as the default for this attribute if it has not
|
|
537
|
+
* already been declared.
|
|
538
|
+
*/
|
|
539
|
+
setGraphAttr<K extends GraphDotAttr>(attr: K, value?: NonNullable<GraphAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
540
|
+
setGraphAttr(attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
541
|
+
setGraphAttr(attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
542
|
+
if (defaultValue === undefined) {
|
|
543
|
+
this._graph.setGraphAttr(attr, String(value));
|
|
544
|
+
} else {
|
|
545
|
+
this._graph.setGraphAttr(attr, String(value), String(defaultValue));
|
|
546
|
+
}
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setGraphHtmlAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
551
|
+
setGraphHtmlAttr(attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
552
|
+
setGraphHtmlAttr(attr: string, value: unknown, defaultValue?: unknown): this {
|
|
553
|
+
if (defaultValue === undefined) {
|
|
554
|
+
this._graph.setGraphHtmlAttr(attr, String(value));
|
|
555
|
+
} else {
|
|
556
|
+
this._graph.setGraphHtmlAttr(attr, String(value), String(defaultValue));
|
|
557
|
+
}
|
|
558
|
+
return this;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
setDefaultGraphAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>): this;
|
|
562
|
+
setDefaultGraphAttr(attr: string, value: string | number | boolean): this;
|
|
563
|
+
setDefaultGraphAttr(attr: string, value: unknown): this {
|
|
564
|
+
this._graph.setDefaultGraphAttr(attr, String(value));
|
|
565
|
+
return this;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
setDefaultGraphHtmlAttr<K extends GraphDotAttr>(attr: K, value: NonNullable<GraphAttrs[K]>): this;
|
|
569
|
+
setDefaultGraphHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
570
|
+
setDefaultGraphHtmlAttr(attr: string, value: unknown): this {
|
|
571
|
+
this._graph.setDefaultGraphHtmlAttr(attr, String(value));
|
|
426
572
|
return this;
|
|
427
573
|
}
|
|
428
574
|
|
|
@@ -432,12 +578,43 @@ export class Graph {
|
|
|
432
578
|
*
|
|
433
579
|
* When `attr` is a known node attribute the value type is inferred
|
|
434
580
|
* automatically. A generic `string | number | boolean` fallback is
|
|
435
|
-
* provided for custom attributes.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
setNodeAttr(node: string, attr:
|
|
440
|
-
|
|
581
|
+
* provided for custom attributes. Omit `value` to reset the attribute to
|
|
582
|
+
* Graphviz's default empty value. `defaultValue` is passed to Graphviz as
|
|
583
|
+
* the default for this attribute if it has not already been declared.
|
|
584
|
+
*/
|
|
585
|
+
setNodeAttr<K extends NodeDotAttr>(node: string, attr: K, value?: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
586
|
+
setNodeAttr(node: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
587
|
+
setNodeAttr(node: string, attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
588
|
+
if (defaultValue === undefined) {
|
|
589
|
+
this._graph.setNodeAttr(node, attr, String(value));
|
|
590
|
+
} else {
|
|
591
|
+
this._graph.setNodeAttr(node, attr, String(value), String(defaultValue));
|
|
592
|
+
}
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
setNodeHtmlAttr<K extends NodeDotAttr>(node: string, attr: K, value: NonNullable<NodeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
597
|
+
setNodeHtmlAttr(node: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
598
|
+
setNodeHtmlAttr(node: string, attr: string, value: unknown, defaultValue?: unknown): this {
|
|
599
|
+
if (defaultValue === undefined) {
|
|
600
|
+
this._graph.setNodeHtmlAttr(node, attr, String(value));
|
|
601
|
+
} else {
|
|
602
|
+
this._graph.setNodeHtmlAttr(node, attr, String(value), String(defaultValue));
|
|
603
|
+
}
|
|
604
|
+
return this;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
setDefaultNodeAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
608
|
+
setDefaultNodeAttr(attr: string, value: string | number | boolean): this;
|
|
609
|
+
setDefaultNodeAttr(attr: string, value: unknown): this {
|
|
610
|
+
this._graph.setDefaultNodeAttr(attr, String(value));
|
|
611
|
+
return this;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
setDefaultNodeHtmlAttr<K extends NodeDotAttr>(attr: K, value: NonNullable<NodeAttrs[K]>): this;
|
|
615
|
+
setDefaultNodeHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
616
|
+
setDefaultNodeHtmlAttr(attr: string, value: unknown): this {
|
|
617
|
+
this._graph.setDefaultNodeHtmlAttr(attr, String(value));
|
|
441
618
|
return this;
|
|
442
619
|
}
|
|
443
620
|
|
|
@@ -448,12 +625,43 @@ export class Graph {
|
|
|
448
625
|
*
|
|
449
626
|
* When `attr` is a known edge attribute the value type is inferred
|
|
450
627
|
* automatically. A generic `string | number | boolean` fallback is
|
|
451
|
-
* provided for custom attributes.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
setEdgeAttr(tail: string, head: string, key: string, attr:
|
|
456
|
-
|
|
628
|
+
* provided for custom attributes. Omit `value` to reset the attribute to
|
|
629
|
+
* Graphviz's default empty value. `defaultValue` is passed to Graphviz as
|
|
630
|
+
* the default for this attribute if it has not already been declared.
|
|
631
|
+
*/
|
|
632
|
+
setEdgeAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value?: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
633
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value?: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
634
|
+
setEdgeAttr(tail: string, head: string, key: string, attr: string, value: unknown = "", defaultValue?: unknown): this {
|
|
635
|
+
if (defaultValue === undefined) {
|
|
636
|
+
this._graph.setEdgeAttr(tail, head, key, attr, String(value));
|
|
637
|
+
} else {
|
|
638
|
+
this._graph.setEdgeAttr(tail, head, key, attr, String(value), String(defaultValue));
|
|
639
|
+
}
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
setEdgeHtmlAttr<K extends EdgeDotAttr>(tail: string, head: string, key: string, attr: K, value: NonNullable<EdgeAttrs[K]>, defaultValue?: string | number | boolean): this;
|
|
644
|
+
setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: string | number | boolean, defaultValue?: string | number | boolean): this;
|
|
645
|
+
setEdgeHtmlAttr(tail: string, head: string, key: string, attr: string, value: unknown, defaultValue?: unknown): this {
|
|
646
|
+
if (defaultValue === undefined) {
|
|
647
|
+
this._graph.setEdgeHtmlAttr(tail, head, key, attr, String(value));
|
|
648
|
+
} else {
|
|
649
|
+
this._graph.setEdgeHtmlAttr(tail, head, key, attr, String(value), String(defaultValue));
|
|
650
|
+
}
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
setDefaultEdgeAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
655
|
+
setDefaultEdgeAttr(attr: string, value: string | number | boolean): this;
|
|
656
|
+
setDefaultEdgeAttr(attr: string, value: unknown): this {
|
|
657
|
+
this._graph.setDefaultEdgeAttr(attr, String(value));
|
|
658
|
+
return this;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
setDefaultEdgeHtmlAttr<K extends EdgeDotAttr>(attr: K, value: NonNullable<EdgeAttrs[K]>): this;
|
|
662
|
+
setDefaultEdgeHtmlAttr(attr: string, value: string | number | boolean): this;
|
|
663
|
+
setDefaultEdgeHtmlAttr(attr: string, value: unknown): this {
|
|
664
|
+
this._graph.setDefaultEdgeHtmlAttr(attr, String(value));
|
|
457
665
|
return this;
|
|
458
666
|
}
|
|
459
667
|
|
|
@@ -547,6 +755,11 @@ export class Graph {
|
|
|
547
755
|
/** Returns the number of direct subgraphs of this graph. */
|
|
548
756
|
subgraphCount(): number { return this._graph.subgraphCount(); }
|
|
549
757
|
|
|
758
|
+
/** Returns the degree of a named node in the graph. */
|
|
759
|
+
nodeDegree(node: string, inDegree: number = 1, outDegree: number = 1): number {
|
|
760
|
+
return this._graph.nodeDegree(node, inDegree, outDegree);
|
|
761
|
+
}
|
|
762
|
+
|
|
550
763
|
// ---- Attribute reading ----------------------------------------------
|
|
551
764
|
|
|
552
765
|
/**
|
|
@@ -697,11 +910,18 @@ export class Graph {
|
|
|
697
910
|
return retVal;
|
|
698
911
|
}
|
|
699
912
|
|
|
913
|
+
/**
|
|
914
|
+
* Serialise the graph to a DOT-language string.
|
|
915
|
+
*/
|
|
916
|
+
write(): string {
|
|
917
|
+
return this._graph.write();
|
|
918
|
+
}
|
|
919
|
+
|
|
700
920
|
/**
|
|
701
921
|
* Serialise the graph to a DOT-language string.
|
|
702
922
|
*/
|
|
703
923
|
toDot(): string {
|
|
704
|
-
return this.
|
|
924
|
+
return this.write();
|
|
705
925
|
}
|
|
706
926
|
|
|
707
927
|
/**
|
|
@@ -1072,4 +1292,20 @@ export class Graphviz {
|
|
|
1072
1292
|
const strict = type.startsWith("strict") ? 1 : 0;
|
|
1073
1293
|
return new Graph(new this._module.CGraph(name, directed, strict), this._module);
|
|
1074
1294
|
}
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Parse DOT source into a mutable {@link Graph}. The returned graph can
|
|
1298
|
+
* be queried, modified, rendered directly, or serialised back to DOT with
|
|
1299
|
+
* {@link Graph.toDot}.
|
|
1300
|
+
*/
|
|
1301
|
+
read(dotSource: string): Graph {
|
|
1302
|
+
const graph = this.createGraph();
|
|
1303
|
+
try {
|
|
1304
|
+
graph.read(dotSource);
|
|
1305
|
+
return graph;
|
|
1306
|
+
} catch (e) {
|
|
1307
|
+
graph.delete();
|
|
1308
|
+
throw e;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1075
1311
|
}
|
package/src/types.ts
CHANGED
|
@@ -81,6 +81,7 @@ export interface NodeAttrs {
|
|
|
81
81
|
group?: string;
|
|
82
82
|
height?: number;
|
|
83
83
|
href?: string;
|
|
84
|
+
id?: string;
|
|
84
85
|
image?: string;
|
|
85
86
|
imagepos?: string;
|
|
86
87
|
imagescale?: boolean | string;
|
|
@@ -146,6 +147,7 @@ export interface EdgeAttrs {
|
|
|
146
147
|
headtooltip?: string;
|
|
147
148
|
headURL?: string;
|
|
148
149
|
href?: string;
|
|
150
|
+
id?: string;
|
|
149
151
|
label?: string;
|
|
150
152
|
labelangle?: number;
|
|
151
153
|
labeldistance?: number;
|
|
@@ -204,6 +206,7 @@ export interface ClusterAttrs {
|
|
|
204
206
|
fontsize?: number;
|
|
205
207
|
gradientangle?: number;
|
|
206
208
|
href?: string;
|
|
209
|
+
id?: string;
|
|
207
210
|
K?: number;
|
|
208
211
|
label?: string;
|
|
209
212
|
labeljust?: string;
|
|
@@ -374,6 +377,7 @@ export const NODE_DOT_ATTRS: readonly NodeDotAttr[] = attrsOf<NodeDotAttr>({
|
|
|
374
377
|
group: true,
|
|
375
378
|
height: true,
|
|
376
379
|
href: true,
|
|
380
|
+
id: true,
|
|
377
381
|
image: true,
|
|
378
382
|
imagepos: true,
|
|
379
383
|
imagescale: true,
|
|
@@ -434,6 +438,7 @@ export const EDGE_DOT_ATTRS: readonly EdgeDotAttr[] = attrsOf<EdgeDotAttr>({
|
|
|
434
438
|
headtooltip: true,
|
|
435
439
|
headURL: true,
|
|
436
440
|
href: true,
|
|
441
|
+
id: true,
|
|
437
442
|
label: true,
|
|
438
443
|
labelangle: true,
|
|
439
444
|
labeldistance: true,
|
|
@@ -486,6 +491,7 @@ export const CLUSTER_DOT_ATTRS: readonly ClusterDotAttr[] = attrsOf<ClusterDotAt
|
|
|
486
491
|
fontsize: true,
|
|
487
492
|
gradientangle: true,
|
|
488
493
|
href: true,
|
|
494
|
+
id: true,
|
|
489
495
|
K: true,
|
|
490
496
|
label: true,
|
|
491
497
|
labeljust: true,
|