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
wnumber | string | FieldExpr | LengthWidth. 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.
hnumber | string | FieldExpr | LengthHeight. 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.
filterFilter | stringA filter over this whole drawing: a Filter strategy (Filter.grayscale(), Filter.luminanceToAlpha()) or a raw CSS filter string ("blur(2px)", "url(#shadow)").
keystringInternal per-node key override.
coordanyCoordinate transform (Coord.polar(), Coord.clock(), Coord.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.
paddingnumber30Pixels the content of this layer's coord keeps from the edge of its box (a polar space's outer radius is half the shorter side less this). 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.
emXbooleanEmbed x in the parent's x space.
ynumber | string | FieldExprStart edge on y: the top edge where y reads top-down, the bottom edge where it grows upward.
cynumber | string | FieldExprCenter y.
y2number | string | FieldExprOther y edge position.
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}.

Coordinate space ​

With a coord, the layer is the box of that coordinate space: its children are drawn in it, and axes and padding apply to it.

ts
layer({ coord: Coord.clock(), w: 300, h: 300 }, [
  chart(seafood)
    .flow(stack({ by: "species", dir: "x" }))
    .mark(rect({ w: "count", fill: "species" })),
]);

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.