Color scales
A color scale paints each cell’s background by interpolating a color from the value’s position in the column’s numeric domain (min → max). It is pure presentation: the engine ships the raw numbers, the frontend only picks a color. The domain is faceted over the whole tree, and the synthetic grand-total row is excluded so its sum can’t flatten the scale.
from dash_tensor_grid import TensorGrid, build_grid
payload = build_grid(sales, { "rows": ["region", "country"], "measures": {"revenue": "sum"}, "formats": {"revenue": "currency:USD"}, "conditional_formats": { "revenue": {"type": "colorScale", "colors": ["#fff5f5", "#2f9e44"]}, # Diverging (3 colors -> low / mid / high): "colors": ["#f8696b", "#ffeb84", "#63be7b"] },})TensorGrid(id="grid", row_data=payload["row_data"], column_defs=payload["column_defs"])<TensorGrid data={data} rows={['region', 'country']} measures={{ revenue: 'sum' }} formats={{ revenue: '$0,0' }} colorScales={{ revenue: { min: '#fff5f5', max: '#2f9e44' } }}/>;// Diverging on zero: { min: '#f8696b', mid: '#ffeb84', max: '#63be7b', domainMid: 0 }<TensorGrid :data="data" :rows="['region', 'country']" :measures="{ revenue: 'sum' }" :formats="{ revenue: '$0,0' }" :color-scales="{ revenue: { min: '#fff5f5', max: '#2f9e44' } }"/>mountTensorGrid(el, { data, rows: ['region', 'country'], measures: { revenue: 'sum' }, formats: { revenue: '$0,0' }, colorScales: { revenue: { min: '#fff5f5', max: '#2f9e44' } },});Options
Section titled “Options”min/max— the CSS hex colors at the low and high ends of the domain (two-stop scale).mid+domainMid— add amidcolor to make a diverging three-stop scale, and setdomainMidto the value the midpoint sits on (e.g.0for profit/loss, so red → white → green centers on zero). WithoutdomainMid, the split is the domain midpoint(min + max) / 2.domainMin/domainMax— fix the domain ends instead of the faceted min/max (useful to keep the scale stable as data changes, or to share one scale across columns).- A flat domain (every value equal) maps to the neutral stop rather than the extreme.
- For a proportional bar instead of a background tint, see data bars; for a discrete value → style, see style rules. All three are collected on the conditional formatting overview.