Skip to content

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.

python
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 ​

python
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:

python
from gofish import Spacing
from gofish.spacing import pitch  # the same function as Spacing.pitch

Members ​

MemberMeasures fromToDepends on the children's sizes
Spacing.box()the end of one child's boxthe start of the next child's boxyes
Spacing.pitch()the point at on one childthe point at on the next childno

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() ​

OptionTypeDefaultDescription
gapfloat | LengthValueRequired. 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() ​

OptionTypeDefaultDescription
distancefloat | LengthValueRequired. 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.
atstr"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 ​