demo D253
Series decomposition in React
Read a series as its trend, its seasonal rhythm and the residual, stacked to compare
type: 'decomposition', trend, seasonal, residual
This reads a series as its trend, its seasonal rhythm and the residual, stacked to compare. It pulls apart what is a long-term direction, what is a repeating pattern, and what is noise, so each can be judged on its own.
This is the React version. The grid mounts through the createLatticeGrid adapter, which takes its configuration as ordinary props and hands back the live grid through a ref. The grid below is the same one every other tab runs.
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.min.css">
<div id="app"></div>
<script type="module">
import React from 'https://esm.sh/react@18';
import { createRoot } from 'https://esm.sh/react-dom@18/client';
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.esm.min.js';
import { createLatticeReact } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/react.esm.min.js';
import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/charts.esm.min.js';
import 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/chart-decomposition.esm.min.js'; // opt in to the decomposition type
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const columns = [
{ field: 'month', title: 'Month' },
{ field: 'observed', title: 'Observed', type: 'number' },
{ field: 'trend', title: 'Trend', type: 'number' },
{ field: 'seasonal', title: 'Seasonal', type: 'number' },
{ field: 'residual', title: 'Residual', type: 'number' },
];
const rows = [/* a series split into its parts: month, observed, trend, seasonal, residual */];
function App() {
const [grid, setGrid] = React.useState(null);
return (
<>
{grid && (
<LatticeChart grid={grid} type="decomposition" observed="observed" trend="trend" seasonal="seasonal" residual="residual" title="A series and its parts" style={{ height: '400px' }} />
)}
<LatticeGrid
rowKey="id"
columns={columns}
rows={rows}
onGridReady={setGrid}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>