HeatMap
HeatMap in UIToolbox shows a grid of values as colored cells: each value takes a color on a scale from a low color to a high color. Use it for the players online by day and hour, the damage of each weapon against each enemy, the wins of each team on each map, the heat of a world map, or any table of numbers that reads better as colors.


Video tutorial: HeatMap. All videos: Video tutorials.
<tb:HeatMap values="1, 3, 4; 2, 5, 7; 3, 6, 9" />
<tb:HeatMap
row-labels="Mon, Tue, Wed"
column-labels="Morning, Noon, Night"
show-values="true"
values="4, 8, 2; 6, 9, 3; 1, 5, 7" />
<tb:HeatMap
steps="5"
min-value="0"
max-value="10"
show-legend="false"
values="0, 2, 5, 9, 10" />
var map = root.Q<HeatMap>("activity");
// rows, then columns
map.SetData(new float[,] { { 1, 3, 4 }, { 2, 5, 7 } });
// a list, row after row, 24 values to a row
map.SetData(kills, 24);
// row 2, column 5
map.SetValue(2, 5, 12);
map.CellSelected += (row, column) =>
Debug.Log(map.GetValue(row, column));
The cells share the room that the labels and the legend leave. The heat map grows to fill its parent and is at least 120 pixels high.
A name wider than its column reaches over the columns beside it. When the columns are too narrow for their names, the heat map shows every second, third, ... name, so the names never overlap, and the first name always shows. With column-labels="0:00, , , 3:00, , , 6:00, ..." a wide map names every 3 hours and a narrow one every 6 or 9 hours. The empty names do not count, and a hidden name keeps its place, so each name that shows stays above its column. The row names thin the same way when the rows are shorter than a name.
Settings
| Setting (UXML) | Type | Default | Does |
|---|---|---|---|
values |
string | "" | The values: the rows separated by ; or a new line, the values of a row by commas, as in 1, 2; 3, 4. A shorter row ends in cells without a value, and NaN is a cell without a value. A part that is not a number counts as 0. |
row-labels |
string | "" | The names of the rows as a comma-separated list, on the left of the grid. Rows too short for their names show every few names. |
column-labels |
string | "" | The names of the columns as a comma-separated list, above the grid. An empty name leaves its column without one, so 0, , , 3 names every third column. Columns too narrow for their names show every few names. |
min-value, max-value |
float | NaN | The values at the low and the high color. NaN fits the lowest and the highest value. A value outside the range takes the color of the nearest end. |
steps |
int | 0 | 0 is a smooth scale. 2 or more puts each value in one of that many bands of color, as an activity calendar does. |
low-color, mid-color, high-color |
Color |
clear | The colors of the scale. Clear takes --tb-heat-map-low, --tb-heat-map-mid and --tb-heat-map-high. Without a mid color the scale has two colors. |
show-values |
bool | false | Shows the value on each cell that is at least 18 × 12 pixels. The text is dark on a light cell. |
show-legend |
bool | true | Shows the scale under the grid, with the lowest and the highest value. |
format-string |
string | 0.## |
The number format of the values on the cells, in the legend and in the tooltips. |
interactive |
bool | true | Lets the pointer and the keys highlight and select cells. |
animate |
bool | true | Eases the cells to the colors of new values. |
When all values are equal, all cells take the low color.
Properties and methods
| Member | Description |
|---|---|
Values, RowLabels, ColumnLabels, MinValue, MaxValue, Steps, LowColor, MidColor, HighColor, ShowValues, ShowLegend, FormatString, Interactive, Animate |
The settings above. |
Rows, Columns |
The size of the grid. |
GetValue(row, column), SetValue(row, column, value) |
Reads or sets one cell. NaN is a cell without a value. A row or a column out of the grid throws. |
SetData(float[,] values) |
Replaces the values with a grid of rows and columns. |
SetData(values, columns) |
Replaces the values with a list that goes row after row, columns values to a row. |
ClearValues() |
Removes all the values. |
Range |
The values at the low and the high color, fitted or fixed. |
ColorOf(value) |
The color of a cell with this value on the scale now. |
SelectedRow, SelectedColumn, SelectCell(row, column), ClearSelection() |
The selected cell, -1 when there is none. A row or a column out of the grid clears the selection. |
HoveredRow, HoveredColumn |
The cell under the pointer, -1 when there is none. |
SetData with values equal to the values changes nothing, so a call each frame with the same grid is free. New values of the same size keep the selection; a new size keeps the selected row and column while they are in the grid.
Events
| Event | Sent when |
|---|---|
CellSelected(row, column) |
A click, a key or SelectCell selects a cell, or the selection is cleared (-1, -1). |
CellHovered(row, column) |
The pointer moves onto a cell, or off the cells (-1, -1). |
CellClicked(row, column) |
A cell is clicked, or Enter, Space or the submit button of a gamepad is pressed while a cell is selected. |
Mouse and keyboard
| Input | Does |
|---|---|
| Pointer over a cell | Draws a thin frame around the cell, and the tooltip of the cells shows its row, column and value. |
| Click | Selects the cell, or clears the selection when the cell is selected. Sends CellClicked. |
| Arrow keys, D-pad, left stick | The first press selects the first cell; then the selection moves. At an edge of the grid the focus moves on. |
| Home, End | The first or the last cell of the row. |
| Page Up, Page Down | The same column in the first or the last row. |
| Enter, Space, submit | Sends CellClicked for the selected cell. |
| Escape, cancel | Clears the selection. |
The heat map takes the focus; the border around the cells takes the accent color while it has it.
Performance
- All cells are one mesh of plain rectangles, with no rounded corners, so a grid of 10,000 cells draws as fast as a few.
- At rest the heat map does no work, and no scheduled item runs. The ease to new colors runs only while a cell changes color.
SetDatawith equal values,SetValueand the draw allocate nothing. The labels follow once a frame, so a loop ofSetValuecalls updates them once, and the text of a value is made once and kept while the value stays.- The names are measured once after the names, their number or the style change, a frame after the change. A new size of the map picks the names that show from the kept sizes, with no measure and no garbage.
show-valuesadds one label for each cell. For a large grid, leave it off: the tooltip andCellHoveredgive the value under the pointer.
Styling
| Class | Element |
|---|---|
tb-heat-map |
The heat map. It grows, and is at least 120 pixels high. |
tb-heat-map--empty |
The heat map while it has no values. The legend hides. |
tb-heat-map__row-labels, tb-heat-map__row-label |
The column of row names, and each name. |
tb-heat-map__column-labels, tb-heat-map__column-label |
The row of column names, and each name. |
tb-heat-map__plot |
The cells. Its border shows the focus. |
tb-heat-map__value-label |
The value on a cell. tb-heat-map__value-label--on-light is the value on a light cell. |
tb-heat-map__legend, tb-heat-map__legend-bar, tb-heat-map__legend-label |
The legend, its color bar, and the lowest and the highest value. |
| Variable | On | Description |
|---|---|---|
--tb-heat-map-low |
tb-heat-map |
The color of the lowest value. Default --tb-color-surface-alt. |
--tb-heat-map-mid |
tb-heat-map |
The color of the middle of the range, for a scale of three colors. Not set by default. |
--tb-heat-map-high |
tb-heat-map |
The color of the highest value. Default --tb-color-accent. |
--tb-heat-map-empty |
tb-heat-map |
The color of a cell without a value. Default a faint gray. |
--tb-heat-map-selection |
tb-heat-map |
The frame of the selected cell and of the cell under the pointer. Default --tb-color-text. |
--tb-heat-map-cell-spacing |
tb-heat-map |
The gap between two cells in pixels, written without a unit. Default 2. |
A scale from blue through white to red, for a change above and below 0, with no gaps:
.balance-map {
--tb-heat-map-low: rgb(59, 110, 200);
--tb-heat-map-mid: rgb(240, 240, 240);
--tb-heat-map-high: rgb(210, 70, 60);
--tb-heat-map-cell-spacing: 0;
}
In the UI Builder, a heat map without values shows a sample grid. The sample does not show in Play mode or in a build, and the UI Builder does not save it to the UXML file.
The HeatMapDemo scene shows the deaths of each match on the grid of a map, the players online in each hour of a week, a damage table of weapons against armor with fixed ends, and four looks. A status line under the map tells the selected cell and the cell under the pointer.