{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stock-sawtooth",
  "type": "registry:component",
  "title": "Stock sawtooth",
  "description": "Stock on hand, drawn down and refilled. Sample data: units on hand, Aug 11 to Oct 9, reorder point 300, one stockout.",
  "registryDependencies": [
    "@chartory/core",
    "@chartory/plot-sawtooth"
  ],
  "files": [
    {
      "path": "registry/chartory/components/stock-sawtooth.tsx",
      "type": "registry:component",
      "target": "components/chartory/stock-sawtooth.tsx",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// Stock sawtooth (Chartory chart 084): sizes xs | s | m | l, laid out again from the data at each\n// size; collection \"hearth\" (default) or \"signal\" (with @chartory/signal, Code and Complete). Data in the type's shape (default: the sample). Docs:\n// https://usechartory.com/docs/charts/stock-sawtooth\nimport { ChartView, type ChartViewProps } from \"@/lib/chartory/charts/chart-view\"\nimport { registerChart } from \"@/lib/chartory/charts/defs\"\nimport { data as sample } from \"@/lib/chartory/charts/types/084-stock-sawtooth/data\"\nimport { def } from \"@/lib/chartory/charts/types/084-stock-sawtooth/layout\"\n\nregisterChart(def, sample)\n\nexport type StockSawtoothData = typeof sample\nexport type StockSawtoothProps = Omit<ChartViewProps, \"def\" | \"data\" | \"states\"> & {\n  /** the data to draw (default: the sample) */\n  data?: StockSawtoothData\n  /** further data states: the chart morphs to them (update) or ticks through them (live, with interval) */\n  states?: StockSawtoothData[]\n}\n\nexport function StockSawtooth(props: StockSawtoothProps) {\n  return <ChartView def={def} {...props} />\n}\n"
    },
    {
      "path": "registry/chartory/charts/types/084-stock-sawtooth/data.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/084-stock-sawtooth/data.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 084 Stock level · sample data (Figma chart/084-sawtooth-stock).\nimport type { SawtoothData } from \"../../plots/sawtooth\";\n\nexport const data: SawtoothData = {\n  vals: [862, 804, 760, 717, 674, 614, 552, 484, 445, 386, 346, 306, 259, 197, 149, 84, 735, 678, 638, 588, 526, 469, 410, 361, 307, 249, 198, 131, 72, 710, 650, 565, 494, 406, 324, 243, 173, 102, 31, 0, 0, 0, 646, 607, 546, 481, 438, 380, 339, 291, 250, 191, 145, 799, 758, 705, 655, 596, 539, 474],\n  reorder: 300,\n  max: 1200,\n  ticks: [\"1,200\", \"800\", \"400\", \"0\"],\n  arrivals: [16, 29, 42, 53],\n  xl: { 0: \"AUG 11\", 30: \"SEP 10\", 59: \"OCT 9\" },\n};\n"
    },
    {
      "path": "registry/chartory/charts/types/084-stock-sawtooth/layout.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/084-stock-sawtooth/layout.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 084 Stock sawtooth (Figma chart/084-sawtooth-stock): C.sawtooth on 60 days of units on hand.\nimport type { ChartDef } from \"../../core/shell\";\nimport { sawtooth } from \"../../plots/sawtooth\";\nimport { data } from \"./data\";\n\nconst start = Date.UTC(2026, 7, 11);\nconst day = (i: number) => new Date(start + i * 864e5).toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"short\", timeZone: \"UTC\" });\nconst out = data.vals.filter((v) => v === 0).length;\n\n/** A later 60 days: each restock cycle runs higher or lower (whole units, same arrivals, same stockout days). */\nfunction update(d0: unknown, step: number): typeof data {\n  const d = d0 as typeof data;\n  let c = 0;\n  const vals = d.vals.map((v, i) => {\n    if (d.arrivals.includes(i)) c++;\n    return v === 0 ? 0 : Math.max(1, Math.min(d.max, Math.round(v * (1 + 0.14 * Math.sin(c * 1.9 + step * 1.3)))));\n  });\n  return { ...d, vals };\n}\n\nexport const def: ChartDef = {\n  no: 84,\n  slug: \"stock-sawtooth\",\n  legend: [[\"data/primary\", \"Units on hand\"], [\"status/warning\", \"Reorder point\"], [\"status/danger\", \"Stockout\"]],\n  plot: (K, p, w, d) => sawtooth(K, p, w, (d as typeof data | undefined) ?? data),\n  update,\n  describe: {\n    title: \"Stock level\",\n    summary: `Units on hand over ${data.vals.length} days from ${day(0)} to ${day(data.vals.length - 1)}, reorder point ${data.reorder}: ${data.arrivals.length} deliveries, one stockout of ${out} days, ${data.vals[data.vals.length - 1]} units at the end.`,\n    table: { head: [\"Day\", \"Units\", \"Delivery\"], rows: data.vals.map((v, i) => [day(i), v, data.arrivals.includes(i) ? \"yes\" : \"\"]) },\n  },\n};\n"
    }
  ],
  "categories": [
    "charts",
    "change-over-time"
  ],
  "meta": {
    "access": "free",
    "no": 84,
    "family": "Change over time"
  }
}
