fletcher.flexigrid()

A β€œflexible” coordinate system to be placed in CeTZ canvas which adapts to nodes contained therein.

Objects drawn inside a flexigrid have access to a 𝑒𝑣 coordinate system, which is a nonlinear grid of rows and columns which stretch to fit nodes, like a table. Only content placed in node() can affect the 𝑒𝑣 grid; edge()s and plain CeTZ objects in a flexigrid never affect the layout.

By default, nodes and edges use 𝑒𝑣 coordinates while CeTZ objects use the default π‘₯𝑦 coordinates. Use the coordinate expressions (uv: ..) and (xy: ..) to specify the system. Both systems can be mixed in coordinate expressions like ((uv: (1,2)), 50%, (xy: (0,0))).

#cetz.canvas({
  import cetz.draw: *
  fletcher.flexigrid(debug: "grid", {
    set-style(node: (fill: yellow))
    node((0,0))[Nodes...]
    node((2,1))[...in $u v$ system]
    circle((uv: (2,0)), radius: 5pt, fill: blue)
    content((3,2))[Content in $x y$ system]
  })
})

The main diagram() function is essentially equivalent to flexigrid() wrapped in cetz.canvas().

fletcher.flexigrid(
  ..args,
  spacing: number length pair,
  axes: array,
  max-layout-iterations: int,
  debug,
)

spacing

number or length or pair default 1.0

Gutter between cells.

Numbers are interpreted in CeTZ units. Column and row gutter can be controlled independently as the first and last numbers in a pair, (col-gutter, row-gutter).

axes

array default (ltr, ttb)

The physical orientation of the (𝑒,𝑣) axes.

This affects the elastic coordinate system used by nodes and edges. By default, the 𝑒 coordinate increases β†’ and 𝑣 increases ↓. To use (β†’,↑), which is what CeTZ uses by default, set axes: (ltr, btt).

max-layout-iterations

int default 20

Maximum number of layout iterations used to find row and column sizes before converging.

Diagrams with nodes at fractional 𝑒𝑣 coordinates may require more iterations of the layout algorithm until the flexigrid stabilizes. You can see how many iterations were used with the debug: "grid.iters" option.