( blocks: Record<string, BlockState>, edges: Edge[], assignLayersFn: (blocks: Record<string, BlockState>, edges: Edge[]) => Map<string, GraphNode> )
| 582 | * @returns Map of container block IDs to their internal layer depth |
| 583 | */ |
| 584 | export function calculateSubflowDepths( |
| 585 | blocks: Record<string, BlockState>, |
| 586 | edges: Edge[], |
| 587 | assignLayersFn: (blocks: Record<string, BlockState>, edges: Edge[]) => Map<string, GraphNode> |
| 588 | ): Map<string, number> { |
| 589 | const depths = new Map<string, number>() |
| 590 | const { children } = getBlocksByParent(blocks) |
| 591 | |
| 592 | for (const [containerId, childIds] of children.entries()) { |
| 593 | if (childIds.length === 0) { |
| 594 | depths.set(containerId, 1) |
| 595 | continue |
| 596 | } |
| 597 | |
| 598 | const childBlocks: Record<string, BlockState> = {} |
| 599 | const layoutChildIds = filterLayoutEligibleBlockIds(childIds, blocks) |
| 600 | for (const childId of layoutChildIds) { |
| 601 | childBlocks[childId] = blocks[childId] |
| 602 | } |
| 603 | |
| 604 | const childEdges = edges.filter( |
| 605 | (edge) => layoutChildIds.includes(edge.source) && layoutChildIds.includes(edge.target) |
| 606 | ) |
| 607 | |
| 608 | if (Object.keys(childBlocks).length === 0) { |
| 609 | depths.set(containerId, 1) |
| 610 | continue |
| 611 | } |
| 612 | |
| 613 | const childNodes = assignLayersFn(childBlocks, childEdges) |
| 614 | let maxLayer = 0 |
| 615 | for (const node of childNodes.values()) { |
| 616 | maxLayer = Math.max(maxLayer, node.layer) |
| 617 | } |
| 618 | |
| 619 | depths.set(containerId, Math.max(maxLayer + 1, 1)) |
| 620 | } |
| 621 | |
| 622 | return depths |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * Layout function type for preparing container dimensions. |
no test coverage detected