Heatmap
heatmap · Charts · interactive
Charts: a scale, its ticks, and a line or area drawn from data.
Import
cpp
#include "gbui/widgets/chart.hpp"Example
cpp
HeatmapResult heatmap(Ui& ui, const Interaction& input, std::string_view id, const std::vector<std::vector<double>>& values, const HeatmapOptions& options = {});A grid of cells shaded by value. values is row-major and may be ragged — a short row simply has fewer cells, which is what a calendar's last week is. The colour is one token at varying strength rather than a rainbow. A multi-hue scale looks richer and reads worse: hue carries no order, so a reader has to consult the legend for every cell, while "more of the same colour" needs no legend at all.
API
HeatmapOptions
| Option | Type | Default | What it does |
|---|---|---|---|
rows | std::vector<std::string> | Names down the side and along the top. Fewer than there are rows or columns leaves the rest unlabelled rather than renumbering them. | |
columns | std::vector<std::string> | As above, along the top. | |
scale | Scale | 0.0, 0.0 | |
autoScale | bool | true | |
steps | int | 5 | Quantise the colour into this many steps; zero is a continuous ramp. Five by default, and steps rather than a ramp because a reader compares cells by matching them, not by judging absolute lightness. Two cells one step apart are visibly different; two cells 3% apart on a continuous ramp are the same colour to anyone reading a grid at a glance. |
color optional | std::optional<Token> | The hue the scale runs to. Unset takes the design's first chart colour, so the grid re-themes with everything else. | |
cellSize | float | 0.0f | Zero lets the cells share out the width. |
gap | float | 3.0f | |
radius | float | 2.0f | |
rowLabels | float | 34.0f | Room for the labels. Zero draws none. |
columnLabels | float | 16.0f | The same, along the top. |
hover | bool | true | |
valueFormat | std::string_view | "%.0f" | |
tooltip | ChartTooltip | ||
name | std::string_view | What the chart is of — "Revenue by month". A chart is the one thing on a screen a reader gets nothing from: the shapes carry all of it, and the numbers behind them are the caller's. A name and a Figure role are the least that makes it navigable, and they are not the whole answer — see the note in docs/reference/accessibility. |