demo D194
Variation along an ordering in Vue
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.
This is the Vue 3 version. A createLatticeGrid component takes the configuration through v-bind, and reactive data flows straight into the grid, so it updates the way the rest of your Vue app does.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<style>
#grid > div { height: 460px; }
</style>
<div id="app"></div>
<script type="module">
import * as Vue from 'https://esm.sh/vue@3/dist/vue.esm-browser.prod.js';
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/vue.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
return {
config: {
rowKey: 'id',
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'date', title: 'Date', type: 'date', layout: { pin: 'start', width: 150 } },
{ field: 'price', title: 'Price', type: 'number' },
],
rows,
},
};
},
mounted() {
// The component exposes the live grid via a template ref, which every figure reads.
const grid = this.$refs.grid.grid();
const out = document.getElementById('out');
const report = () => {
// by is required: reductions see rows as loaded, not in the grid's sort.
out.textContent = JSON.stringify(
grid.statistics.series('price', { by: 'date', periodsPerYear: 252 }), null, 2);
};
grid.on('filter:changed', report); // every figure follows the filters
report();
},
template: `
<div id="grid"><lattice-grid ref="grid" v-bind="config" /></div>
<pre id="out" style="margin-top: 12px"></pre>
`,
}).mount('#app');
</script>