| 174 | * Behauptung, es sei nichts geladen. |
| 175 | */ |
| 176 | export function buildFlowDiagram(view: FlowView): FlowDiagram { |
| 177 | const sequence = view.sequence; |
| 178 | const labels = sequence.participants; |
| 179 | const indexOf = new Map<string, number>(); |
| 180 | labels.forEach((label, index) => indexOf.set(label, index)); |
| 181 | |
| 182 | const lifelines: DiagramLifeline[] = labels.map((label, index) => { |
| 183 | const boxX = DIAGRAM_PAD_X + index * (DIAGRAM_BOX_WIDTH + DIAGRAM_COLUMN_GAP); |
| 184 | return { |
| 185 | index, |
| 186 | label, |
| 187 | x: boxX + DIAGRAM_BOX_WIDTH / 2, |
| 188 | boxX, |
| 189 | boxWidth: DIAGRAM_BOX_WIDTH, |
| 190 | boxHeight: DIAGRAM_BOX_HEIGHT, |
| 191 | headY: DIAGRAM_PAD_TOP, |
| 192 | // Wird gesetzt, sobald die Zeilen stehen: die Fussbox sitzt unter |
| 193 | // der letzten Zeile und nicht an einer geratenen Stelle. |
| 194 | footY: 0, |
| 195 | lineTop: DIAGRAM_PAD_TOP + DIAGRAM_BOX_HEIGHT, |
| 196 | lineBottom: 0, |
| 197 | }; |
| 198 | }); |
| 199 | |
| 200 | const arrows: DiagramArrow[] = sequence.interactions.map((interaction, index) => { |
| 201 | const from = indexOf.get(interaction.from) ?? 0; |
| 202 | const to = indexOf.get(interaction.to) ?? 0; |
| 203 | return { |
| 204 | index, |
| 205 | from, |
| 206 | to, |
| 207 | fromX: lifelines[from]?.x ?? DIAGRAM_PAD_X, |
| 208 | toX: lifelines[to]?.x ?? DIAGRAM_PAD_X, |
| 209 | y: 0, |
| 210 | label: interaction.message, |
| 211 | self: from === to, |
| 212 | cycle: interaction.cycle, |
| 213 | labelX: 0, |
| 214 | labelY: 0, |
| 215 | labelAnchor: from === to ? 'start' : 'middle', |
| 216 | }; |
| 217 | }); |
| 218 | |
| 219 | const loops = loopsOf(view, indexOf, lifelines); |
| 220 | |
| 221 | // Die Zeilen in der Reihenfolge, in der der Kasten sie haelt: die Pfeile in |
| 222 | // Indexreihenfolge, und eine Schleife direkt hinter dem letzten Pfeil, der |
| 223 | // ihre Datei erreicht. Wo kein Pfeil dorthin geht, steht sie am Ende: eine |
| 224 | // Schleife vor dem Aufruf, der sie ausloest, waere eine erfundene Ordnung. |
| 225 | const rows: Row[] = []; |
| 226 | const loopsAfterArrow = new Map<number, number[]>(); |
| 227 | const trailing: number[] = []; |
| 228 | loops.forEach((loop, at) => { |
| 229 | let last = -1; |
| 230 | arrows.forEach((arrow) => { |
| 231 | if (arrow.to === loop.lifeline) { |
| 232 | last = arrow.index; |
| 233 | } |