Lattice Grid Buy a licence

demo D194

Variation along an ordering in Svelte

Volatility, growth and drawdown, from rows loaded out of order

grid.statistics.series(col, { by })

This grid computes volatility, growth and drawdown along an ordering, even from rows loaded out of order. It reads a series' behaviour over its own sequence, so trend and swings surface without the data arriving pre-sorted.

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',
    toolPanel: { side: 'left', panels: ['filters', 'columns'] },
    columns: [
      { field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
      { field: 'price', title: 'Price', type: 'number' },
    ],
    rows,
    // onGrid hands over the live grid the moment it is created. by is required:
    // reductions see rows as loaded, not in the grid's sort. Every figure follows
    // the filters, so narrow the rows and the series moves.
    onGrid: (grid) => {
      const report = () => {
        out = JSON.stringify(
          grid.statistics.series('price', { by: 'date', periodsPerYear: 252 }), 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>