{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "star-ratings",
  "type": "registry:component",
  "title": "Star ratings",
  "description": "The average and how the stars split. Sample data: reviews averaging 4.3, 1,412 five-star and 82 one-star.",
  "registryDependencies": [
    "@chartory/core",
    "@chartory/plot-ratings"
  ],
  "files": [
    {
      "path": "registry/chartory/components/star-ratings.tsx",
      "type": "registry:component",
      "target": "components/chartory/star-ratings.tsx",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// Star ratings (Chartory chart 093): 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/star-ratings\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/093-star-ratings/data\"\nimport { def } from \"@/lib/chartory/charts/types/093-star-ratings/layout\"\n\nregisterChart(def, sample)\n\nexport type StarRatingsData = typeof sample\nexport type StarRatingsProps = Omit<ChartViewProps, \"def\" | \"data\" | \"states\"> & {\n  /** the data to draw (default: the sample) */\n  data?: StarRatingsData\n  /** further data states: the chart morphs to them (update) or ticks through them (live, with interval) */\n  states?: StarRatingsData[]\n}\n\nexport function StarRatings(props: StarRatingsProps) {\n  return <ChartView def={def} {...props} />\n}\n"
    },
    {
      "path": "registry/chartory/charts/types/093-star-ratings/data.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/093-star-ratings/data.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 093 Star ratings · sample data (Figma chart/093, e-commerce: product reviews in the last 90 days).\nimport type { RatingsData } from \"../../plots/ratings\";\n\nexport const data: RatingsData = {\n  avg: 4.3,\n  rows: [[5, 1412], [4, 612], [3, 214], [2, 98], [1, 82]],\n};\n"
    },
    {
      "path": "registry/chartory/charts/types/093-star-ratings/layout.ts",
      "type": "registry:lib",
      "target": "lib/chartory/charts/types/093-star-ratings/layout.ts",
      "content": "// SPDX-License-Identifier: MIT · Copyright (c) 2026 BEY AGENCY LTD · Chartory, usechartory.com\n// 093 Star ratings (Figma chart/093): C.ratings; no legend (the bars are labelled by star level).\nimport type { ChartDef, TooltipSpec } from \"../../core/shell\";\nimport { ratings } from \"../../plots/ratings\";\nimport { data } from \"./data\";\n\nconst total = data.rows.reduce((a, r) => a + r[1], 0);\n\n/** A later 90 days: review counts move, the average (one decimal, as shown) recomputed from them. */\nfunction update(d0: unknown, step: number): typeof data {\n  const d = d0 as typeof data;\n  const rows = d.rows.map(([s, n], i): [number, number] => [s, Math.round(n * (1 + 0.2 * Math.sin(i * 2.1 + step * 1.7 + 0.4)))]);\n  const avg = +(rows.reduce((a, [s, n]) => a + s * n, 0) / rows.reduce((a, r) => a + r[1], 0)).toFixed(1);\n  return { ...d, rows, avg: Math.min(4.9, Math.max(4.1, avg)) };\n}\n\n/** Hover: one star level (its bar and count): reviews and their share of all reviews. */\nfunction tip(d0: unknown, g: number): TooltipSpec | null {\n  const rows = (d0 as typeof data).rows, r = rows[g];\n  if (!r) return null;\n  const all = rows.reduce((a, x) => a + x[1], 0);\n  return { kind: \"value\", text: `${r[0]} star · ${r[1].toLocaleString(\"en-US\")} reviews · ${Math.round((100 * r[1]) / all)}%` };\n}\n\nexport const def: ChartDef = {\n  no: 93,\n  slug: \"star-ratings\",\n  legend: null,\n  plot: (K, p, w, d) => ratings(K, p, w, (d as typeof data | undefined) ?? data),\n  tip,\n  update,\n  describe: {\n    title: \"Review ratings\",\n    summary: `${total.toLocaleString(\"en-US\")} reviews with an average of ${data.avg.toFixed(1)} stars: ${data.rows.map(([s, n]) => `${s} star ${n.toLocaleString(\"en-US\")}`).join(\", \")}.`,\n    table: { head: [\"Rating\", \"Reviews\"], rows: data.rows.map(([s, n]) => [`${s} star`, n]) },\n  },\n};\n"
    }
  ],
  "categories": [
    "charts",
    "distribution"
  ],
  "meta": {
    "access": "free",
    "no": 93,
    "family": "Distribution"
  }
}
