(value: unknown)
| 74 | * waere dieselbe Regel an zwei Stellen. |
| 75 | */ |
| 76 | export function readGraphData(value: unknown): GraphData { |
| 77 | const raw = isRecord(value) ? value : {}; |
| 78 | const nodes: GraphNode[] = []; |
| 79 | for (const entry of Array.isArray(raw['nodes']) ? raw['nodes'] : []) { |
| 80 | if (!isRecord(entry)) { |
| 81 | continue; |
| 82 | } |
| 83 | const id = num(entry['id']); |
| 84 | const x = num(entry['x']); |
| 85 | const y = num(entry['y']); |
| 86 | const z = num(entry['z']); |
| 87 | const size = num(entry['size']); |
| 88 | const color = text(entry['color']); |
| 89 | const name = text(entry['name']); |
| 90 | if (id === undefined || x === undefined || y === undefined || z === undefined) { |
| 91 | continue; |
| 92 | } |
| 93 | const label = text(entry['label']) ?? ''; |
| 94 | const qualifiedName = text(entry['qualified_name']); |
| 95 | nodes.push({ |
| 96 | id, |
| 97 | x, |
| 98 | y, |
| 99 | z, |
| 100 | label, |
| 101 | name: name ?? String(id), |
| 102 | // Der Branch-Knoten traegt im Layout die Datei "{}"; das ist keine Datei (Runde 4, N1). |
| 103 | file_path: nodeFilePath({ name: name ?? String(id), label, qualified_name: qualifiedName, file_path: text(entry['file_path']) }), |
| 104 | qualified_name: qualifiedName, |
| 105 | start_line: num(entry['start_line']), |
| 106 | end_line: num(entry['end_line']), |
| 107 | size: size !== undefined && size > 0 ? size : 1, |
| 108 | color: color ?? '#8899aa', |
| 109 | status: text(entry['status']) as NodeStatus | undefined, |
| 110 | in_calls: num(entry['in_calls']), |
| 111 | out_calls: num(entry['out_calls']), |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | const edges: GraphEdge[] = []; |
| 116 | for (const entry of Array.isArray(raw['edges']) ? raw['edges'] : []) { |
| 117 | if (!isRecord(entry)) { |
| 118 | continue; |
| 119 | } |
| 120 | const source = num(entry['source']); |
| 121 | const target = num(entry['target']); |
| 122 | if (source === undefined || target === undefined) { |
| 123 | continue; |
| 124 | } |
| 125 | edges.push({ source, target, type: text(entry['type']) ?? '' }); |
| 126 | } |
| 127 | |
| 128 | let missedGraph: MissedGraph | undefined; |
| 129 | const missed = raw['missed_graph']; |
| 130 | if (isRecord(missed) && isRecord(missed['offset'])) { |
| 131 | const x = num(missed['offset']['x']); |
| 132 | const y = num(missed['offset']['y']); |
| 133 | const z = num(missed['offset']['z']); |
no test coverage detected