{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-bar-time-in-range",
  "title": "Time in range bar chart",
  "description": "Continuous glucose monitor time in range by week, as a stacked bar chart.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-bar-time-in-range.tsx",
      "content": "\"use client\"\n\nimport { Bar, BarChart, XAxis, YAxis } 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  \"Continuous glucose monitor time in range by week, as a stacked bar chart\"\n\n// Share of each week a fictional patient's sensor glucose spent in each\n// range, in percent. The ranges are the international consensus ones.\nconst chartData = [\n  { week: \"Week 1\", veryLow: 2, low: 5, inRange: 58, high: 25, veryHigh: 10 },\n  { week: \"Week 2\", veryLow: 1, low: 4, inRange: 63, high: 23, veryHigh: 9 },\n  { week: \"Week 3\", veryLow: 1, low: 3, inRange: 68, high: 21, veryHigh: 7 },\n  { week: \"Week 4\", veryLow: 0, low: 2, inRange: 74, high: 18, veryHigh: 6 },\n]\n\n// One ramp from low to high glucose, so the order of the stack reads at a\n// glance.\nconst chartConfig = {\n  veryHigh: {\n    label: \"Very high (>250)\",\n    color: \"var(--chart-1)\",\n  },\n  high: {\n    label: \"High (181–250)\",\n    color: \"var(--chart-2)\",\n  },\n  inRange: {\n    label: \"In range (70–180)\",\n    color: \"var(--chart-3)\",\n  },\n  low: {\n    label: \"Low (54–69)\",\n    color: \"var(--chart-4)\",\n  },\n  veryLow: {\n    label: \"Very low (<54)\",\n    color: \"var(--chart-5)\",\n  },\n} satisfies ChartConfig\n\n// The ranges from lowest to highest, the order they stack from the base.\nconst ranges = [\"veryLow\", \"low\", \"inRange\", \"high\", \"veryHigh\"] as const\n\n// Consensus targets for most adults: over 70% in range, under 4% below 70.\nconst targets = { inRange: 70, below: 4 }\nconst first = chartData[0]!\nconst latest = chartData.at(-1)!\nconst atTarget =\n  latest.inRange > targets.inRange &&\n  latest.low + latest.veryLow < targets.below\n\nexport function ChartBarTimeInRange() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Time in range</CardTitle>\n        <CardDescription>Sensor glucose, mg/dL, by week</CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {latest.inRange}%{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              in range\n            </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\" : \"Below target\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <BarChart accessibilityLayer data={chartData}>\n            <XAxis\n              dataKey=\"week\"\n              tickLine={false}\n              tickMargin={10}\n              axisLine={false}\n            />\n            <YAxis hide domain={[0, 100]} />\n            <ChartTooltip\n              cursor={false}\n              content={\n                <ChartTooltipContent\n                  formatter={(value, name) => (\n                    <div className=\"flex min-w-[150px] 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                        {value}%\n                      </span>\n                    </div>\n                  )}\n                />\n              }\n            />\n            {ranges.map((range, index) => (\n              <Bar\n                key={range}\n                dataKey={range}\n                stackId=\"a\"\n                fill={`var(--color-${range})`}\n                maxBarSize={48}\n                radius={\n                  index === 0\n                    ? [0, 0, 4, 4]\n                    : index === ranges.length - 1\n                      ? [4, 4, 0, 0]\n                      : 0\n                }\n              />\n            ))}\n            {/* Highest to lowest, the order the stack reads from the top. */}\n            <ChartLegend\n              itemSorter={(item) =>\n                -ranges.indexOf(item.dataKey as (typeof ranges)[number])\n              }\n              content={<ChartLegendContent className=\"flex-wrap\" />}\n            />\n          </BarChart>\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.inRange >= first.inRange ? \"Up\" : \"Down\"}{\" \"}\n          {Math.abs(latest.inRange - first.inRange)} points since{\" \"}\n          {first.week.toLowerCase()}{\" \"}\n          {latest.inRange < first.inRange ? (\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          Targets: over {targets.inRange}% in range, under {targets.below}% low;\n          a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Time in range bar chart: https://organui.com/charts/bar#chart-bar-time-in-range",
  "categories": [
    "charts",
    "charts-bar"
  ],
  "type": "registry:block"
}