{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line-forest-plot",
  "title": "Forest plot line chart",
  "description": "A forest plot of hazard ratios with 95% confidence intervals by subgroup.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-line-forest-plot.tsx",
      "content": "\"use client\"\n\nimport {\n  CartesianGrid,\n  ComposedChart,\n  ErrorBar,\n  Label,\n  ReferenceLine,\n  Scatter,\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  type ChartConfig,\n} from \"@/components/ui/chart\"\n\nexport const description =\n  \"A forest plot of hazard ratios with 95% confidence intervals by subgroup\"\n\n// Hazard ratios, treatment against control, for a fictional trial.\nconst subgroups = [\n  { subgroup: \"Overall\", ratio: 0.48, low: 0.3, high: 0.77 },\n  { subgroup: \"Age < 65\", ratio: 0.44, low: 0.24, high: 0.81 },\n  { subgroup: \"Age ≥ 65\", ratio: 0.55, low: 0.28, high: 1.07 },\n  { subgroup: \"Women\", ratio: 0.51, low: 0.26, high: 1.0 },\n  { subgroup: \"Men\", ratio: 0.46, low: 0.25, high: 0.85 },\n  { subgroup: \"Diabetes\", ratio: 0.62, low: 0.31, high: 1.24 },\n]\n\n// The interval as distances below and above the ratio, as the error bar\n// draws it.\nconst chartData = subgroups.map((row) => ({\n  ...row,\n  interval: [row.ratio - row.low, row.high - row.ratio],\n}))\n\nconst chartConfig = {\n  ratio: {\n    label: \"Hazard ratio\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\n// Intervals entirely below 1 favour treatment with confidence.\nconst confident = chartData.filter(({ high }) => high < 1)\n\nexport function ChartLineForestPlot() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Subgroups</CardTitle>\n        <CardDescription>Hazard ratio with 95% CI, log scale</CardDescription>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <ComposedChart\n            accessibilityLayer\n            data={chartData}\n            layout=\"vertical\"\n            margin={{ left: 8, right: 16, top: 16 }}\n          >\n            <CartesianGrid horizontal={false} />\n            <XAxis\n              type=\"number\"\n              scale=\"log\"\n              domain={[0.2, 2]}\n              ticks={[0.25, 0.5, 1, 2]}\n              allowDataOverflow\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n            />\n            <YAxis\n              type=\"category\"\n              dataKey=\"subgroup\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              width={80}\n            />\n            {/* A ratio of 1 means no difference between the arms. */}\n            <ReferenceLine\n              x={1}\n              stroke=\"var(--muted-foreground)\"\n              strokeDasharray=\"4 4\"\n            >\n              <Label\n                value=\"No effect\"\n                position=\"top\"\n                className=\"fill-muted-foreground\"\n                fontSize={11}\n              />\n            </ReferenceLine>\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\">{row.subgroup}</div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">HR</span>\n                      <span className=\"font-mono font-medium tabular-nums\">\n                        {row.ratio.toFixed(2)} ({row.low.toFixed(2)}–\n                        {row.high.toFixed(2)})\n                      </span>\n                    </div>\n                  </div>\n                )\n              }}\n            />\n            <Scatter dataKey=\"ratio\" fill=\"var(--color-ratio)\" shape=\"square\">\n              <ErrorBar\n                dataKey=\"interval\"\n                direction=\"x\"\n                width={0}\n                stroke=\"var(--color-ratio)\"\n                strokeWidth={2}\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          {confident.length} of {chartData.length} intervals sit below 1\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          Below 1 favours treatment; a fictional trial\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Forest plot line chart: https://organui.com/charts/line#chart-line-forest-plot",
  "categories": [
    "charts",
    "charts-line"
  ],
  "type": "registry:block"
}