demo D248
Alluvial flow in React
Follow a measure as it flows from one category into another, ribbon by ribbon
type: 'alluvial', source, target, value
This follows a measure as it flows from one category into another, ribbon by ribbon. It shows how a total redistributes between two groupings, so a shift in the mix reads as the width of each ribbon.
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-alluvial.esm.min.js'; // opt in to the alluvial type
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const columns = [
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'status', title: 'Status', filter: { type: 'set' } },
{ field: 'bandwidth', title: 'Bandwidth', type: 'number' },
{ field: 'utilisation', title: 'Utilisation', type: 'number', format: { decimals: 1, suffix: '%' } },
{ field: 'charge', title: 'Monthly charge', type: 'number',
format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
];
const rows = [/* circuits: region, status, bandwidth, utilisation, charge */];
function App() {
const [grid, setGrid] = React.useState(null);
return (
<>
{grid && (
<LatticeChart grid={grid} type="alluvial" source="region" target="status" value="charge" title="Charge from region to status" style={{ height: '320px' }} />
)}
<LatticeGrid
rowKey="id"
columns={columns}
rows={rows}
onGridReady={setGrid}
style={{ height: '340px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>