Heatmap

Heatmap :: # (opaque)

A validated Plotly heatmap: a grid of finite values drawn as colors.

is_eq : _

Compare the encoded trace, including input order and all style settings.

new : Props -> Try(Heatmap, [RowLengthMismatch({ y : Coordinate, expected : U64, actual : U64 }), InvalidValueRange({ min : F64, max : F64 }), Infinity, NaN, NegativeInfinity])

Validate the grid and construct a heatmap trace. Returns RowLengthMismatch({ y, expected, actual }) for a row whose value count differs from the number of x positions, NaN, Infinity or NegativeInfinity for a nonfinite value, and InvalidValueRange({ min, max }) for bounds that are nonfinite or where min is not below max.

expect {
    grid = Heatmap.new({ x: ["09:00", "09:01"], rows: [{ y: "error", values: [3, 0] }] })?
    grid.to_json().contains("heatmap")
}
to_json_value : Heatmap -> InternalJson

Internal composition hook used by Plume's renderers. Applications normally use Heatmap.to_json for complete JSON text; this returns the package's safe internal value without accepting raw JSON.

to_json : Heatmap -> Str

Serialize the trace as JSON.

Row

:= { y : Coordinate, values : List(F64) }

One row of the grid: its y position and one value per x position. values must have exactly as many entries as Heatmap.Props's x, and each value must be finite.

ColorScale : [Blackbody, Bluered, Blues, Cividis, Earth, Electric, Greens, Greys, Hot, Jet, Picnic, Portland, Rainbow, RdBu, Reds, Viridis, YlGnBu, YlOrRd]

Plotly's named color scales. Viridis and Cividis are perceptually uniform and remain readable for most color-vision deficiencies. Plotly defines a few sequential scales, including YlOrRd, YlGnBu and Greys, from dark to light; use direction: Reversed when low values should be light.

Props

:= {
    x : List(Coordinate),
    rows : List(Row),
    name : Str ?? "",
    color_scale : ColorScale ?? Viridis,
    direction : [Normal, Reversed] ?? Normal,
    value_range : [Auto, Bounds({ min : F64, max : F64 })] ?? Auto,
    color_bar : [Shown, Hidden] ?? Shown,
    cell_gap : U8 ?? 0,
}

Configure a heatmap.

  • x lists the column positions, and rows the rows from bottom to top; both may be empty. Use Coordinate.from_time for instants.
  • name is the legend/hover label, and may be empty.
  • color_scale defaults to Viridis; direction: Reversed maps the highest value to the scale's first color instead.
  • value_range: Auto stretches the scale over the data. `Bounds({ min, max })` fixes it, so colors keep their meaning when the data changes; values beyond the bounds take the end colors.
  • color_bar defaults to Shown, drawing the scale beside the grid.
  • cell_gap separates cells by this many pixels, defaulting to zero.