{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "underwater-drawdown",
  "type": "registry:component",
  "title": "Underwater drawdown",
  "description": "How far below the last peak, and for how long. Sample data: fund drawdown, January to October, max −16.5%.",
  "registryDependencies": [
    "@chartory/core",
    "@chartory/plot-underwater"
  ],
  "files": [
    {
      "path": "registry/chartory/components/underwater-drawdown.tsx",
      "type": "registry:component",
      "target": "components/chartory/underwater-drawdown.tsx",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// Underwater drawdown (Chartory chart 080): 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/underwater-drawdown\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/080-underwater-drawdown/data\"\nimport { def } from \"@/lib/chartory/charts/types/080-underwater-drawdown/layout\"\n\nregisterChart(def, sample)\n\nexport type UnderwaterDrawdownData = typeof sample\nexport type UnderwaterDrawdownProps = Omit<ChartViewProps, \"def\" | \"data\" | \"states\"> & {\n  /** the data to draw (default: the sample) */\n  data?: UnderwaterDrawdownData\n  /** further data states: the chart morphs to them (update) or ticks through them (live, with interval) */\n  states?: UnderwaterDrawdownData[]\n}\n\nexport function UnderwaterDrawdown(props: UnderwaterDrawdownProps) {\n  return <ChartView def={def} {...props} />\n}\n"
    },
    {
      "path": "registry/chartory/charts/types/080-underwater-drawdown/data.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/080-underwater-drawdown/data.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 080 Underwater drawdown · sample data (Figma chart/080-underwater-fund, fintech: a fund's weekly drawdown from its\n// running peak, Jan to Oct; the seeded series from the definition, expanded).\nimport type { UnderwaterData } from \"../../plots/underwater\";\n\nconst vals = [\n  -1.81, -0.16, -0.43, -0.7, -1.42, -1.34, 0, -1.46, -3.36, -6.49, -6.68, -7.28, -6.65, -5.74, -8.88, -8.74, -10.3, -9.51, -12.36, -14.04,\n  -15.48, -16.47, -15.74, -13.64, -11.23, -11.44, -10.7, -10.34, -10.65, -10.8, -9.57, -10.2, -8.99, -5.82, -6.47, -4.62, -3.42, -0.76, 0, 0,\n  -0.81, -1.86, -2.75, -4.18, -6.36, -4.13, -6.01, -4.82, -3.88, -2.85, -1.77, -1.72, -3.52, -1.93, -2.28, -0.81, -2.81, -1.46, -3.21, -3.76,\n];\nconst low = Math.min(...vals);\n\nexport const data: UnderwaterData = {\n  vals,\n  min: -20,\n  ticks: [\"0\", \"−5%\", \"−10%\", \"−15%\", \"−20%\"],\n  xl: { 0: \"JAN\", 20: \"APR\", 40: \"JUL\", 59: \"OCT\" },\n  mark: { i: vals.indexOf(low), text: \"MAX \" + low.toFixed(1).replace(\"-\", \"−\") + \"%\" },\n};\n"
    },
    {
      "path": "registry/chartory/charts/types/080-underwater-drawdown/layout.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/080-underwater-drawdown/layout.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 080 Underwater drawdown (Figma chart/080-underwater-fund): C.underwater on the fund's drawdown series.\nimport type { ChartDef, TooltipSpec } from \"../../core/shell\";\nimport { underwater } from \"../../plots/underwater\";\nimport { data } from \"./data\";\n\nconst pct = (v: number) => v.toFixed(2).replace(\"-\", \"−\") + \"%\";\nconst n = data.vals.length;\nconst sinceZero = n - 1 - data.vals.lastIndexOf(0);\n\n/** A later run of the fund: drawdowns deepen or recover smoothly (peaks stay at 0), the max chip follows the low. */\nfunction update(d0: unknown, step: number): typeof data {\n  const d = d0 as typeof data;\n  const vals = d.vals.map((v, i) => (v === 0 ? 0 : Math.max(d.min + 0.5, +(v * (1 + 0.16 * Math.sin(i / 9 + step * 1.4))).toFixed(2))));\n  const low = Math.min(...vals);\n  return { ...d, vals, mark: { i: vals.indexOf(low), text: \"MAX \" + low.toFixed(1).replace(\"-\", \"−\") + \"%\" } };\n}\n\n/** Hover: the max drawdown marker (dot and chip): its period and depth. */\nfunction tip(d0: unknown, g: number): TooltipSpec | null {\n  const d = d0 as typeof data;\n  return g === 1 ? { kind: \"value\", text: `Max drawdown · week ${d.mark.i + 1} · ${pct(d.vals[d.mark.i])}` } : null;\n}\n\nexport const def: ChartDef = {\n  no: 80,\n  slug: \"underwater-drawdown\",\n  legend: [[\"status/danger\", \"Drawdown\"]],\n  plot: (K, p, w, d) => underwater(K, p, w, (d as typeof data | undefined) ?? data),\n  tip,\n  update,\n  describe: {\n    title: \"Drawdown from peak\",\n    summary: `Drawdown from the running peak over ${n} periods from January to October: deepest ${pct(data.vals[data.mark.i])} at period ${data.mark.i + 1}, now ${pct(data.vals[n - 1])}, ${sinceZero} periods since the last peak.`,\n    table: { head: [\"Period\", \"Drawdown\"], rows: data.vals.map((v, i) => [i + 1, pct(v)]) },\n  },\n};\n"
    }
  ],
  "categories": [
    "charts",
    "change-over-time"
  ],
  "meta": {
    "access": "free",
    "no": 80,
    "family": "Change over time"
  }
}
