Lattice Grid Buy a licence

demo D228

Confidence intervals, charted

The mean lead time of each supplier with its 95% interval as a whisker, and a tile that narrows as you filter

grid.statistics.interval(col) · chart error: true

Building…
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>
  #chart { height: 250px; }
  #tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
  #grid > div { height: 340px; }
</style>
<div id="app"></div>

<script type="module">
  import * as Vue from 'https://esm.sh/vue@3';
  import { createGrid, createStat } 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';
  import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/charts.esm.min.js';

  const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });

  Vue.createApp({
    components: { LatticeGrid },
    data() {
      return {
        config: {
          rowKey: 'id',
          toolPanel: { side: 'left', panels: ['filters', 'columns', 'statistics'] },
          columns: [
            { field: 'supplier', title: 'Supplier', filter: { type: 'set' } },
            { field: 'days', title: 'Lead time', type: 'number', format: { suffix: ' d', maximumFractionDigits: 1 }, total: 'avg' },
          ],
          rows,  // e.g. [{ id: 'O0', supplier: 'Kestrel', days: 3.1 }, ...]
        },
      };
    },
    mounted() {
      // The component exposes the live grid via a template ref: the tile and the
      // chart both read that one instance, so both follow the filters.
      const grid = this.$refs.grid.grid();

      // interval() is the range the mean is pinned to, computed over the filtered
      // rows. The tile shows it under the value; ask for a proportion with
      // { kind: 'proportion' } and a rule for what counts as a success.
      const tile = document.getElementById('tiles').appendChild(document.createElement('div'));
      createStat({ grid, container: tile, title: 'Mean lead time', of: 'days', fn: 'avg',
        interval: (value, grid) => grid.statistics.interval('days'), footer: '95% confidence interval' });

      // error: true draws each mean's interval as a whisker, computed from the
      // readings behind the bar.
      createChart({ grid, container: '#chart', type: 'bar', x: 'supplier', y: { col: 'days', fn: 'avg' },
        error: true, title: 'Mean lead time by supplier, with 95% confidence interval' });
    },
    template: `
      <div id="chart"></div>
      <div id="tiles"></div>
      <div id="grid"><lattice-grid ref="grid" v-bind="config" /></div>
    `,
  }).mount('#app');
</script>