demo D189
Quantile colour scales in htmx
A scale that ignores the outlier flattening it
scale: { from: 'quantile' }
This grid shades a column by quantile rather than by raw range, so one extreme value does not flatten the colour for everything else. It keeps a heat map readable when the data is skewed, spreading colour by rank so the middle of the distribution still shows contrast.
This is the htmx version. A server-rendered table is upgraded in place, so the page is readable before any script runs and gains the full grid when the module loads, which suits a progressively enhanced app.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<!-- A real, server-rendered table: readable with JavaScript off. data-field on
each header names the column that cell becomes, and data-id on each row is
the key the grid carries it under. -->
<table id="quantile-colour-scales-table" data-lattice-grid>
<thead>
<tr>
<th data-field="node">Node</th>
<th data-field="value">min-max scale</th>
</tr>
</thead>
<tbody>
<tr data-id="1"><td>node-001</td><td>3000</td></tr>
<tr data-id="2"><td>node-002</td><td>52</td></tr>
<tr data-id="3"><td>node-003</td><td>89</td></tr>
<!-- the rest of the rows, rendered by your server -->
</tbody>
</table>
<script type="module">
import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/htmx.esm.min.js';
// The markup carries the rows; a server-rendered table's column types are
// declared in the config hydrateTable takes. The grid replaces the table
// where it stood.
const grid = hydrateTable(document.getElementById('quantile-colour-scales-table'), {
// The same skewed column, two scales. A min-max scale is flattened by one
// large value; a quantile scale spans the 5th to 95th percentile instead.
formatting: {
'v-minmax': [{ scale: { from: 'minmax', colours: ['#f5f7fa', '#1a6bc7'] } }],
'v-quantile': [{ scale: { from: 'quantile', low: 5, high: 95, colours: ['#f5f7fa', '#1a6bc7'] } }],
},
columns: [
{ field: 'node', title: 'Node', layout: { pin: 'start', width: 150 } },
{ field: 'value', id: 'v-minmax', title: 'min-max scale', type: 'number' },
{ field: 'value', id: 'v-quantile', title: 'quantile scale', type: 'number' },
{ field: 'value', title: 'value', type: 'number' },
],
});
</script>