@hpcc-js/wasm-graphviz 1.25.0 → 1.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-graphviz",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "description": "hpcc-js - WASM Graphviz",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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": "e9302b649306927c2844eda31d3ee58b17b8eb8a"
59
+ "gitHead": "b173ceec45fa54ec60a1642655d4f785ade8165c"
60
60
  }
package/src/graphviz.ts CHANGED
@@ -5,7 +5,8 @@ import type {
5
5
  NodeDotAttr, NodeAttrs,
6
6
  EdgeDotAttr, EdgeAttrs,
7
7
  ClusterDotAttr, ClusterAttrs,
8
- GraphDotAttr, GraphAttrs as GraphAttrs
8
+ GraphDotAttr, GraphAttrs,
9
+ Format, Engine
9
10
  } from "./types.ts";
10
11
 
11
12
  type AttrValues<T> = Partial<{ [K in keyof T]: NonNullable<T[K]> }>;
@@ -24,11 +25,6 @@ function applyAttrs<T extends object>(
24
25
  }
25
26
  }
26
27
 
27
- /**
28
- * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/docs/outputs/) for more information.
29
- */
30
- export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
31
-
32
28
  /**
33
29
  * An edge returned by graph-traversal methods.
34
30
  */
@@ -58,11 +54,6 @@ function parseEdges(json: string): EdgeInfo[] {
58
54
  return result;
59
55
  }
60
56
 
