scale-time

Temporal position scale formatting axis labels as times (x or y).

Usage

scale-time(
  ..args,
)

Parameters

Parameter Default Description
..args Named arguments forwarded to the axis scale.

Keys accepted by ..args:

  • name: Axis or legend title, as a string or content; none (default) falls back to the mapped column name.
  • limits: Domain as a (lo, hi) pair of numbers or ISO-8601 strings, where either side may be auto to train that side from the data; none (default) trains both sides.
  • oob: Handling of rows outside limits: "drop" (default) removes them, "squish" clamps them to the nearest limit.
  • breaks: Array of tick positions in the scale’s numeric units, a bare number for a single tick, a function of the trained values returning positions (the breaks-* helpers return such a function), or auto (default) for computed breaks.
  • labels: Array of labels aligned with the breaks, a function of the break value returning a string or content (the format-* helpers return such a function), or auto (default) to format each break.
  • expand: Padding around the domain as a ratio (5%), a length (5pt), a relative, or a (lo, hi) pair whose sides may each be auto; false or none removes it. auto (default) pads 5% per side.
  • date-format: Typst datetime.display format string; default “[hour]:[minute]”.

Returns

Deferred scale spec consumed by scales.

Examples

Label a y axis of elapsed seconds as times of day.

#let d = range(0, 7).map(i => (x: i, y: i * 900))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-line(),),
  scales: scales(y: scale-time()),
  width: 12cm,
  height: 6cm,
)

Line chart of seven rising points on a y axis whose ticks read as hour-and-minute times decoded from elapsed seconds.

Line chart of seven rising points on a y axis whose ticks read as hour-and-minute times decoded from elapsed seconds.

See also

scales, scale-date, scale-datetime.

Back to top