@thi.ng/rstream-dot 2.1.49 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-03-27T19:05:49Z
3
+ - **Last updated**: 2023-04-08T11:09:50Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,20 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ # [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-dot@3.0.0) (2023-04-08)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - add serialize() ([f3bb5ab](https://github.com/thi-ng/umbrella/commit/f3bb5ab))
17
+ - BREAKING CHANGE: rename walk() => traverse()
18
+ - add serialize() function
19
+ - rename WalkState => TraversalState
20
+ - update default rank direction from TB => LR
21
+
22
+ #### 🩹 Bug fixes
23
+
24
+ - update descendants collection ([fdd1ad2](https://github.com/thi-ng/umbrella/commit/fdd1ad2))
25
+
12
26
  ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-dot@2.1.0) (2021-11-17)
13
27
 
14
28
  #### 🚀 Features
package/README.md CHANGED
@@ -54,7 +54,7 @@ For Node.js REPL:
54
54
  const rstreamDot = await import("@thi.ng/rstream-dot");
55
55
  ```
56
56
 
57
- Package sizes (brotli'd, pre-treeshake): ESM: 754 bytes
57
+ Package sizes (brotli'd, pre-treeshake): ESM: 807 bytes
58
58
 
59
59
  ## Dependencies
60
60
 
@@ -70,54 +70,51 @@ directory are using this package.
70
70
 
71
71
  A selection:
72
72
 
73
- | Description | Live demo | Source |
74
- |:-------------------------------|:-------------------------------------------------------|:------------------------------------------------------------------------------------|
75
- | Minimal rstream dataflow graph | [Demo](https://demo.thi.ng/umbrella/rstream-dataflow/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rstream-dataflow) |
73
+ | Screenshot | Description | Live demo | Source |
74
+ |:--------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------|:-------------------------------------------------------|:------------------------------------------------------------------------------------|
75
+ | | Minimal rstream dataflow graph | [Demo](https://demo.thi.ng/umbrella/rstream-dataflow/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rstream-dataflow) |
76
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg" width="240"/> | Multi-layer vectorization & dithering of bitmap images | [Demo](https://demo.thi.ng/umbrella/trace-bitmap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/trace-bitmap) |
76
77
 
77
78
  ## API
78
79
 
79
80
  [Generated API docs](https://docs.thi.ng/umbrella/rstream-dot/)
80
81
 
81
- ```ts
82
- import * as rsd from "@thi.ng/rstream-dot";
83
-
84
- import * as rs from "@thi.ng/rstream";
85
- import * as tx from "@thi.ng/transducers";
82
+ ```ts tangle:export/readme.ts
83
+ import { fromIterable, merge, trace } from "@thi.ng/rstream";
84
+ import { serialize } from "@thi.ng/rstream-dot";
86
85
 
87
86
  // create dummy dataflow
88
- a = rs.fromIterable([1,2,3]);
89
- b = rs.fromIterable([10, 20, 30]);
90
- a.transform(tx.map((x) => x * 10), "x10");
91
- rs.merge({src: [a, b]}).subscribe(rs.trace());
87
+ const a = fromIterable([1, 2, 3]);
88
+ const b = fromIterable([10, 20, 30]);
89
+ a.map((x) => x * 10, { id: "x10" });
90
+ merge({ src: [a, b] }).subscribe(trace());
92
91
 
93
92
  // now capture the topology by walking the graph from its root(s)
94
93
  // and convert the result to GraphViz DOT format
95
- console.log(rsd.toDot(rsd.walk([a, b])));
96
-
97
- // digraph g {
98
- // rankdir=LR;
99
- // node[fontname=Inconsolata,fontsize=11,style=filled,fontcolor=white];
100
- // edge[fontname=Inconsolata,fontsize=11];
101
- // s0[label="iterable-0\n(Stream)", color=blue];
102
- // s1[label="x10", color=black];
103
- // s2[label="in-iterable-0", color=black];
104
- // s3[label="<noid>", color=gray];
105
- // s4[label="streammerge-0\n(StreamMerge)", color=red];
106
- // s5[label="sub-1", color=black];
107
- // s6[label="<noid>", color=gray];
108
- // s7[label="iterable-1\n(Stream)", color=blue];
109
- // s8[label="in-iterable-1", color=black];
110
- // s9[label="<noid>", color=gray];
111
- // s5 -> s6;
112
- // s4 -> s5;
113
- // s3 -> s4;
114
- // s2 -> s3;
115
- // s0 -> s1[label="xform"];
116
- // s0 -> s2;
117
- // s9 -> s4;
118
- // s8 -> s9;
119
- // s7 -> s8;
120
- // }
94
+ console.log(serialize([a, b]));
95
+ ```
96
+
97
+ Resulting output:
98
+
99
+ ```dot tangle:export/readme.dot
100
+ digraph g {
101
+ rankdir=LR;
102
+ node[fontname="sans-serif",fontsize=10,style=filled,fontcolor=white];
103
+ edge[fontname="sans-serif",fontsize=10];
104
+ s0[label="iterable-0\n(Stream)", color="blue"];
105
+ s1[label="x10", color="black"];
106
+ s2[label="in-iterable-0", color="black"];
107
+ s3[label="streammerge-2\n(StreamMerge)", color="red"];
108
+ s4[label="sub-3", color="black"];
109
+ s5[label="iterable-1\n(Stream)", color="blue"];
110
+ s6[label="in-iterable-1", color="black"];
111
+ s3 -> s4;
112
+ s2 -> s3;
113
+ s0 -> s1[label="xform"];
114
+ s0 -> s2;
115
+ s6 -> s3;
116
+ s5 -> s6;
117
+ }
121
118
  ```
122
119
 
123
120
  Copy output to file `graph.dot` and then run:
package/api.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface Node {
10
10
  xform?: boolean;
11
11
  body?: string;
12
12
  }
13
- export interface WalkState {
13
+ export interface TraversalState {
14
14
  subs: Map<ISubscribable<any>, Node>;
15
15
  rels: Node[][];
16
16
  id: number;
package/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  import type { ISubscribable } from "@thi.ng/rstream";
2
- import type { DotOpts, WalkState } from "./api.js";
2
+ import type { DotOpts, TraversalState } from "./api.js";
3
3
  export * from "./api.js";
4
- export declare const walk: (subs: ISubscribable<any>[], opts?: Partial<DotOpts>, state?: WalkState) => WalkState;
5
- export declare const toDot: (state: WalkState, opts?: Partial<DotOpts>) => string;
4
+ export declare const traverse: (subs: ISubscribable<any>[], opts?: Partial<DotOpts>, state?: TraversalState) => TraversalState;
5
+ export declare const toDot: (state: TraversalState, opts?: Partial<DotOpts>) => string;
6
+ /**
7
+ * Syntax sugar for the composition {@link traverse} and {@link toDot},
8
+ * serializing the traversable graph topology to Graphviz DOT format.
9
+ *
10
+ * @param subs
11
+ * @param opts
12
+ */
13
+ export declare const serialize: (subs: ISubscribable<any>[], opts?: Partial<DotOpts>) => string;
6
14
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -11,6 +11,16 @@ const getNodeType = (sub) => sub instanceof Stream
11
11
  : sub instanceof StreamMerge
12
12
  ? "StreamMerge"
13
13
  : undefined;
14
+ const getChildren = (sub) => {
15
+ let children = [];
16
+ if (sub.subs)
17
+ children.push(...sub.subs);
18
+ if (sub.__owner)
19
+ children.push(sub.__owner);
20
+ if (sub.wrapped)
21
+ children.push(...getChildren(sub.wrapped));
22
+ return children;
23
+ };
14
24
  const dotNode = (s, opts) => {
15
25
  let res = `s${s.id}[label="`;
16
26
  res += s.type ? `${s.label}\\n(${s.type})` : `${s.label}`;
@@ -28,7 +38,7 @@ const subValue = (sub) => {
28
38
  const res = JSON.stringify(sub.deref ? sub.deref() : undefined);
29
39
  return res ? truncate(64, "...")(res) : res;
30
40
  };
31
- export const walk = (subs, opts, state) => {
41
+ export const traverse = (subs, opts, state) => {
32
42
  opts || (opts = {});
33
43
  state || (state = { id: 0, subs: new Map(), rels: [] });
34
44
  for (let sub of subs) {
@@ -44,10 +54,9 @@ export const walk = (subs, opts, state) => {
44
54
  };
45
55
  state.subs.set(sub, desc);
46
56
  state.id++;
47
- const children = sub.subs ||
48
- (sub.__owner ? [sub.__owner] : undefined);
49
- if (children) {
50
- walk(children, opts, state);
57
+ const children = getChildren(sub);
58
+ if (children.length) {
59
+ traverse(children, opts, state);
51
60
  for (let c of children) {
52
61
  const childNode = state.subs.get(c);
53
62
  childNode && state.rels.push([desc, childNode]);
@@ -58,7 +67,7 @@ export const walk = (subs, opts, state) => {
58
67
  };
59
68
  export const toDot = (state, opts) => {
60
69
  opts = {
61
- dir: "TB",
70
+ dir: "LR",
62
71
  font: "sans-serif",
63
72
  fontsize: 10,
64
73
  text: "white",
@@ -82,3 +91,11 @@ export const toDot = (state, opts) => {
82
91
  "}",
83
92
  ].join("\n");
84
93
  };
94
+ /**
95
+ * Syntax sugar for the composition {@link traverse} and {@link toDot},
96
+ * serializing the traversable graph topology to Graphviz DOT format.
97
+ *
98
+ * @param subs
99
+ * @param opts
100
+ */
101
+ export const serialize = (subs, opts) => toDot(traverse(subs, opts), opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream-dot",
3
- "version": "2.1.49",
3
+ "version": "3.0.1",
4
4
  "description": "Graphviz DOT conversion of @thi.ng/rstream dataflow graph topologies",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,17 +34,17 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/rstream": "^7.2.46",
38
- "@thi.ng/strings": "^3.4.3",
39
- "@thi.ng/transducers": "^8.4.1"
37
+ "@thi.ng/rstream": "^8.0.1",
38
+ "@thi.ng/strings": "^3.4.5",
39
+ "@thi.ng/transducers": "^8.4.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@microsoft/api-extractor": "^7.34.4",
43
- "@thi.ng/testament": "^0.3.14",
43
+ "@thi.ng/testament": "^0.3.15",
44
44
  "rimraf": "^4.4.1",
45
45
  "tools": "^0.0.1",
46
46
  "typedoc": "^0.23.28",
47
- "typescript": "^5.0.2"
47
+ "typescript": "^5.0.4"
48
48
  },
49
49
  "keywords": [
50
50
  "conversion",
@@ -85,5 +85,5 @@
85
85
  ],
86
86
  "year": 2018
87
87
  },
88
- "gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
88
+ "gitHead": "3a56bc490f1e68754762a503d06327b5b34ff7eb\n"
89
89
  }