{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line-hba1c",
  "title": "HbA1c line chart",
  "description": "HbA1c by quarter, as a line chart with labels.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-line-hba1c.tsx",
      "content": "\"use client\"\n\nimport {\n  CartesianGrid,\n  Label,\n  LabelList,\n  Line,\n  LineChart,\n  ReferenceLine,\n  XAxis,\n  YAxis,\n} 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 = \"HbA1c by quarter, as a line chart with labels\"\n\n// Quarterly results in percent, a fictional patient.\nconst chartData = [\n  { quarter: \"Q1 2025\", hba1c: 8.4 },\n  { quarter: \"Q2 2025\", hba1c: 7.9 },\n  { quarter: \"Q3 2025\", hba1c: 7.5 },\n  { quarter: \"Q4 2025\", hba1c: 7.2 },\n  { quarter: \"Q1 2026\", hba1c: 6.9 },\n  { quarter: \"Q2 2026\", hba1c: 6.8 },\n]\n\nconst chartConfig = {\n  hba1c: {\n    label: \"HbA1c (%)\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\nconst latest = chartData.at(-1)!\n// A common target for adults, in percent; set your own patient's.\nconst target = 7\nconst atTarget = latest.hba1c < target\n\nconst first = chartData[0]!\n// The first quarter from which every reading stays below target.\nconst belowFrom = chartData.find((_, index) =>\n  chartData.slice(index).every(({ hba1c }) => hba1c < target)\n)\n\nexport function ChartLineHba1c() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>HbA1c</CardTitle>\n        <CardDescription>Quarterly, over 18 months</CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {latest.hba1c}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">%</span>\n          </div>\n          <Badge variant=\"outline\">\n            {atTarget ? (\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            {atTarget ? \"At target\" : \"Above target\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <LineChart\n            accessibilityLayer\n            data={chartData}\n            // Room for half of the first and last quarter labels.\n            margin={{ top: 20, left: 20, right: 20 }}\n          >\n            <CartesianGrid vertical={false} />\n            <XAxis\n              dataKey=\"quarter\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              // \"Q1 2025\" as \"Q1 '25\", so the year stays on the axis.\n              tickFormatter={(value) => value.replace(\" 20\", \" '\")}\n              interval={0}\n            />\n            <YAxis hide domain={[6, 9]} />\n            <ReferenceLine\n              y={target}\n              stroke=\"var(--muted-foreground)\"\n              strokeDasharray=\"4 4\"\n            >\n              <Label\n                value={`Target ${target}%`}\n                position=\"insideBottomLeft\"\n                className=\"fill-muted-foreground\"\n                fontSize={11}\n              />\n            </ReferenceLine>\n            <ChartTooltip\n              cursor={false}\n              content={<ChartTooltipContent indicator=\"line\" />}\n            />\n            <Line\n              dataKey=\"hba1c\"\n              type=\"monotone\"\n              stroke=\"var(--color-hba1c)\"\n              strokeWidth={2}\n              dot={{ fill: \"var(--color-hba1c)\" }}\n              activeDot={{ r: 6 }}\n            >\n              <LabelList\n                position=\"top\"\n                offset={12}\n                className=\"fill-foreground\"\n                fontSize={12}\n              />\n            </Line>\n          </LineChart>\n        </ChartContainer>\n      </CardContent>\n      <CardFooter className=\"flex-col items-start gap-2 text-sm\">\n        <div className=\"flex items-center gap-2 leading-none font-medium\">\n          {latest.hba1c <= first.hba1c ? \"Down\" : \"Up\"}{\" \"}\n          {Math.abs(first.hba1c - latest.hba1c).toFixed(1)} points since{\" \"}\n          {first.quarter}{\" \"}\n          {latest.hba1c <= first.hba1c ? (\n            <IconPlaceholder\n              lucide=\"TrendingDownIcon\"\n              tabler=\"IconTrendingDown\"\n              hugeicons=\"ChartDownIcon\"\n              phosphor=\"TrendDownIcon\"\n              remixicon=\"RiArrowDownLine\"\n              className=\"size-4\"\n            />\n          ) : (\n            <IconPlaceholder\n              lucide=\"TrendingUpIcon\"\n              tabler=\"IconTrendingUp\"\n              hugeicons=\"ChartUpIcon\"\n              phosphor=\"TrendUpIcon\"\n              remixicon=\"RiArrowUpLine\"\n              className=\"size-4\"\n            />\n          )}\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          {belowFrom\n            ? `Below ${target}% since ${belowFrom.quarter}`\n            : `Not yet below ${target}%`}\n          ; a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "HbA1c line chart: https://organui.com/charts/line#chart-line-hba1c",
  "categories": [
    "charts",
    "charts-line"
  ],
  "type": "registry:block"
}