{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "polar-area",
  "type": "registry:component",
  "title": "Polar area",
  "description": "Parts as wedges, sized by their value. Sample data: new trial signups by channel, organic 4.2K (30%), events 0.6K (4%).",
  "registryDependencies": [
    "@chartory/core",
    "@chartory/plot-polar"
  ],
  "files": [
    {
      "path": "registry/chartory/components/polar-area.tsx",
      "type": "registry:component",
      "target": "components/chartory/polar-area.tsx",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// Polar area (Chartory chart 019): 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/polar-area\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/019-polar-area/data\"\nimport { def } from \"@/lib/chartory/charts/types/019-polar-area/layout\"\n\nregisterChart(def, sample)\n\nexport type PolarAreaData = typeof sample\nexport type PolarAreaProps = Omit<ChartViewProps, \"def\" | \"data\" | \"states\"> & {\n  /** the data to draw (default: the sample) */\n  data?: PolarAreaData\n  /** further data states: the chart morphs to them (update) or ticks through them (live, with interval) */\n  states?: PolarAreaData[]\n}\n\nexport function PolarArea(props: PolarAreaProps) {\n  return <ChartView def={def} {...props} />\n}\n"
    },
    {
      "path": "registry/chartory/charts/types/019-polar-area/data.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/019-polar-area/data.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 019 Polar area · sample data (Figma chart/019, SaaS: new trial signups by channel in September, 13.8K in all).\nimport type { PolarData } from \"../../plots/polar\";\n\nconst items: [string, number, string][] = [\n  [\"Organic\", 4200, \"data/cat-1\"], [\"Paid search\", 3400, \"data/cat-2\"], [\"Referral\", 2600, \"data/cat-3\"],\n  [\"Social\", 1800, \"data/cat-4\"], [\"Partners\", 1200, \"data/cat-5\"], [\"Events\", 600, \"data/cat-6\"],\n];\nexport const data: PolarData = {\n  items: items.map(([label, v, tok]) => ({ label, v, tok, text: (v / 1000).toFixed(1) + \"K\", pct: Math.round(v / 138) + \"%\" })),\n};\n"
    },
    {
      "path": "registry/chartory/charts/types/019-polar-area/layout.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/019-polar-area/layout.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 019 Polar area (Figma chart/019, \"Signups by channel\"): C.polar with the channel list beside it.\nimport type { ChartDef, TooltipSpec } from \"../../core/shell\";\nimport { polar } from \"../../plots/polar\";\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/** Whole-percent shares that sum to 100 (largest remainder). */\nconst shares = (vs: number[]): number[] => {\n  const t = vs.reduce((a, b) => a + b, 0), raw = vs.map((v) => (v / t) * 100), out = raw.map(Math.floor);\n  const left = 100 - out.reduce((a, b) => a + b, 0);\n  raw.map((r, i) => [r - Math.floor(r), i]).sort((a, b) => b[0] - a[0]).slice(0, left).forEach(([, i]) => out[i]++);\n  return out;\n};\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\n/** Hover tooltip: one channel's sector (signups and share, as in the list). */\nconst tip = (d: unknown, g: number): TooltipSpec => {\n  const it = (d as typeof data).items[g];\n  return { kind: \"value\", text: `${it.label} · ${it.text} · ${it.pct}` };\n};\n\nexport const def: ChartDef = {\n  no: 19,\n  slug: \"polar-area\",\n  legend: null,\n  plot: (K, p, w, d) => {\n    const o = (d as typeof data | undefined) ?? data;\n    const pl = polar(K, p, w, o);\n    return o === data ? pl : keepNames(pl, polar(K, frame(null, \"sample\"), w, data));\n  },\n  tip,\n  update: (d, step) => {\n    const o = d as typeof data;\n    // later months: signups per channel move ±8 % (to the hundred); values and shares recomputed, shares sum to 100\n    const vs = o.items.map((it, i) => Math.max(100, Math.round((it.v * (1 + 0.08 * wave(i, step))) / 100) * 100));\n    const pc = shares(vs);\n    return { ...o, items: o.items.map((it, i) => ({ ...it, v: vs[i], text: (vs[i] / 1000).toFixed(1) + \"K\", pct: pc[i] + \"%\" })) };\n  },\n  describe: {\n    title: \"Signups by channel\",\n    summary: `13.8K new trial signups in September across six channels: Organic leads with ${data.items[0].text} (${data.items[0].pct}), Events is smallest with ${data.items[5].text} (${data.items[5].pct}).`,\n    table: { head: [\"Channel\", \"Signups\", \"Share\"], rows: data.items.map((it) => [it.label, it.v, it.pct ?? \"\"]) },\n  },\n};\n"
    }
  ],
  "categories": [
    "charts",
    "part-of-a-whole"
  ],
  "meta": {
    "access": "free",
    "no": 19,
    "family": "Part of a whole"
  }
}
