demo D230
An SPC study: control, range, capability in Svelte
A drifting process with limits fixed on the first thirty readings, so the drift breaks a rule rather than being absorbed
chart type: control · movingRange · capability
This grid runs an SPC study, control, moving range and capability, with limits fixed on the first thirty readings so a later drift breaks a rule rather than being absorbed. It shows a process going out of control being caught, not smoothed over.
This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.
The configuration
<script>
import { createGrid, createStat } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/svelte.esm.min.js';
import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';
const lattice = createLatticeAction({ createGrid });
let tilesEl, controlEl, mrEl, capEl;
const config = {
rowKey: 'id',
toolPanel: { side: 'left', panels: ['columns', 'statistics'] },
columns: [
{ field: 'n', title: '#', type: 'number' },
// The tolerance is declared once, on the column; every SPC figure reads it.
{ field: 'bore', title: 'Bore', type: 'millimetres', spec: { lower: 9.95, upper: 10.05, target: 10 } },
],
rows, // measured parts, in the order they were made
// onGrid hands over the live grid the moment it is created. Every chart reads
// it, so all three follow the grid's filters and sort.
onGrid: (grid) => {
// Three figures read from the live grid: Cpk against the tolerance, the
// mean bore, and the count. baseline fixes the control limits on the first
// thirty readings, so the later drift breaks a rule.
const tile = () => { const d = document.createElement('div'); tilesEl.append(d); return d; };
createStat({ grid, container: tile(), title: 'Cpk',
value: (g) => g.statistics.capability('bore', { rules: 'nelson', baseline: 30 })?.cpk,
goodWhen: 'up', baseline: 1.33, decimals: 2, footer: '1.33 is the usual floor' });
createStat({ grid, container: tile(), title: 'Mean bore', of: 'bore', fn: 'avg' });
createStat({ grid, container: tile(), title: 'Readings', fn: 'count', footer: 'the first 30 set the limits' });
// baseline fixes the limits on the first 30 readings, so a later drift breaks
// a rule rather than widening the limits to absorb it.
createChart({ grid, container: controlEl, type: 'control', y: 'bore', baseline: 30, rules: 'nelson',
title: 'Control chart, limits fixed on the first 30 readings' });
createChart({ grid, container: mrEl, type: 'movingRange', y: 'bore', title: 'Moving range' });
createChart({ grid, container: capEl, type: 'capability', y: 'bore', title: 'Capability against the tolerance' });
},
};
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
</svelte:head>
<div bind:this={tilesEl} style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px"></div>
<div bind:this={controlEl} style="height: 220px; margin-top: 12px"></div>
<div style="display: flex; gap: 12px; margin-top: 12px">
<div bind:this={mrEl} style="flex: 1; height: 200px"></div>
<div bind:this={capEl} style="flex: 1; height: 200px"></div>
</div>
<div use:lattice={config} style="height: 320px; margin-top: 12px"></div>