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
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">
<style>
#grid > div { height: 540px; }
</style>
<div id="grid"></div>
<script type="module">
import * as Vue from 'https://esm.sh/vue@3';
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/vue.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
// The column's median, mean, standard deviation and 90th percentile, read
// into computed columns that sort and filter like any other.
const prices = rows.map((r) => r.price).slice().sort((a, b) => a - b);
const n = prices.length;
const median = n % 2 ? prices[(n - 1) / 2] : (prices[n / 2 - 1] + prices[n / 2]) / 2;
const mean = prices.reduce((s, x) => s + x, 0) / n;
const sd = Math.sqrt(prices.reduce((s, x) => s + (x - mean) ** 2, 0) / n) || 1;
const p90 = prices[Math.floor(0.9 * (n - 1))];
return {
config: {
rowKey: 'id',
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
{ id: 'vsMedian', title: 'vs MEDIAN', type: 'number', format: { decimals: 4, signed: true },
value: { deps: ['price'], pure: true, compute: (d) => Math.round((d.price - median) * 1e4) / 1e4 } },
{ id: 'z', title: 'Z-score (STDEV)', type: 'number', format: { decimals: 2, signed: true },
value: { deps: ['price'], pure: true, compute: (d) => Math.round(((d.price - mean) / sd) * 100) / 100 } },
{ id: 'p90', title: 'over PERCENTILE 90', type: 'boolean',
value: { deps: ['price'], pure: true, compute: (d) => d.price > p90 } },
],
rows,
},
};
},
template: '<lattice-grid v-bind="config" />',
}).mount('#grid');
</script>