{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-bar-lab-panel",
  "title": "Lab panel bar chart",
  "description": "A lab panel, each result placed on its own reference range with high and low flags.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-bar-lab-panel.tsx",
      "content": "\"use client\"\n\nimport { Bar, ComposedChart, LabelList, Scatter, 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  ChartTooltip,\n  type ChartConfig,\n} from \"@/components/ui/chart\"\nimport { IconPlaceholder } from \"@/icons/icon-placeholder\"\n\nexport const description =\n  \"A lab panel, each result placed on its own reference range\"\n\n// One draw for a fictional patient, with typical adult reference ranges.\n// Check your own laboratory's ranges, which vary by method and population.\nconst results = [\n  { analyte: \"Sodium\", value: 138, low: 135, high: 145, unit: \"mmol/L\" },\n  { analyte: \"Potassium\", value: 5.4, low: 3.5, high: 5.0, unit: \"mmol/L\" },\n  { analyte: \"Creatinine\", value: 1.1, low: 0.6, high: 1.2, unit: \"mg/dL\" },\n  { analyte: \"Glucose\", value: 92, low: 70, high: 99, unit: \"mg/dL\" },\n  { analyte: \"Hemoglobin\", value: 11.2, low: 12.0, high: 15.5, unit: \"g/dL\" },\n]\n\n// Each row has its own units, so each is scaled to its range: the range fills\n// the middle half of the row, and the result sits where it falls.\nconst chartData = results.map((result) => {\n  const width = result.high - result.low\n  const start = result.low - width / 2\n  const position = ((result.value - start) / (width * 2)) * 100\n  return {\n    ...result,\n    range: [25, 75],\n    position: Math.min(Math.max(position, 2), 98),\n    flag:\n      result.value > result.high ? \"H\" : result.value < result.low ? \"L\" : \"\",\n  }\n})\n\nconst chartConfig = {\n  range: {\n    label: \"Reference range\",\n    color: \"var(--muted-foreground)\",\n  },\n  position: {\n    label: \"Result\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\nconst flagged = chartData.filter(({ flag }) => flag)\n\nexport function ChartBarLabPanel() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Lab panel</CardTitle>\n        <CardDescription>Results against reference ranges</CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {flagged.length}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              of {chartData.length} flagged\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {flagged.length ? (\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              <IconPlaceholder\n                lucide=\"CheckIcon\"\n                tabler=\"IconCheck\"\n                hugeicons=\"Tick02Icon\"\n                phosphor=\"CheckIcon\"\n                remixicon=\"RiCheckLine\"\n                data-icon=\"inline-start\"\n              />\n            )}\n            {flagged.length ? \"Review\" : \"All in range\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <ComposedChart\n            accessibilityLayer\n            data={chartData}\n            layout=\"vertical\"\n            margin={{ left: 8, right: 24 }}\n          >\n            <XAxis type=\"number\" domain={[0, 100]} hide />\n            <YAxis\n              type=\"category\"\n              dataKey=\"analyte\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              width={84}\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-[10rem] gap-1 rounded-lg border bg-background px-2.5 py-1.5 text-xs shadow-xl\">\n                    <div className=\"font-medium\">{row.analyte}</div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Result</span>\n                      <span className=\"font-mono font-medium tabular-nums\">\n                        {row.value} {row.unit} {row.flag}\n                      </span>\n                    </div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Range</span>\n                      <span className=\"font-mono tabular-nums\">\n                        {row.low}–{row.high}\n                      </span>\n                    </div>\n                  </div>\n                )\n              }}\n            />\n            <Bar\n              dataKey=\"range\"\n              fill=\"var(--color-range)\"\n              fillOpacity={0.15}\n              radius={4}\n              barSize={12}\n            />\n            <Scatter dataKey=\"position\" fill=\"var(--color-position)\">\n              {/* A high or low flag beside the result, as on a lab report. */}\n              <LabelList\n                dataKey=\"flag\"\n                position=\"right\"\n                offset={10}\n                className=\"fill-foreground font-semibold\"\n                fontSize={12}\n              />\n            </Scatter>\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          {flagged.length\n            ? flagged\n                .map(\n                  ({ analyte, flag }) =>\n                    `${analyte} ${flag === \"H\" ? \"high\" : \"low\"}`\n                )\n                .join(\", \")\n            : \"Every result in range\"}\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          The shaded bar is each range; a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Lab panel bar chart: https://organui.com/charts/bar#chart-bar-lab-panel",
  "categories": [
    "charts",
    "charts-bar"
  ],
  "type": "registry:block"
}