| 19 | } |
| 20 | |
| 21 | function parseGraph(config, graph) { |
| 22 | let nodes = {}; |
| 23 | let edges = []; |
| 24 | let inputs = {}; |
| 25 | let inputs_tag = {}; |
| 26 | let outputs = {}; |
| 27 | let outputs_tag = {}; |
| 28 | |
| 29 | let subgraphs = {}; |
| 30 | let dots = []; |
| 31 | |
| 32 | for (const name in graph.nodes) { |
| 33 | let node = graph.nodes[name]; |
| 34 | if (isGraph(config, node.ty)) { |
| 35 | subgraphs[name] = parseGraph(config, config.graphs[node.ty]); |
| 36 | node.link = subgraphs[name]; |
| 37 | } else { |
| 38 | nodes[name] = { |
| 39 | id: config.counter, |
| 40 | label: name, |
| 41 | color: "#fff", |
| 42 | title: graph.name, |
| 43 | ports: new Set(), |
| 44 | }; |
| 45 | node.link = nodes[name]; |
| 46 | config.counter += 1; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | for (const conn of graph.connections) { |
| 51 | let related = { rx: [], tx: [], unknown: [] }; |
| 52 | for (const port of conn.ports) { |
| 53 | let port_split = port.split(":"); |
| 54 | let node_name = port_split[0]; |
| 55 | let node_port = port_split[1]; |
| 56 | if (nodes.hasOwnProperty(node_name)) { |
| 57 | nodes[node_name].ports.add(node_port); |
| 58 | related.unknown.push(nodes[node_name].id); |
| 59 | } else if (subgraphs.hasOwnProperty(node_name)) { |
| 60 | const subgraph = subgraphs[node_name]; |
| 61 | if (isInput(subgraph, node_port)) { |
| 62 | for (const id of subgraph.inputs[node_port]) { |
| 63 | related.rx.push(id); |
| 64 | } |
| 65 | } else if (isOutput(subgraph, node_port)) { |
| 66 | for (const id of subgraph.outputs[node_port]) { |
| 67 | related.tx.push(id); |
| 68 | } |
| 69 | } else { |
| 70 | throw new Error( |
| 71 | `port[${node_port}] is not found in graph[${graph.nodes[node_name].ty}]` |
| 72 | ); |
| 73 | } |
| 74 | } else if (config.g_nodes.hasOwnProperty(node_name)) { |
| 75 | config.g_nodes[node_name].ports.add(node_port); |
| 76 | related.unknown.push(config.g_nodes[node_name].id); |
| 77 | } else if (config.g_graphs.hasOwnProperty(node_name)) { |
| 78 | const subgraph = config.g_graphs[node_name]; |