grid_in_bbox
Functiongrid_in_bbox(
states: list[State],
x: float,
y: float,
width: float,
height: float,
rows: Optional[int] = None,
cols: Optional[int] = None,
alignment: ElementAlignment = <ElementAlignment.PRESERVE: 'preserve'>,
element_rotation_offset: float = 0
) -> list[State]
Arrange states in a rectangular grid that fits within a bounding box.
Alternative specification to grid() for users who think in terms of available space rather than spacing between elements. The grid will be sized to fill the specified bounding box with elements evenly distributed.
Parameters
-
states - List of states to arrange
-
x - X coordinate of bounding box top-left corner
-
y - Y coordinate of bounding box top-left corner
-
width - Width of bounding box
-
height - Height of bounding box
-
rows - Number of rows in the grid (optional, auto-calculated if not provided)
-
cols - Number of columns in the grid (optional, auto-calculated if not provided)
-
alignment - How to align each element relative to the grid
-
element_rotation_offset - Additional rotation in degrees added to the alignment base
Returns
New list of states with grid positions Raises: ValueError: If width or height is zero or negative
Examples
# 3x3 grid in 600x600 box
grid_in_bbox(states, 0, 0, 600, 600, rows=3, cols=3)
# Auto-sized grid filling rectangular area
grid_in_bbox(states, -200, -150, 400, 300)
# Equivalent to grid() with spacing:
# grid_in_bbox(states, 0, 0, 400, 200, rows=3, cols=4)
# == grid(states, rows=3, cols=4, center=Point2D(), spacing_h=~133, spacing_v=100)