Lattice Grid Buy a licence

demo D193

Statistics without a panel in Svelte

Every figure available to your own interface, as an object

grid.statistics.*

This grid exposes every figure it computes as a plain object, for your own interface with no panel involved. It lets you take the statistics into a custom dashboard or export, so the numbers are available wherever you need them.

Building…
Loading a live grid…

This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.

The configuration

<script>
  import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
  import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/svelte.esm.min.js';

  const lattice = createLatticeAction({ createGrid });

  let out = '';

  const config = {
    rowKey: 'id',
    columnDefaults: { filter: true },
    toolPanel: { side: 'left', panels: ['filters', 'columns'] },
    columns: [
      { field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
      { field: 'desk', title: 'Desk', filter: { type: 'set' } },
      { field: 'region', title: 'Region', filter: { type: 'set' } },
      { field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
      { field: 'bid', title: 'Bid', type: 'number', format: { decimals: 4 } },
      { field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
      { field: 'notional', title: 'Notional', type: 'number',
        format: { style: 'currency', currency: 'USD', decimals: 2 }, total: 'sum' },
    ],
    rows,  // trading book: symbol, desk, region, price, bid, volume, notional
    // onGrid hands over the live grid the moment it is created. Profile,
    // correlation, regression, rank correlation and a weighted median are read
    // straight from the grid, and every figure follows the filters: narrow the
    // rows and they move.
    onGrid: (grid) => {
      const report = () => {
        out = JSON.stringify({
          profile:        grid.statistics.profile('notional'),
          correlation:    grid.statistics.correlation('price', 'bid'),
          regression:     grid.statistics.regression('price', 'bid'),
          spearman:       grid.statistics.spearman('price', 'bid'),
          weightedMedian: grid.statistics.weightedQuantile('price', 'volume', 0.5),
        }, null, 2);
      };
      grid.on('filter:changed', report);
      report();
    },
  };
</script>

<svelte:head>
  <link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
</svelte:head>

<div use:lattice={config} style="height: 460px"></div>
<pre style="margin-top: 12px">{out}</pre>