Recursively estimate pixel height for nested steps (used for container node sizing).
(steps: FlowNodeData[] | undefined)
| 10 | |
| 11 | /** Recursively estimate pixel height for nested steps (used for container node sizing). */ |
| 12 | function calculateNestedStepsHeight(steps: FlowNodeData[] | undefined): number { |
| 13 | if (!steps || steps.length === 0) return 0; |
| 14 | |
| 15 | let totalHeight = 0; |
| 16 | for (const step of steps) { |
| 17 | switch (step.nodeType) { |
| 18 | case 'if': { |
| 19 | const { thenSteps, elseSteps } = step as IfNodeData; |
| 20 | const branchHeight = Math.max( |
| 21 | calculateNestedStepsHeight(thenSteps), |
| 22 | calculateNestedStepsHeight(elseSteps), |
| 23 | ); |
| 24 | totalHeight += 60 + branchHeight + 30; |
| 25 | break; |
| 26 | } |
| 27 | case 'while': |
| 28 | case 'for_each': { |
| 29 | const { loopSteps } = step as WhileNodeData | ForEachNodeData; |
| 30 | totalHeight += 50 + calculateNestedStepsHeight(loopSteps) + 30; |
| 31 | break; |
| 32 | } |
| 33 | case 'switch': { |
| 34 | const { cases, defaultSteps } = step as SwitchNodeData; |
| 35 | let casesHeight = 0; |
| 36 | if (cases) { |
| 37 | for (const caseSteps of Object.values(cases)) { |
| 38 | casesHeight += calculateNestedStepsHeight(caseSteps) + 40; |
| 39 | } |
| 40 | } |
| 41 | totalHeight += 80 + casesHeight + calculateNestedStepsHeight(defaultSteps) + 50; |
| 42 | break; |
| 43 | } |
| 44 | default: |
| 45 | totalHeight += 40; |
| 46 | } |
| 47 | } |
| 48 | return totalHeight; |
| 49 | } |
| 50 | |
| 51 | // Calculate node dimensions based on type and content |
| 52 | export function getNodeDimensions(node: FlowNode): { width: number; height: number } { |