| name | bed-layout |
| description | Edit the visual grid layout of a garden bed, assigning crops to cells on a canvas editor. Use when asked to arrange crops in a bed, draw a planting layout, move crops around, visualize companion planting placement, or check for enemy crop adjacency in a specific bed. Triggers include "layout editor", "bed grid", "draw the bed", "assign crops to cells", "companion warning in layout", or similar visual planning tasks. |
bed-layout
Visual canvas-based grid editor for assigning crops to garden bed cells. Companion relationships are shown live as you edit.
When to Use
- Arranging crops in a specific bed on a visual grid
- Checking which cells have which crops assigned
- Detecting enemy crop adjacency (shown with red borders)
- Saving or updating the layout JSON for a bed
Layout JSON Format
Each bed stores its layout as JSON in the layout_json column:
{
"cell_size_ft": 1,
"cells": {
"0,0": "crop-uuid-here",
"0,1": "crop-uuid-here",
"1,0": "another-crop-uuid"
}
}
Keys are "row,col" strings. Values are crop UUIDs. Empty cells are absent from the cells map.
API Usage
Save a layout
PATCH /api/beds/:id/layout
Content-Type: application/json
{
"cell_size_ft": 1,
"cells": {
"0,0": "uuid-tomato",
"0,1": "uuid-basil"
}
}
Returns 200 with the updated bed record, or 400 if the layout JSON is invalid.
Get a bed with its layout
GET /api/beds/:id
Returns the bed with layout_json parsed as an object.
Grid Dimensions
The grid size is computed from the bed dimensions:
cols = ceil(width_ft / cell_size_ft)
rows = ceil(length_ft / cell_size_ft)
A 4x12 ft bed with cell_size_ft: 1 produces a 4-column, 12-row grid (48 cells total).
Companion Warnings
The editor computes adjacency warnings client-side:
- For each assigned cell, check its 4 neighbors (up, down, left, right).
- If the neighbor has a different crop and the two crops have an
enemy relationship, render a red dashed border on the shared edge.
- Friend relationships show a subtle green tint on adjacent cells.
The companion data is fetched from GET /api/crops/:id/companions for each unique crop in the layout.
Keyboard Shortcuts (in the canvas editor)
| Key | Action |
|---|
| Arrow keys | Move selection cursor |
| Space | Assign selected crop to current cell |
| Delete / Backspace | Clear current cell |
| E | Switch to Erase tool |
| 1-9 | Select crop at position N in palette |
Notes
- The layout auto-saves every 500ms after a change (debounced). A "Saved" indicator appears in the toolbar.
- Undo/redo is not implemented. The last saved state can be restored by refreshing.
- The cell size can be changed (0.5 ft, 1 ft, 2 ft) but this resets the cell assignments for that bed.