Skip to content

layer ​

Overlays multiple children in the same coordinate space without any layout offset.

js
gf.layer([
  gf.rect({ w: 100, h: 80, fill: gf.color.blue[3] }),
  gf.ellipse({ w: 60, h: 60, fill: gf.color.red[3] }),
]).render(root, { w: 200, h: 150 });

Both shapes occupy the same space. The ellipse is drawn on top of the rectangle because it appears second in the array.

Signature ​

ts
layer(options?, [child1, child2, ...])

Parameters ​

Compose children on the same canvas at (0, 0) unless placed by constraints. Also accepts explicit box dims when given a self-scaling size.

OptionTypeDefaultDescription
keystringInternal per-node key override.
coordanyCoordinate transform (polar(), clock(), wavy(), ...) the children are drawn in. Given one, the layer becomes that coordinate boundary.
axesAxesOptionsDraw the coordinate axes of this layer's coord. Ignored on a layer with no coord.
transformobjectNon-affine-foldable scale applied to the composed children.
boxbooleanTrue renders this as a coordinate-space transparent "box" boundary rather than a plain layer.

Box dimensions ​

OptionTypeDefaultDescription
xnumber | string | FieldExprLeft edge position.
cxnumber | string | FieldExprCenter x.
x2number | string | FieldExprRight edge position.
wnumber | string | FieldExprWidth.
emXbooleanEmbed x in the parent's x space.
ynumber | string | FieldExprTop/bottom edge position (y-up: bottom).
cynumber | string | FieldExprCenter y.
y2number | string | FieldExprOther y edge position.
hnumber | string | FieldExprHeight.
emYbooleanEmbed y in the parent's y space.
dimsRecord<string, AxisDimsValue>Box dimensions by axis name: x/y, or a name the enclosing coordinate space declares (polar theta/r, geo lon/lat). Each value is a position (like x) or an interval {min, center, max, size, embedded}.

Z-ordering ​

By default, children are drawn in the order they appear in the array — later children appear on top. You can override this with .zOrder(n) on any child. Children are sorted by z-order value before rendering; lower values are drawn first (underneath). Children with the same z-order value keep their original array order.

ts
layer([
  chart(data)
    .flow(scatter({ by: "x", y: "y" }))
    .mark(line())
    .zOrder(0),
  chart(data)
    .flow(scatter({ by: "x", y: "y" }))
    .mark(circle({ r: 5 }))
    .zOrder(1),
]);

.zOrder() is available on ChartBuilder (the object returned by chart()) and on GoFishNode instances.