{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-area-glucose-profile",
  "title": "Glucose profile area chart",
  "description": "An ambulatory glucose profile: the median and percentile bands over a day.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-area-glucose-profile.tsx",
      "content": "\"use client\"\n\nimport {\n  Area,\n  CartesianGrid,\n  ComposedChart,\n  Label,\n  Line,\n  ReferenceLine,\n  XAxis,\n  YAxis,\n} from \"recharts\"\n\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport {\n  ChartContainer,\n  ChartTooltip,\n  ChartTooltipContent,\n  type ChartConfig,\n} from \"@/components/ui/chart\"\n\nexport const description =\n  \"An ambulatory glucose profile: the median and percentile bands over a day\"\n\n// A bump centred on an hour of the day, for the shape of the sample data.\nfunction bump(hour: number, centre: number, width: number) {\n  return Math.exp(-(((hour - centre) / width) ** 2) / 2)\n}\n\n// Fourteen days of sensor glucose for a fictional patient, folded into one\n// day: the median at each hour, with the 25th–75th and 5th–95th percentiles.\n// It rises before waking and after each meal.\nconst chartData = Array.from({ length: 24 }, (_, hour) => {\n  const median =\n    104 +\n    14 * bump(hour, 5.5, 1.5) +\n    44 * bump(hour, 8.5, 1.2) +\n    50 * bump(hour, 13.5, 1.3) +\n    58 * bump(hour, 19.5, 1.4)\n  const spread = 14 + (median - 100) * 0.3\n  return {\n    time: `${String(hour).padStart(2, \"0\")}:00`,\n    median: Math.round(median),\n    middle: [Math.round(median - spread), Math.round(median + spread)],\n    outer: [\n      Math.round(median - spread * 2.2),\n      Math.round(median + spread * 2.4),\n    ],\n  }\n})\n\nconst chartConfig = {\n  median: {\n    label: \"Median\",\n    color: \"var(--chart-2)\",\n  },\n  middle: {\n    label: \"25th–75th\",\n    color: \"var(--chart-2)\",\n  },\n  outer: {\n    label: \"5th–95th\",\n    color: \"var(--chart-1)\",\n  },\n} satisfies ChartConfig\n\n// The consensus target range, in mg/dL.\nconst target = { low: 70, high: 180 }\nconst peak = chartData.reduce((a, b) => (b.median > a.median ? b : a))\n\nexport function ChartAreaGlucoseProfile() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Glucose profile</CardTitle>\n        <CardDescription>14 days folded into one, mg/dL</CardDescription>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <ComposedChart\n            accessibilityLayer\n            data={chartData}\n            margin={{ left: -12, right: 12 }}\n          >\n            <CartesianGrid vertical={false} />\n            <XAxis\n              dataKey=\"time\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              interval={5}\n            />\n            <YAxis\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              domain={[40, 280]}\n              ticks={[target.low, target.high, 250]}\n            />\n            <ChartTooltip\n              cursor={false}\n              content={\n                <ChartTooltipContent\n                  indicator=\"line\"\n                  formatter={(value, name) => (\n                    <div className=\"flex min-w-[130px] items-center text-xs text-muted-foreground\">\n                      {chartConfig[name as keyof typeof chartConfig]?.label}\n                      <span className=\"ml-auto font-mono font-medium text-foreground tabular-nums\">\n                        {Array.isArray(value) ? value.join(\"–\") : value}\n                      </span>\n                    </div>\n                  )}\n                />\n              }\n            />\n            <Area\n              dataKey=\"outer\"\n              type=\"monotone\"\n              fill=\"var(--color-outer)\"\n              fillOpacity={0.25}\n              stroke=\"none\"\n              activeDot={false}\n            />\n            <Area\n              dataKey=\"middle\"\n              type=\"monotone\"\n              fill=\"var(--color-middle)\"\n              fillOpacity={0.35}\n              stroke=\"none\"\n              activeDot={false}\n            />\n            <Line\n              dataKey=\"median\"\n              type=\"monotone\"\n              stroke=\"var(--color-median)\"\n              strokeWidth={2}\n              dot={false}\n            />\n            {[target.low, target.high].map((limit) => (\n              <ReferenceLine\n                key={limit}\n                y={limit}\n                stroke=\"var(--muted-foreground)\"\n                strokeDasharray=\"4 4\"\n              >\n                {limit === target.low && (\n                  <Label\n                    value={`Target ${target.low}–${target.high}`}\n                    position=\"insideBottomRight\"\n                    dy={16}\n                    className=\"fill-muted-foreground\"\n                    fontSize={11}\n                  />\n                )}\n              </ReferenceLine>\n            ))}\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          Highest at {peak.time}, median {peak.median} mg/dL\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          Median with 25th–75th and 5th–95th percentiles; a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Glucose profile area chart: https://organui.com/charts/area#chart-area-glucose-profile",
  "categories": [
    "charts",
    "charts-area"
  ],
  "type": "registry:block"
}