{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line-rehab",
  "title": "Cardiac rehab line chart",
  "description": "Resting heart rate through cardiac rehab: daily readings, a 7-day average and milestones.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-line-rehab.tsx",
      "content": "\"use client\"\n\nimport {\n  CartesianGrid,\n  ComposedChart,\n  Label,\n  Line,\n  ReferenceLine,\n  Scatter,\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  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n  type ChartConfig,\n} from \"@/components/ui/chart\"\nimport { IconPlaceholder } from \"@/icons/icon-placeholder\"\n\nexport const description =\n  \"Resting heart rate through cardiac rehab, daily readings with a 7-day average and milestones\"\n\n// Repeatable noise between -1 and 1, so the server and browser draw the same\n// chart.\nfunction noise(n: number) {\n  const x = Math.sin(n * 12.9898) * 43758.5453\n  return (x - Math.floor(x)) * 2 - 1\n}\n\n// What happened, marked on the timeline.\nconst milestones = [\n  { date: \"2026-04-15\", label: \"Rehab starts\" },\n  { date: \"2026-05-27\", label: \"Home exercise\" },\n]\nconst start = Date.UTC(2026, 3, 15)\n\n// Resting heart rate from a fictional patient's wearable, each morning for\n// twelve weeks: steady before rehab, then falling with training.\nconst readings = Array.from({ length: 84 }, (_, day) => {\n  const date = Date.UTC(2026, 3, 1 + day)\n  const trained = Math.max(0, (date - start) / 86_400_000)\n  return {\n    date: new Date(date).toISOString().slice(0, 10),\n    heartRate: Math.round(\n      76 - 9 * (1 - Math.exp(-trained / 30)) + 2.5 * noise(day)\n    ),\n  }\n})\n\n// Each day with the mean of the seven days to it.\nconst chartData = readings.map((day, index) => {\n  const week = readings.slice(Math.max(0, index - 6), index + 1)\n  return {\n    ...day,\n    average:\n      index < 6\n        ? null\n        : Math.round(\n            (week.reduce((sum, { heartRate }) => sum + heartRate, 0) /\n              week.length) *\n              10\n          ) / 10,\n  }\n})\n\nconst chartConfig = {\n  heartRate: {\n    label: \"Morning reading\",\n    color: \"var(--chart-1)\",\n  },\n  average: {\n    label: \"7-day average\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\nconst before = chartData.find(({ date }) => date === milestones[0]!.date)!\nconst latest = chartData.at(-1)!\nconst change =\n  Math.round(((latest.average ?? 0) - (before.average ?? 0)) * 10) / 10\nconst improving = change < 0\n\n// Dates are UTC days, so they read the same on the server and in the browser.\nfunction formatDate(value: string, options?: Intl.DateTimeFormatOptions) {\n  return new Date(value).toLocaleDateString(\"en-US\", {\n    month: \"short\",\n    day: \"numeric\",\n    timeZone: \"UTC\",\n    ...options,\n  })\n}\n\nexport function ChartLineRehab() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Cardiac rehab</CardTitle>\n        <CardDescription>\n          Resting heart rate each morning, from a wearable; a fictional patient\n        </CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {change > 0 ? \"+\" : \"\"}\n            {change}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              bpm since rehab\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {improving ? (\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            {improving ? \"Improving\" : \"Not improving\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent className=\"px-2 sm:px-6\">\n        <ChartContainer\n          config={chartConfig}\n          className=\"aspect-auto h-[260px] w-full\"\n        >\n          <ComposedChart\n            accessibilityLayer\n            data={chartData}\n            margin={{ left: -12, right: 12, top: 16 }}\n          >\n            <CartesianGrid vertical={false} />\n            <XAxis\n              dataKey=\"date\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              minTickGap={32}\n              tickFormatter={(value) => formatDate(value)}\n            />\n            <YAxis\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              domain={[60, 82]}\n              ticks={[65, 70, 75, 80]}\n            />\n            <ChartTooltip\n              cursor={false}\n              content={\n                <ChartTooltipContent\n                  indicator=\"line\"\n                  labelFormatter={(_, payload) =>\n                    formatDate(payload[0]?.payload.date, { weekday: \"short\" })\n                  }\n                />\n              }\n            />\n            {milestones.map((milestone) => (\n              <ReferenceLine\n                key={milestone.date}\n                x={milestone.date}\n                stroke=\"var(--muted-foreground)\"\n              >\n                <Label\n                  value={milestone.label}\n                  position=\"insideTopLeft\"\n                  className=\"fill-foreground\"\n                  fontSize={11}\n                />\n              </ReferenceLine>\n            ))}\n            {/* Each reading faint, the average strong. */}\n            <Scatter\n              dataKey=\"heartRate\"\n              fill=\"var(--color-heartRate)\"\n              fillOpacity={0.45}\n              shape={(props: { cx?: number; cy?: number }) => (\n                <circle\n                  cx={props.cx}\n                  cy={props.cy}\n                  r={2.5}\n                  fill=\"var(--color-heartRate)\"\n                  fillOpacity={0.45}\n                />\n              )}\n            />\n            <Line\n              dataKey=\"average\"\n              type=\"monotone\"\n              stroke=\"var(--color-average)\"\n              strokeWidth={2}\n              dot={false}\n            />\n            <ChartLegend content={<ChartLegendContent />} />\n          </ComposedChart>\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          From {before.average} to {latest.average} bpm, 7-day average{\" \"}\n          {latest.average! <= before.average! ? (\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          {formatDate(milestones[0]!.date)} to {formatDate(latest.date)}; a\n          fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "fullWidth": true
  },
  "docs": "Cardiac rehab line chart: https://organui.com/charts/line#chart-line-rehab",
  "categories": [
    "charts",
    "charts-line"
  ],
  "type": "registry:block"
}