{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-pie-blood-types",
  "title": "Blood donations pie chart",
  "description": "Blood donations by ABO group against the population, as two rings.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-pie-blood-types.tsx",
      "content": "\"use client\"\n\nimport { Pie, PieChart } from \"recharts\"\n\nimport {\n  Card,\n  CardAction,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport { Badge } from \"@/components/ui/badge\"\nimport {\n  ChartContainer,\n  ChartTooltip,\n  ChartTooltipContent,\n  type ChartConfig,\n} from \"@/components/ui/chart\"\nimport { IconPlaceholder } from \"@/icons/icon-placeholder\"\n\nexport const description =\n  \"Blood donations by ABO group against the population, as two rings\"\n\n// Units donated this month, illustrative, and the share of people in each\n// group, roughly as in the UK. Use your own population's figures.\nconst groups = [\n  { type: \"o\", units: 412, population: 48 },\n  { type: \"a\", units: 356, population: 38 },\n  { type: \"b\", units: 98, population: 10 },\n  { type: \"ab\", units: 34, population: 4 },\n]\n\nconst units = groups.reduce((sum, { units }) => sum + units, 0)\nconst chartData = groups.map((group) => ({\n  ...group,\n  donated: Math.round((group.units / units) * 100),\n  fill: `var(--color-${group.type})`,\n}))\n\nconst chartConfig = {\n  donated: {\n    label: \"Donations\",\n  },\n  population: {\n    label: \"Population\",\n  },\n  o: {\n    label: \"O\",\n    color: \"var(--chart-1)\",\n  },\n  a: {\n    label: \"A\",\n    color: \"var(--chart-2)\",\n  },\n  b: {\n    label: \"B\",\n    color: \"var(--chart-3)\",\n  },\n  ab: {\n    label: \"AB\",\n    color: \"var(--chart-4)\",\n  },\n} satisfies ChartConfig\n\n// The group donated furthest below its share of the population.\nconst short = chartData.reduce((a, b) =>\n  b.donated - b.population < a.donated - a.population ? b : a\n)\nconst shortfall = short.donated < short.population\nconst label = chartConfig[short.type as keyof typeof chartConfig].label\n\nexport function ChartPieBloodTypes() {\n  return (\n    <Card className=\"flex flex-col\">\n      <CardHeader>\n        <CardTitle>Blood donations</CardTitle>\n        <CardDescription>Outer: units donated. Inner: people.</CardDescription>\n        <CardAction>\n          <Badge variant=\"outline\">\n            {shortfall ? (\n              <IconPlaceholder\n                lucide=\"TriangleAlertIcon\"\n                tabler=\"IconAlertTriangle\"\n                hugeicons=\"Alert02Icon\"\n                phosphor=\"WarningIcon\"\n                remixicon=\"RiAlertLine\"\n                data-icon=\"inline-start\"\n              />\n            ) : (\n              <IconPlaceholder\n                lucide=\"CheckIcon\"\n                tabler=\"IconCheck\"\n                hugeicons=\"Tick02Icon\"\n                phosphor=\"CheckIcon\"\n                remixicon=\"RiCheckLine\"\n                data-icon=\"inline-start\"\n              />\n            )}\n            {shortfall ? `Type ${label} short` : \"In proportion\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent className=\"flex-1 pb-0\">\n        <ChartContainer\n          config={chartConfig}\n          className=\"mx-auto aspect-square max-h-[250px]\"\n        >\n          <PieChart>\n            <ChartTooltip\n              cursor={false}\n              content={\n                <ChartTooltipContent\n                  hideLabel\n                  nameKey=\"type\"\n                  formatter={(value, name, item) => (\n                    <div className=\"flex min-w-[130px] items-center gap-2 text-xs text-muted-foreground\">\n                      <div\n                        className=\"size-2.5 shrink-0 rounded-[2px]\"\n                        style={{ background: item.payload.fill }}\n                      />\n                      {\n                        chartConfig[\n                          item.payload.type as keyof typeof chartConfig\n                        ].label\n                      }\n                      ,{\" \"}\n                      {chartConfig[\n                        name as keyof typeof chartConfig\n                      ]?.label.toLowerCase()}\n                      <span className=\"ml-auto font-mono font-medium text-foreground tabular-nums\">\n                        {value}%\n                      </span>\n                    </div>\n                  )}\n                />\n              }\n            />\n            {/* People inside, donations outside, so a gap reads across. */}\n            <Pie\n              data={chartData}\n              dataKey=\"population\"\n              nameKey=\"type\"\n              innerRadius={40}\n              outerRadius={64}\n              fillOpacity={0.45}\n              strokeWidth={2}\n            />\n            <Pie\n              data={chartData}\n              dataKey=\"donated\"\n              nameKey=\"type\"\n              innerRadius={70}\n              outerRadius={100}\n              strokeWidth={2}\n            />\n          </PieChart>\n        </ChartContainer>\n        {/* One key for both rings, which share their colors. */}\n        <div className=\"flex items-center justify-center gap-4 pt-3 text-xs\">\n          {chartData.map(({ type }) => (\n            <div key={type} className=\"flex items-center gap-1.5\">\n              <div\n                className=\"size-2 shrink-0 rounded-[2px]\"\n                style={{\n                  background: chartConfig[type as \"o\" | \"a\" | \"b\" | \"ab\"].color,\n                }}\n              />\n              {chartConfig[type as keyof typeof chartConfig].label}\n            </div>\n          ))}\n        </div>\n      </CardContent>\n      <CardFooter className=\"flex-col gap-2 text-sm\">\n        <div className=\"flex items-center gap-2 leading-none font-medium\">\n          Type {label} is {short.donated}% of units, {short.population}% of\n          people\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          This month; illustrative data\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Blood donations pie chart: https://organui.com/charts/pie#chart-pie-blood-types",
  "categories": [
    "charts",
    "charts-pie"
  ],
  "type": "registry:block"
}