theme = Generators.observe(notify => {const read = () => {const css =getComputedStyle(document.body);const v = (name, fallback) => (css.getPropertyValue(name).trim() || fallback);return {dark:document.body.classList.contains("quarto-dark"),fg:v("--bs-body-color","#212529"),bg:v("--bs-body-bg","#ffffff"),muted:v("--bs-secondary-color","#6c757d"),grid:v("--bs-border-color","#dee2e6"),primary:v("--bs-link-color","#0d6efd"),accent:v("--bs-danger","#dc3545"),good:v("--bs-success","#198754") }; };// Quarto swaps stylesheets when the theme changes, and the new variables apply only once// the stylesheet has loaded; read them again shortly after, and keep the last reading.let last ="";const emit = () => {const t =read();const key =JSON.stringify(t);if (key !== last) { last = key;notify(t); } };const update = () => { emit();setTimeout(emit,100);setTimeout(emit,400); };update();const observer =newMutationObserver(update); observer.observe(document.body, {attributes:true,attributeFilter: ["class"]});return () => observer.disconnect();})
plotStyle = ({// "inherit" takes the page's text color directly, so axes and labels follow a theme// switch even before the plot redraws.color:"inherit",background:"transparent",fontSize:"13px",overflow:"visible"})
themedButton = (label, counterLabel =null) => {const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`;// The counter shows which run is on screen, so every press visibly does something and a// reader can tell runs apart. It reads 1 at page load and after Reset.const counter = counterLabel?html`<span class="bisc-run-counter" aria-live="polite"></span>`:null;const form =html`<form class="bisc-explorer-control">${button}${counter ||""}</form>`;const show = () => { if (counter) counter.textContent=`${counterLabel}${form.value+1}`; }; form.value=0;show(); button.onclick= () => { form.value+=1; form.dispatchEvent(newEvent("input", {bubbles:true})); };// Reset sets the value back to 0 and dispatches input; refresh the counter either way. form.addEventListener("input", show);return form;}
resetButton = (controls, label ="Reset to the starting values") => {// This runs once per page, because the cell that calls it depends on the controls// themselves (viewof), not on their values; so these are the values at page load.const start = controls.map(c => c.value);const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`; button.onclick= () => { controls.forEach((c, k) => { c.value= start[k]; c.dispatchEvent(newEvent("input", {bubbles:true})); }); };returnhtml`<div style="margin: 0.5rem 0">${button}</div>`;}
// A small seeded generator (mulberry32), so a run can be repeated.makeRandom = (seed) => {let a = seed >>>0;return () => { a = (a +0x6D2B79F5) >>>0;let t = a; t =Math.imul(t ^ (t >>>15), t |1); t ^= t +Math.imul(t ^ (t >>>7), t |61);return ((t ^ (t >>>14)) >>>0) /4294967296; };}
This explorer builds the ABC classification of Chapter 2 from an item file you can edit, with the two cut points on sliders. Items are ranked by annual dollar usage, \(\lambda_i c_i\), the shares are accumulated down the ranking, and each cut ends its class at the item whose cumulative share comes closest to it. Move the cuts and watch how much of the money each class holds, and how many items you would be reviewing to watch it.
The page starts from the chapter’s twelve items; Reset returns to them. It runs in your browser and records nothing.
import {classify} from"./explorers/lib/abc.js"result = {const problems = [];const lines = text.split("\n").map(s => s.trim()).filter(Boolean);const items = lines.map((s, n) => {const parts = s.split(/[,\t]+/).map(x => x.trim());const lambda =Number(parts[1]), c =Number(parts[2]);if (parts.length!==3||!parts[0] ||!Number.isFinite(lambda) ||!Number.isFinite(c) || lambda <0|| c <0) problems.push(`Line ${n +1} needs a name, an annual demand and a unit cost, separated by commas, with the numbers 0 or more.`);return {label: parts[0], lambda, c}; });if (!lines.length) problems.push("Enter at least one item.");if (lines.length>500) problems.push(`There are ${lines.length} items; this page takes at most 500.`);if (cutB < cutA) problems.push("The B cut must be at least the A cut.");if (problems.length) return {ok:false, problems};try { return {ok:true,r:classify(items, cutA /100, cutB /100)}; }catch (e) { return {ok:false,problems: [e.message.charAt(0).toUpperCase() + e.message.slice(1) +"."]}; }}
{if (!result.ok) {returnhtml`<div class="callout callout-style-simple callout-warning"><div class="callout-body"> <p><strong>The page cannot classify these items.</strong></p> <ul>${result.problems.map(p =>html`<li>${p}</li>`)}</ul></div></div>`; }const {r} = result;const dollars = x =>"$"+ x.toLocaleString("en-US", {maximumFractionDigits:2});const pct = x => (100* x).toFixed(1) +"%";returnhtml`<table class="table table-sm" style="max-width: 30rem"> <thead><tr><th>Class</th><th>Items</th><th>Share of items</th><th>Share of value</th></tr></thead> <tbody>${r.summary.map(s =>html`<tr><td>${s.cls}</td><td>${s.count}</td><td>${pct(s.itemShare)}</td><td>${pct(s.valueShare)}</td></tr>`)}</tbody> </table> <p>Total annual dollar usage is ${dollars(r.total)}.</p> <div style="max-height: 24rem; overflow: auto; max-width: 100%"> <table class="table table-sm" style="font-size: 0.9rem; white-space: nowrap"> <thead><tr><th>Rank</th><th>Item</th><th>λ</th><th>c</th><th>Dollar usage</th><th>Cumulative %</th><th>Class</th></tr></thead> <tbody>${r.ranked.map(it =>html`<tr style="${it.rank=== r.endA|| it.rank=== r.endB?"font-weight: 600":""}"><td>${it.rank}</td><td>${it.label}</td> <td>${it.lambda.toLocaleString("en-US")}</td><td>${dollars(it.c)}</td><td>${dollars(it.usage)}</td><td>${pct(it.share)}</td><td>${it.cls}</td></tr>`)}</tbody> </table></div> <p>The bold rows end classes A and B: each is the item whose cumulative share is nearest its cut.</p>`;}
The plot is the cumulative curve: the share of dollar usage against the share of items, with the cuts as dashed lines and each item’s point in its class’s color. The diagonal is what an item file with no concentration would look like.
result.ok? (() => {const {r} = result, n = r.ranked.length;const pts = [{x:0,y:0,cls:"start"},...r.ranked.map((it, i) => ({x:100* (i +1) / n,y:100* it.share,cls: it.cls,label: it.label}))];return Plot.plot({style: plotStyle,height:300,marginLeft:55,marginBottom:45,x: {label:"Cumulative share of items (%)",labelAnchor:"center",labelOffset:38,domain: [0,100],grid:true},y: {label:"Cumulative share of value (%)",domain: [0,100],grid:true},color: {domain: ["A","B","C"],range: [theme.accent, theme.primary, theme.muted],legend:true},marks: [ Plot.line([[0,0], [100,100]], {stroke: theme.grid}), Plot.ruleY([cutA, cutB], {stroke: theme.muted,strokeDasharray:"5,3"}), Plot.line(pts, {x:"x",y:"y",stroke: theme.fg,strokeWidth:1}), Plot.dot(pts.slice(1), {x:"x",y:"y",fill:"cls",r:4,title: d =>`${d.label}: ${d.y.toFixed(1)}%`}) ],ariaLabel:"The cumulative curve of dollar usage",ariaDescription:`Class A holds ${r.summary[0].count} items and ${(100* r.summary[0].valueShare).toFixed(1)}% of the value.` });})() :html``
Things to Try
Start at the conventional cuts, 80% and 95%. Class A is IT-01 to IT-03, 25% of the items and 81.6% of the value; B is IT-04 to IT-06, 13.2%; C is the other six, 5.2%. IT-03 ends class A because its 81.6% is nearer 80% than IT-02’s 69.3%.
Raise the A cut to 85%. IT-04’s 88.1% is now nearer than 81.6%, so class A takes a third of the items and 88.1% of the value: the extra six and a half points of value cost one more item to review.
Lower the A cut to 75%, and then to 70%. Both give two items and 69.3%, because 69.3% is nearer either cut than 81.6%. Nothing in the data says where to stop.
Raise IT-08’s unit cost from $0.15 to $0.60, a price change on an item that costs fifteen cents. Its dollar usage rises to $10,800 and it moves from class C to class B, fifth in the ranking, while IT-06 drops into C.
Check What You Found
Check what you found
1. On the chapter’s twelve items, an A cut at 75% and an A cut at 70% both give class A two items and 69.3% of the value, and a cut at 85% gives four items and 88.1%. What does that say about the cut points?