{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "semi-donut",
  "type": "registry:component",
  "title": "Semi donut",
  "description": "A split under one headline number. Sample data: 3,412 orders by channel, web 52%, app 28%, market 14%, retail 7%.",
  "registryDependencies": [
    "@chartory/core",
    "@chartory/plot-semi-donut"
  ],
  "files": [
    {
      "path": "registry/chartory/components/semi-donut.tsx",
      "type": "registry:component",
      "target": "components/chartory/semi-donut.tsx",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// Semi donut (Chartory chart 018): 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/semi-donut\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/018-semi-donut/data\"\nimport { def } from \"@/lib/chartory/charts/types/018-semi-donut/layout\"\n\nregisterChart(def, sample)\n\nexport type SemiDonutData = typeof sample\nexport type SemiDonutProps = Omit<ChartViewProps, \"def\" | \"data\" | \"states\"> & {\n  /** the data to draw (default: the sample) */\n  data?: SemiDonutData\n  /** further data states: the chart morphs to them (update) or ticks through them (live, with interval) */\n  states?: SemiDonutData[]\n}\n\nexport function SemiDonut(props: SemiDonutProps) {\n  return <ChartView def={def} {...props} />\n}\n"
    },
    {
      "path": "registry/chartory/charts/types/018-semi-donut/data.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/018-semi-donut/data.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 018 Semi donut · sample data (Figma chart/018, e-commerce: orders by channel).\nimport type { SemiDonutData } from \"../../plots/semi-donut\";\n\nexport const data: SemiDonutData = {\n  caps: \"ORDERS\",\n  value: \"3,412\",\n  items: [\n    {  label: \"Web\", v: 118, tok: \"data/cat-1\"  },\n    {  label: \"App\", v: 64, tok: \"data/cat-2\"  },\n    {  label: \"Market\", v: 31, tok: \"data/cat-3\"  },\n    {  label: \"Retail\", v: 15, tok: \"data/cat-5\"  },\n  ],\n};\n"
    },
    {
      "path": "registry/chartory/charts/types/018-semi-donut/layout.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/018-semi-donut/layout.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 018 Semi donut (Figma chart/018): C.semiDonut; no card legend (the plot carries its own legend with the shares).\nimport type { ChartDef, TooltipSpec } from \"../../core/shell\";\nimport { semiDonut } from \"../../plots/semi-donut\";\nimport { data } from \"./data\";\nimport { frame, type Frame, type Text } from \"../../core/node\";\n\n/** Deterministic wave in [-1, 1] per index and update step (no randomness: the same step gives the same period). */\nconst wave = (i: number, step: number, f = 1.7) => Math.sin(step * 2.3 + i * f + 0.5);\n/** A text is named by its characters, so an update state takes the sample's text names (same order): its value\n *  labels then stay the same marks and morph in place instead of reading as new ones. */\nfunction keepNames(pl: Frame, ref: Frame): Frame {\n  const texts = (f: Frame): Text[] => f.children.flatMap((c) => (c.removed ? [] : c.kind === \"text\" ? [c] : c.kind === \"frame\" ? texts(c) : []));\n  const a = texts(pl), b = texts(ref);\n  if (a.length === b.length) a.forEach((t, i) => { if (t.name === t.text.slice(0, 40)) t.name = b[i].name; });\n  return pl;\n}\n\nconst tot = data.items.reduce((a, s) => a + s.v, 0);\nconst pct = (v: number) => Math.round((v / tot) * 100) + \"%\";\n\n/** Hover tooltip: one channel's segment and its share of orders. */\nconst tip = (d: unknown, g: number): TooltipSpec => {\n  const o = d as typeof data, tot = o.items.reduce((a, s) => a + s.v, 0), s = o.items[g];\n  return { kind: \"value\", text: `${s.label} · ${Math.round((s.v / tot) * 100)}% of orders` };\n};\n\nexport const def: ChartDef = {\n  no: 18,\n  slug: \"semi-donut\",\n  legend: null,\n  plot: (K, p, w, d) => {\n    const o = (d as typeof data | undefined) ?? data;\n    const pl = semiDonut(K, p, w, o);\n    return o === data ? pl : keepNames(pl, semiDonut(K, frame(null, \"sample\"), w, data));\n  },\n  tip,\n  update: (d, step) => {\n    const o = d as typeof data;\n    // later weeks: each channel moves ±12 %; the order total follows the channel sum (the plot recomputes the shares)\n    const tot0 = o.items.reduce((a, s) => a + s.v, 0);\n    const items = o.items.map((s, i) => ({ ...s, v: Math.max(1, Math.round(s.v * (1 + 0.12 * wave(i, step)))) }));\n    const tot = items.reduce((a, s) => a + s.v, 0);\n    const orders = Math.round((Number(o.value.replace(/,/g, \"\")) * tot) / tot0);\n    return { ...o, items, value: orders.toLocaleString(\"en-US\") };\n  },\n  describe: {\n    title: \"Orders by channel\",\n    summary: `${data.value} orders by channel: ${data.items.map((s) => `${s.label} ${pct(s.v)}`).join(\", \")}.`,\n    table: { head: [\"Channel\", \"Share\"], rows: data.items.map((s) => [s.label, pct(s.v)]) },\n  },\n};\n"
    }
  ],
  "categories": [
    "charts",
    "part-of-a-whole"
  ],
  "meta": {
    "access": "free",
    "no": 18,
    "family": "Part of a whole"
  }
}
