( nodes: Map<string, GraphNode>, gridSize: number | undefined )
| 61 | * Returns null if gridSize is not set or no snapping was needed. |
| 62 | */ |
| 63 | export function snapNodesToGrid( |
| 64 | nodes: Map<string, GraphNode>, |
| 65 | gridSize: number | undefined |
| 66 | ): { width: number; height: number } | null { |
| 67 | if (!gridSize || gridSize <= 0 || nodes.size === 0) { |
| 68 | return null |
| 69 | } |
| 70 | |
| 71 | let minX = Number.POSITIVE_INFINITY |
| 72 | let minY = Number.POSITIVE_INFINITY |
| 73 | let maxX = Number.NEGATIVE_INFINITY |
| 74 | let maxY = Number.NEGATIVE_INFINITY |
| 75 | |
| 76 | for (const node of nodes.values()) { |
| 77 | node.position = snapPositionToGrid(node.position, gridSize) |
| 78 | minX = Math.min(minX, node.position.x) |
| 79 | minY = Math.min(minY, node.position.y) |
| 80 | maxX = Math.max(maxX, node.position.x + node.metrics.width) |
| 81 | maxY = Math.max(maxY, node.position.y + node.metrics.height) |
| 82 | } |
| 83 | |
| 84 | return { |
| 85 | width: maxX - minX + CONTAINER_PADDING * 2, |
| 86 | height: maxY - minY + CONTAINER_PADDING * 2, |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Checks if a block type is a container (loop or parallel) |
no test coverage detected