Spacing
The Spacing family holds the ways spread sets its neighbors apart along dir. A spacing is a value of spread's spacing option, beside a bare amount. Spacing.box(gap) leaves a gap between the facing edges of each child's box. Spacing.pitch(distance, at=...) puts the same point on each child a fixed distance from the last one. The spacing of Constraint.distribute takes the same values.
from gofish import Spacing, chart, field, scatter, spread
(
chart(seattle_weather)
.flow(
spread(
by=field("month").sort(MONTH_NAMES),
dir="y",
spacing=Spacing.pitch(24, at="baseline"),
),
scatter(x="temp_max", h=40),
)
.mark(ridge)
.render(w=500, h=400)
)Signature
spread(dir=..., spacing=Spacing.box(gap))
spread(dir=..., spacing=Spacing.pitch(distance, at=None))
spread(dir=..., spacing=gap) # the same as Spacing.box(gap)A bare amount is Spacing.box(amount): spacing=8 and spacing=Spacing.box(8) lay the children out the same way. The amount is a number of pixels, percent(n), or fr(k), in both members. gap and distance are positional.
A spacing is a plain dict, {"kind": ..., **params}, for example {"kind": "pitch", "distance": 24, "at": "baseline"}.
The family is also a module of its own:
from gofish import Spacing
from gofish.spacing import pitch # the same function as Spacing.pitchMembers
| Member | Measures from | To | Depends on the children's sizes |
|---|---|---|---|
Spacing.box() | the end of one child's box | the start of the next child's box | yes |
Spacing.pitch() | the point at on one child | the point at on the next child | no |
at is "start", "middle", "end" or "baseline". "middle" is center to center. "baseline" is each child's local 0, which for a ribbon or a text is its baseline, not an edge of its box.
Spacing.box()
| Option | Type | Default | Description |
|---|---|---|---|
gap | float | LengthValue | Required. The gap between facing edges, in pixels. A negative gap overlaps the children. Also percent(n), n percent of the room it is laid out in (its parent's, or the canvas), or fr(k), k shares of the room its nearest scope divides. |
Spacing.pitch()
| Option | Type | Default | Description |
|---|---|---|---|
distance | float | LengthValue | Required. The distance between the points, in pixels. Also percent(n), n percent of the room it is laid out in (its parent's, or the canvas), or fr(k), k shares of the room its nearest scope divides. | |
at | str | "baseline" | The point on each child: the start of its box, its middle, the end of its box, or its baseline (its local 0). "middle" is center to center. |
See also
spreadConstraint.distribute- Underlying space, the essay on how a chain of children claims its room
