.md →
GridDraw API#
Bases: AnyWidget
Drawable square grid widget for dots and orthogonal line segments.
rows and cols count cells. Intersections are addressed as
[row, col] coordinates from [0, 0] through [rows, cols].
Examples:
import marimo as mo
from wigglystuff import GridDraw
grid = mo.ui.anywidget(GridDraw(rows=8, cols=8, line_width=[1, 2, 4]))
grid
Create a GridDraw widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
int
|
Number of grid cells vertically. |
8
|
cols
|
int
|
Number of grid cells horizontally. |
8
|
line_width
|
int | Sequence[int]
|
Positive int for fixed width, or non-empty list of positive ints to show a width picker. The first list item is the default width. |
2
|
dot_radius
|
int
|
Drawn dot radius in pixels. |
6
|
theme
|
str | None
|
|
None
|
width
|
int
|
Widget pixel width. |
440
|
height
|
int
|
Widget pixel height. |
440
|
dots
|
Iterable[Sequence[int]] | None
|
Optional initial dot coordinates. |
None
|
lines
|
Iterable[dict[str, Any]] | None
|
Optional initial line dictionaries. |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in wigglystuff/grid_draw.py
add_dot #
Add a dot at an intersection.
Adding an existing dot is a no-op.
Source code in wigglystuff/grid_draw.py
add_line #
Add a unit line segment between orthogonally adjacent intersections.
Source code in wigglystuff/grid_draw.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
dots |
list |
Drawn intersections as [[row, col], ...]. |
lines |
list |
Drawn unit segments as {"from": [r, c], "to": [r, c], "width": int} dictionaries. |
rows |
int |
Number of grid cells vertically; row intersections are 0..rows. |
cols |
int |
Number of grid cells horizontally; column intersections are 0..cols. |
line_width |
int \| list[int] |
Fixed line width, or picker options when a list is supplied. |
dot_radius |
int |
Drawn dot radius in pixels. |
theme |
str \| None |
None follows the notebook; "light" or "dark" forces the widget theme. |
width |
int |
Widget width in pixels. |
height |
int |
Widget height in pixels. |