Skip to content

enclose ​

Draws a rounded rectangle around the union of its children's bounding boxes, padded by padding. Use it to group elements of a diagram visually.

python
from gofish import enclose, stack, rect

enclose(
    [
        stack(
            [rect(w=40, h=40, fill="#a0c4e8"), rect(w=40, h=60, fill="#e8a0a0")],
            dir="x",
        )
    ],
    padding=10,
    stroke="#4e79a7",
).render(w=160, h=120)

Signature ​

python
enclose(children, *, padding=None, rx=None, ry=None, fill=None,
        stroke=None, stroke_width=None, stroke_dasharray=None,
        opacity=None) -> Mark

background is an alias for the same function: it takes the same arguments and produces the same node.

The enclosure is the children's bbox union grown by padding, so it draws nothing of its own beyond that box — reach for position when one child needs a precise absolute offset with its own styling instead.

Parameters ​

Draw a rounded-rect enclosure around the union of the children's bboxes, padded by padding.

OptionTypeDefaultDescription
paddingfloat2Pixels of slack between the children's bbox union and the drawn enclosure.
rxfloat2Corner radius, x.
ryfloat2Corner radius, y.
fillstr"none"Fill color of the enclosure.
strokestr"#D1D9E2"Stroke color of the enclosure.
stroke_widthfloat1Stroke width in pixels.
stroke_dasharraystrRaw SVG stroke-dasharray (e.g. "4 2") for a dashed enclosure.
opacityfloat1Opacity, 0 to 1.