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.
js
gf.enclose({ padding: 10, stroke: gf.color.blue[4] }, [
gf.stack({ dir: "x" }, [
gf.rect({ w: 40, h: 40, fill: gf.color.blue[2] }),
gf.rect({ w: 40, h: 60, fill: gf.color.red[2] }),
]),
]).render(root, { w: 160, h: 120 });Signature
ts
enclose(options?, [child1, child2, ...]);background is an alias for the same factory: it takes the same options 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.
| Option | Type | Default | Description |
|---|---|---|---|
padding | number | 2 | Pixels of slack between the children's bbox union and the drawn enclosure. |
rx | number | 2 | Corner radius, x. |
ry | number | 2 | Corner radius, y. |
fill | string | "none" | Fill color of the enclosure. |
stroke | string | "#D1D9E2" | Stroke color of the enclosure. |
strokeWidth | number | 1 | Stroke width in pixels. |
strokeDasharray | string | Raw SVG stroke-dasharray (e.g. "4 2") for a dashed enclosure. | |
opacity | number | 1 | Opacity, 0 to 1. |
