{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-pie-pdc",
  "title": "Medication adherence pie chart",
  "description": "Proportion of days covered by a medication over a year, with the 80% adherence threshold.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-pie-pdc.tsx",
      "content": "\"use client\"\n\nimport { Label, Pie, PieChart, usePlotArea } 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  \"Proportion of days covered by a medication over a year, as a donut chart\"\n\n// Days in the last year a fictional patient had their statin on hand, from\n// pharmacy fills.\nconst days = { covered: 303, total: 365 }\n\nconst chartData = [\n  { status: \"covered\", days: days.covered, fill: \"var(--color-covered)\" },\n  {\n    status: \"uncovered\",\n    days: days.total - days.covered,\n    fill: \"var(--color-uncovered)\",\n  },\n]\n\nconst chartConfig = {\n  days: {\n    label: \"Days\",\n  },\n  covered: {\n    label: \"Covered\",\n    color: \"var(--chart-2)\",\n  },\n  uncovered: {\n    label: \"Without medication\",\n    color: \"var(--muted)\",\n  },\n} satisfies ChartConfig\n\n// The usual threshold for calling a patient adherent.\nconst threshold = 80\nconst pdc = Math.round((days.covered / days.total) * 100)\nconst adherent = pdc >= threshold\nconst radius = { inner: 64, outer: 88 }\n\n// The threshold as a dashed spoke across the ring, clockwise from the top.\nfunction ThresholdSpoke() {\n  const plot = usePlotArea()\n  if (!plot) return null\n  const cx = plot.x + plot.width / 2\n  const cy = plot.y + plot.height / 2\n  const angle = ((90 - (threshold / 100) * 360) * Math.PI) / 180\n  const at = (r: number) => ({\n    x: cx + r * Math.cos(angle),\n    y: cy - r * Math.sin(angle),\n  })\n  const start = at(radius.inner - 4)\n  const end = at(radius.outer + 4)\n  const label = at(radius.outer + 16)\n  return (\n    <g aria-hidden=\"true\">\n      <line\n        x1={start.x}\n        y1={start.y}\n        x2={end.x}\n        y2={end.y}\n        stroke=\"var(--muted-foreground)\"\n        strokeDasharray=\"4 4\"\n      />\n      <text\n        x={label.x}\n        y={label.y}\n        textAnchor=\"middle\"\n        dominantBaseline=\"middle\"\n        className=\"fill-muted-foreground\"\n        fontSize={11}\n      >\n        {threshold}%\n      </text>\n    </g>\n  )\n}\n\nexport function ChartPiePdc() {\n  return (\n    <Card className=\"flex flex-col\">\n      <CardHeader>\n        <CardTitle>Statin adherence</CardTitle>\n        <CardDescription>Proportion of days covered, last year</CardDescription>\n        <CardAction>\n          <Badge variant=\"outline\">\n            {adherent ? (\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              <IconPlaceholder\n                lucide=\"TriangleAlertIcon\"\n                tabler=\"IconAlertTriangle\"\n                hugeicons=\"Alert02Icon\"\n                phosphor=\"WarningIcon\"\n                remixicon=\"RiAlertLine\"\n                data-icon=\"inline-start\"\n              />\n            )}\n            {adherent ? \"Adherent\" : \"Below threshold\"}\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={<ChartTooltipContent hideLabel />}\n            />\n            <Pie\n              data={chartData}\n              dataKey=\"days\"\n              nameKey=\"status\"\n              innerRadius={radius.inner}\n              outerRadius={radius.outer}\n              startAngle={90}\n              endAngle={-270}\n              strokeWidth={2}\n            >\n              <Label\n                content={({ viewBox }) => {\n                  if (viewBox && \"cx\" in viewBox && \"cy\" in viewBox) {\n                    return (\n                      <text\n                        x={viewBox.cx}\n                        y={viewBox.cy}\n                        textAnchor=\"middle\"\n                        dominantBaseline=\"middle\"\n                      >\n                        <tspan\n                          x={viewBox.cx}\n                          y={viewBox.cy}\n                          className=\"fill-foreground text-3xl font-bold\"\n                        >\n                          {pdc}%\n                        </tspan>\n                        <tspan\n                          x={viewBox.cx}\n                          y={(viewBox.cy || 0) + 24}\n                          className=\"fill-muted-foreground\"\n                        >\n                          PDC\n                        </tspan>\n                      </text>\n                    )\n                  }\n                }}\n              />\n            </Pie>\n            <ThresholdSpoke />\n          </PieChart>\n        </ChartContainer>\n      </CardContent>\n      <CardFooter className=\"flex-col gap-2 text-sm\">\n        <div className=\"flex items-center gap-2 leading-none font-medium\">\n          {days.total - days.covered} days without medication\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          {threshold}% or more counts as adherent; a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Medication adherence pie chart: https://organui.com/charts/pie#chart-pie-pdc",
  "categories": [
    "charts",
    "charts-pie"
  ],
  "type": "registry:block"
}