* Computes layout positions for a subset of blocks using the core layout function
( childIds: string[], blocks: Record<string, BlockState>, edges: Edge[], parentBlock: BlockState | undefined, horizontalSpacing: number, verticalSpacing: number, subflowDepths?: Map<string, number>, gridSize?: number )
| 433 | * Computes layout positions for a subset of blocks using the core layout function |
| 434 | */ |
| 435 | function computeLayoutPositions( |
| 436 | childIds: string[], |
| 437 | blocks: Record<string, BlockState>, |
| 438 | edges: Edge[], |
| 439 | parentBlock: BlockState | undefined, |
| 440 | horizontalSpacing: number, |
| 441 | verticalSpacing: number, |
| 442 | subflowDepths?: Map<string, number>, |
| 443 | gridSize?: number |
| 444 | ): Map<string, { x: number; y: number }> { |
| 445 | const subsetBlocks: Record<string, BlockState> = {} |
| 446 | for (const id of childIds) { |
| 447 | subsetBlocks[id] = blocks[id] |
| 448 | } |
| 449 | |
| 450 | const subsetEdges = edges.filter( |
| 451 | (edge) => childIds.includes(edge.source) && childIds.includes(edge.target) |
| 452 | ) |
| 453 | |
| 454 | if (Object.keys(subsetBlocks).length === 0) { |
| 455 | return new Map() |
| 456 | } |
| 457 | |
| 458 | const isContainer = !!parentBlock |
| 459 | const { nodes, dimensions } = layoutBlocksCore(subsetBlocks, subsetEdges, { |
| 460 | isContainer, |
| 461 | layoutOptions: { |
| 462 | horizontalSpacing: isContainer ? horizontalSpacing * 0.85 : horizontalSpacing, |
| 463 | verticalSpacing, |
| 464 | gridSize, |
| 465 | }, |
| 466 | subflowDepths, |
| 467 | }) |
| 468 | |
| 469 | if (parentBlock) { |
| 470 | parentBlock.data = { |
| 471 | ...parentBlock.data, |
| 472 | width: Math.max(dimensions.width, CONTAINER_DIMENSIONS.DEFAULT_WIDTH), |
| 473 | height: Math.max(dimensions.height, CONTAINER_DIMENSIONS.DEFAULT_HEIGHT), |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | const positions = new Map<string, { x: number; y: number }>() |
| 478 | for (const node of nodes.values()) { |
| 479 | positions.set(node.id, { x: node.position.x, y: node.position.y }) |
| 480 | } |
| 481 | |
| 482 | return positions |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Updates container dimensions based on children |
no test coverage detected