demo D252
Calendar heatmap in React
A year of daily figures as one square per day, so busy runs and quiet spells stand out
type: 'calendar', x, y
This draws a year of daily figures as one square per day, shaded by value. It makes busy runs and quiet spells across a year stand out at a glance, the way a contribution calendar does.
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-calendar.esm.min.js'; // opt in to the calendar type
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const columns = [
{ field: 'date', title: 'Date', type: 'dateString' },
{ field: 'orders', title: 'Orders', type: 'number', total: 'sum' },
];
const rows = [/* one row a day for a year: date, orders */];
function App() {
const [grid, setGrid] = React.useState(null);
return (
<>
{grid && (
<LatticeChart grid={grid} type="calendar" x="date" y="orders" title="Orders through the year" style={{ height: '240px' }} />
)}
<LatticeGrid
rowKey="id"
columns={columns}
rows={rows}
onGridReady={setGrid}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>