@woosh/meep-engine 2.119.95 → 2.119.96
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert_node_graph_to_dot_string.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/util/convert_node_graph_to_dot_string.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,4DAHW,SAAS,GACP,MAAM,CA6DlB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import LineBuilder from "../../../codegen/LineBuilder.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Graphviz diagram from a node graph
|
|
5
|
+
* @param {NodeGraph} graph
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function convert_node_graph_to_dot_string({graph}){
|
|
9
|
+
// see https://stackoverflow.com/questions/7922960/block-diagram-layout-with-dot-graphviz
|
|
10
|
+
|
|
11
|
+
const lb = new LineBuilder();
|
|
12
|
+
|
|
13
|
+
lb.add('digraph G {');
|
|
14
|
+
lb.indent();
|
|
15
|
+
|
|
16
|
+
lb.add('graph [rankdir = LR];')
|
|
17
|
+
lb.add('node[shape=record];')
|
|
18
|
+
|
|
19
|
+
function nodeId(index) {
|
|
20
|
+
return `n${index}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param index
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
function portId(index){
|
|
29
|
+
return `p${index}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param {NodeInstancePortReference[]} endpoints
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function portBlock(endpoints){
|
|
38
|
+
return `{${endpoints.map(e => `<${portId(e.port.id)}>${e.port.name}`).join("|")}}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// populate nodes
|
|
42
|
+
const nodes = graph.getNodes();
|
|
43
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
44
|
+
const node = nodes[i];
|
|
45
|
+
|
|
46
|
+
const inputs = portBlock(node.inEndpoints);
|
|
47
|
+
const outputs = portBlock(node.outEndpoints);
|
|
48
|
+
|
|
49
|
+
lb.add(`${nodeId(node.id)}[label="${inputs}|${node.desciption.name}/${node.id}|${outputs}"];`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// populate connections
|
|
53
|
+
const connections = graph.getConnections();
|
|
54
|
+
for (let i = 0; i < connections.length; i++) {
|
|
55
|
+
const connection = connections[i];
|
|
56
|
+
|
|
57
|
+
const source = connection.source;
|
|
58
|
+
const target = connection.target;
|
|
59
|
+
lb.add(`${nodeId(source.instance.id)}:${portId(source.port.id)} -> ${nodeId(source.instance.id)}:${portId(source.port.id)};`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
lb.dedent();
|
|
63
|
+
lb.add('}');
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
return lb.build();
|
|
67
|
+
}
|