61
- /**
62
- * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
63
- */
64
- export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
65
-
66
57
  /**
67
58
  * Example: Passing a web hosted Image to GraphViz:
68
59
  * ```ts
@@ -165,7 +156,7 @@ export type ClusterInit = SubgraphInit;
165
156
  /**
166
157
  * A subgraph (or cluster) inside a {@link Graph}.
167
158
  *
168
- * Obtain via {@link Graph.addSubgraph}. All mutation methods return `this`
159
+ * Obtain via {@link Graph.addSubgraph} or {@link Subgraph.addSubgraph}. All mutation methods return `this`
169
160
  * for chaining. **Call {@link Subgraph.delete} (or use the `using` keyword)
170
161
  * when finished** to free the underlying WASM wrapper — the actual subgraph
171
162
  * data is owned by the parent {@link Graph} and is freed with it.
@@ -223,6 +214,18 @@ export class Subgraph {
223
214
  return this;
224
215
  }
225
216
 
217
+ /**
218
+ * Create (or return an existing) named subgraph under this subgraph.
219
+ */
220
+ addSubgraph(name: string): Subgraph;
221
+ addSubgraph(init: SubgraphInit): Subgraph;
222
+ addSubgraph(nameOrInit: string | SubgraphInit): Subgraph {
223
+ const init = typeof nameOrInit === "string" ? { name: nameOrInit } : nameOrInit;
224
+ // addSubgraph only returns null when the internal subgraph pointer is null,
225
+ // which cannot happen while this Subgraph instance is alive.
226
+ return new Subgraph(this._sg.addSubgraph(init.name)!).applyInit(init);
227
+ }
228
+
226
229
  applyInit(init: SubgraphInit): this {
227
230
  applyAttrs<ClusterAttrs>(init.attrs, (attr, value) => this.setAttr(attr, value));
228
231
  applyAttrs<ClusterAttrs>(init.htmlAttrs, (attr, value) => this.setHtmlAttr(attr, value));
@@ -560,6 +563,17 @@ export class Graph {
560
563
  this._module = module;
561
564
  }
562
565
 
566
+ private ensureDefaultFonts(includeNodeAndEdgeDefaults: boolean): void {
567
+ if (this.getGraphAttr("fontname") === "") {
568
+ this.setGraphAttr("fontname", "Arial");
569
+ }
570
+ this.setDefaultGraphAttr("fontname", "Arial");
571
+ if (includeNodeAndEdgeDefaults) {
572
+ this.setDefaultNodeAttr("fontname", "Arial");
573
+ this.setDefaultEdgeAttr("fontname", "Arial");
574
+ }
575
+ }
576
+
563
577
  /**
564
578
  * Create a node. If a node with this name already exists it is returned
565
579
  * unchanged.
@@ -597,6 +611,7 @@ export class Graph {
597
611
  }
598
612
 
599
613
  applyInit(init: GraphInit): this {
614
+ this.ensureDefaultFonts(true);
600
615
  applyAttrs<GraphAttrs>(init.attrs, (attr, value) => this.setGraphAttr(attr, value));
601
616
  applyAttrs<GraphAttrs>(init.htmlAttrs, (attr, value) => this.setGraphHtmlAttr(attr, value));
602
617
  return this;
@@ -610,6 +625,7 @@ export class Graph {
610
625
  if (!this._graph.read(dotSource)) {
611
626
  throw new Error("Invalid DOT source");
612
627
  }
628
+ this.ensureDefaultFonts(false);
613
629
  return this;
614
630
  }
615
631
 
@@ -879,18 +895,18 @@ export class Graph {
879
895
  // ---- Graph traversal ------------------------------------------------
880
896
 
881
897
  /**
882
- * Returns the names of all nodes in the graph (in internal iteration
883
- * order).
898
+ * Returns the names of all direct subgraphs.
884
899
  */
885
- nodeNames(): string[] {
886
- return parseNames(this._graph.nodeNames());
900
+ subgraphNames(): string[] {
901
+ return parseNames(this._graph.subgraphNames());
887
902
  }
888
903
 
889
904
  /**
890
- * Returns the names of all direct subgraphs.
905
+ * Returns the names of all nodes in the graph (in internal iteration
906
+ * order).
891
907
  */
892
- subgraphNames(): string[] {
893
- return parseNames(this._graph.subgraphNames());
908
+ nodeNames(): string[] {
909
+ return parseNames(this._graph.nodeNames());
894
910
  }
895
911
 
896
912
  /**
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from "./types.ts";
1
2
  export * from "./graphviz.ts";
package/src/types.ts CHANGED
@@ -611,3 +611,13 @@ export const GRAPH_DOT_ATTRS: readonly GraphDotAttr[] = attrsOf<GraphDotAttr>({
611
611
  voro_margin: true,
612
612
  xdotversion: true,
613
613
  });
614
+
615
+ /**
616
+ * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/docs/outputs/) for more information.
617
+ */
618
+ export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
619
+
620
+ /**
621
+ * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
622
+ */
623
+ export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
@@ -1,12 +1,8 @@
1
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";
2
+ import type { NodeDotAttr, NodeAttrs, EdgeDotAttr, EdgeAttrs, ClusterDotAttr, ClusterAttrs, GraphDotAttr, GraphAttrs, Format, Engine } from "./types.ts";
3
3
  type AttrValues<T> = Partial<{
4
4
  [K in keyof T]: NonNullable<T[K]>;
5
5
  }>;
6
- /**
7
- * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/docs/outputs/) for more information.
8
- */
9
- export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
10
6
  /**
11
7
  * An edge returned by graph-traversal methods.
12
8
  */
@@ -21,10 +17,6 @@ export interface EdgeInfo {
21
17
  */
22
18
  key: string;
23
19
  }
24
- /**
25
- * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
26
- */
27
- export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
28
20
  /**
29
21
  * Example: Passing a web hosted Image to GraphViz:
30
22
  * ```ts
@@ -94,7 +86,7 @@ export type ClusterInit = SubgraphInit;
94
86
  /**
95
87
  * A subgraph (or cluster) inside a {@link Graph}.
96
88
  *
97
- * Obtain via {@link Graph.addSubgraph}. All mutation methods return `this`
89
+ * Obtain via {@link Graph.addSubgraph} or {@link Subgraph.addSubgraph}. All mutation methods return `this`
98
90
  * for chaining. **Call {@link Subgraph.delete} (or use the `using` keyword)
99
91
  * when finished** to free the underlying WASM wrapper — the actual subgraph
100
92
  * data is owned by the parent {@link Graph} and is freed with it.
@@ -126,6 +118,11 @@ export declare class Subgraph {
126
118
  */
127
119
  addEdge(tail: string, head: string, key?: string): this;
128
120
  addEdge(init: EdgeInit): this;
121
+ /**
122
+ * Create (or return an existing) named subgraph under this subgraph.
123
+ */
124
+ addSubgraph(name: string): Subgraph;
125
+ addSubgraph(init: SubgraphInit): Subgraph;
129
126
  applyInit(init: SubgraphInit): this;
130
127
  /**
131
128
  * Remove a node from this subgraph only. The node (and any edges
@@ -303,6 +300,7 @@ export declare class Graph {
303
300
  private _module;
304
301
  /** @internal */
305
302
  constructor(g: CGraphWasm, module: MainModule);
303
+ private ensureDefaultFonts;
306
304
  /**
307
305
  * Create a node. If a node with this name already exists it is returned
308
306
  * unchanged.
@@ -451,15 +449,15 @@ export declare class Graph {
451
449
  * Pass `key = ""` for the first (or only) edge between `tail` and `head`.
452
450
  */
453
451
  getEdgeAttr(tail: string, head: string, key: string, attr: string): string;
452
+ /**
453
+ * Returns the names of all direct subgraphs.
454
+ */
455
+ subgraphNames(): string[];
454
456
  /**
455
457
  * Returns the names of all nodes in the graph (in internal iteration
456
458
  * order).
457
459
  */
458
460
  nodeNames(): string[];
459
- /**
460
- * Returns the names of all direct subgraphs.
461
- */
462
- subgraphNames(): string[];
463
461
  /**
464
462
  * Returns all edges in the graph. Each unique edge is listed exactly
465
463
  * once.
@@ -122,6 +122,7 @@ export interface CSubgraph extends ClassHandle {
122
122
  addNode(_0: EmbindString): void;
123
123
  addEdge(_0: EmbindString, _1: EmbindString): void;
124
124
  addEdge(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
125
+ addSubgraph(_0: EmbindString): CSubgraph | null;
125
126
  setAttr(_0: EmbindString, _1: EmbindString): void;
126
127
  setAttr(_0: EmbindString, _1: EmbindString, _2: EmbindString): void;
127
128
  setHtmlAttr(_0: EmbindString, _1: EmbindString): void;
package/types/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from "./types.ts";
1
2
  export * from "./graphviz.ts";
package/types/types.d.ts CHANGED
@@ -299,4 +299,12 @@ export declare const EDGE_DOT_ATTRS: readonly EdgeDotAttr[];
299
299
  export declare const CLUSTER_DOT_ATTRS: readonly ClusterDotAttr[];
300
300
  /** Graph DOT attributes (excludes write-only: bb, lheight, lp, lwidth; and non-DOT: type) */
301
301
  export declare const GRAPH_DOT_ATTRS: readonly GraphDotAttr[];
302
+ /**
303
+ * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.org/docs/outputs/) for more information.
304
+ */
305
+ export type Format = "svg" | "svg_inline" | "dot" | "json" | "dot_json" | "xdot_json" | "plain" | "plain-ext" | "canon";
306
+ /**
307
+ * Various algorithms for projecting abstract graphs into a space for visualization. See [Layout Engines](https://graphviz.org/docs/layouts/) for more details.
308
+ */
309
+ export type Engine = "circo" | "dot" | "fdp" | "sfdp" | "neato" | "osage" | "patchwork" | "twopi" | "nop" | "nop2";
302
310
  export {};