{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-bar-turnaround",
  "title": "Lab turnaround bar chart",
  "description": "Daily laboratory turnaround for urgent bloods, against a target.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-bar-turnaround.tsx",
      "content": "\"use client\"\n\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  Cell,\n  Label,\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  type ChartConfig,\n} from \"@/components/ui/chart\"\nimport { IconPlaceholder } from \"@/icons/icon-placeholder\"\n\nexport const description =\n  \"Daily laboratory turnaround for urgent bloods, against a target\"\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// The median minutes from request to result for urgent bloods each day, from\n// April to June, illustrative: slower at weekends, with fewer staff.\nconst chartData = Array.from({ length: 91 }, (_, day) => {\n  const date = new Date(Date.UTC(2026, 3, 1 + day))\n  const weekend = [0, 6].includes(date.getUTCDay())\n  return {\n    date: date.toISOString().slice(0, 10),\n    minutes: Math.round((weekend ? 63 : 49) + 8 * noise(day)),\n  }\n})\n\nconst chartConfig = {\n  minutes: {\n    label: \"Median turnaround\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\n// The target from request to result for urgent bloods; set your own.\nconst target = 60\nconst lastMonth = chartData.slice(-30)\nconst withinTarget = lastMonth.filter(({ minutes }) => minutes <= target)\nconst share = Math.round((withinTarget.length / lastMonth.length) * 100)\n// The share of days within target the service aims for; set your own.\nconst goal = 90\nconst meets = share >= goal\nconst slowest = chartData.reduce((a, b) => (b.minutes > a.minutes ? b : a))\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 ChartBarTurnaround() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Lab turnaround</CardTitle>\n        <CardDescription>\n          Urgent bloods, median minutes from request to result, each day\n        </CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {share}%{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              of the last 30 days on target\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {meets ? (\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            {meets ? \"At goal\" : \"Below goal\"} of {goal}%\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          <BarChart\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={[0, 80]}\n              ticks={[0, 30, 60]}\n              tickFormatter={(value) => `${value} min`}\n            />\n            <ChartTooltip\n              cursor={false}\n              content={({ active, payload }) => {\n                const row = payload?.[0]?.payload as\n                  (typeof chartData)[number] | undefined\n                if (!active || !row) return null\n                return (\n                  <div className=\"grid min-w-[9rem] gap-1 rounded-lg border bg-background px-2.5 py-1.5 text-xs shadow-xl\">\n                    <div className=\"font-medium\">\n                      {formatDate(row.date, { weekday: \"short\" })}\n                    </div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Median</span>\n                      <span className=\"font-mono font-medium tabular-nums\">\n                        {row.minutes} min\n                      </span>\n                    </div>\n                  </div>\n                )\n              }}\n            />\n            {/* Days over target at full strength, the rest muted. */}\n            <Bar dataKey=\"minutes\" radius={[2, 2, 0, 0]}>\n              {chartData.map((day) => (\n                <Cell\n                  key={day.date}\n                  fill=\"var(--color-minutes)\"\n                  fillOpacity={day.minutes > target ? 1 : 0.3}\n                />\n              ))}\n            </Bar>\n            <ReferenceLine\n              y={target}\n              stroke=\"var(--muted-foreground)\"\n              strokeDasharray=\"4 4\"\n            >\n              <Label\n                value={`Target ${target} min`}\n                position=\"insideTopRight\"\n                className=\"fill-muted-foreground\"\n                fontSize={11}\n              />\n            </ReferenceLine>\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          Slowest on {formatDate(slowest.date, { weekday: \"short\" })}, at{\" \"}\n          {slowest.minutes} minutes\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          Strong bars missed the target; illustrative data\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "fullWidth": true
  },
  "docs": "Lab turnaround bar chart: https://organui.com/charts/bar#chart-bar-turnaround",
  "categories": [
    "charts",
    "charts-bar"
  ],
  "type": "registry:block"
}