demo D183
Statistical values in a column
A column's median, deviation and percentile, read into computed columns
value.compute
Loading a live grid…
The configuration
<script>
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/svelte.esm.min.js';
const lattice = createLatticeAction({ createGrid });
let out = '';
const config = {
rowKey: 'id',
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'price', title: 'Price', type: 'number' },
],
rows,
// onGrid hands over the live grid the moment it is created. Each figure is
// read straight from the grid and follows the filters: narrow the rows and
// the median, standard deviation and 90th percentile all move.
onGrid: (grid) => {
const report = () => {
out = 'median ' + grid.statistics.reduce('price', 'median')
+ ' · stddev ' + grid.statistics.reduce('price', 'stddev')
+ ' · p90 ' + grid.statistics.reduce('price', 'p90');
};
grid.on('filter:changed', report); // every figure follows the filters
report();
},
};
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">
</svelte:head>
<div use:lattice={config} style="height: 460px"></div>
<pre style="margin-top: 12px">{out}</pre>