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.

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.

OptionTypeDefaultDescription
paddingnumber2Pixels of slack between the children's bbox union and the drawn enclosure.
rxnumber2Corner radius, x.
rynumber2Corner radius, y.
fillstring"none"Fill color of the enclosure.
strokestring"#D1D9E2"Stroke color of the enclosure.
strokeWidthnumber1Stroke width in pixels.
strokeDasharraystringRaw SVG stroke-dasharray (e.g. "4 2") for a dashed enclosure.
opacitynumber1Opacity, 0 to 1.