Skip to content

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

Nothing is downloaded until you press it.

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

OptionTypeDefaultWhat it does
rowsstd::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.
columnsstd::vector<std::string>As above, along the top.
scaleScale0.0, 0.0
autoScalebooltrue
stepsint5Quantise 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 optionalstd::optional<Token>The hue the scale runs to. Unset takes the design's first chart colour, so the grid re-themes with everything else.
cellSizefloat0.0fZero lets the cells share out the width.
gapfloat3.0f
radiusfloat2.0f
rowLabelsfloat34.0fRoom for the labels. Zero draws none.
columnLabelsfloat16.0fThe same, along the top.
hoverbooltrue
valueFormatstd::string_view"%.0f"
tooltipChartTooltip
namestd::string_viewWhat 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.

Released under the LGPL-3.0-or-later licence.