demo D211
Analytical chemistry in React
Molarity, ppb and dose types, with a contaminated batch the rules find
type: molarity · ppb · doseRate
This is an analytical chemistry sheet with molarity, parts-per-billion and dose-rate types, and a contaminated batch that the rules find. It shows domain units and inline rules catching a real problem in scientific data.
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="grid"></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 createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/react.esm.min.js';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const columns = [
{ field: 'sample', title: 'Sample', layout: { pin: 'start', width: 120 } },
{ field: 'batch', title: 'Batch', filter: { type: 'set' } },
// Each reading is its own unit type: molarity, parts per billion,
// temperature, radioactivity and dose rate, all sortable and totalled.
{ field: 'concentration', title: 'Concentration', type: 'molarity', total: 'median' },
{ field: 'contaminant', title: 'Contaminant', type: 'ppb', total: 'p95' },
{ field: 'temperature', title: 'Temp', type: 'celsius', total: 'avg' },
{ field: 'activity', title: 'Activity', type: 'radioactivity' },
{ field: 'doseRate', title: 'Dose rate', type: 'doseRate', total: 'max' },
];
const formatting = {
// The z-score and outlier rules read the whole column, so a contaminated
// batch is flagged whatever the sort order.
contaminant: [
{ id: 'c-z', when: { op: 'zAbove', value: 3 }, style: { background: '#fbeceb', color: '#a4262c' } },
{ id: 'c-out', when: { op: 'outlier' }, style: { background: '#fff4e5' } },
],
};
const rows = [/* lab samples: sample, batch, concentration, contaminant, temperature, activity, doseRate */];
function App() {
return (
<LatticeGrid
rowKey="id"
columnDefaults={{ filter: true }}
toolPanel={{ side: 'left', panels: ['columns', 'filters', 'statistics'] }}
formatting={formatting}
columns={columns}
rows={rows}
style={{ height: '480px' }}
/>
);
}
createRoot(document.getElementById('grid')).render(<App />);
</script>