{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-area-ed-arrivals",
  "title": "ED arrivals area chart",
  "description": "Daily emergency department arrivals with a 7-day average, a surge threshold and events.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-area-ed-arrivals.tsx",
      "content": "\"use client\"\n\nimport {\n  Bar,\n  CartesianGrid,\n  ComposedChart,\n  Label,\n  Line,\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  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  \"Daily emergency department arrivals with a 7-day average, a surge threshold and events\"\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// Daily arrivals from April to June, illustrative: busier on Mondays, with a\n// rise through May.\nconst arrivals = Array.from({ length: 91 }, (_, day) => {\n  const date = new Date(Date.UTC(2026, 3, 1 + day))\n  const monday = date.getUTCDay() === 1 ? 26 : 0\n  const rise = 28 * Math.exp(-(((day - 50) / 12) ** 2) / 2)\n  return {\n    date: date.toISOString().slice(0, 10),\n    arrivals: Math.round(186 + monday + rise + 18 * noise(day)),\n  }\n})\n\n// Each day with the mean of the seven days to it, the line that smooths out\n// the weekly pattern.\nconst chartData = arrivals.map((day, index) => {\n  const week = arrivals.slice(Math.max(0, index - 6), index + 1)\n  return {\n    ...day,\n    average:\n      index < 6\n        ? null\n        : Math.round(\n            week.reduce((sum, { arrivals }) => sum + arrivals, 0) / week.length\n          ),\n  }\n})\n\nconst chartConfig = {\n  arrivals: {\n    label: \"Arrivals\",\n    color: \"var(--chart-1)\",\n  },\n  average: {\n    label: \"7-day average\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\n// The level at which the department calls in extra staff; set your own.\nconst surge = 220\n\n// What happened, marked on the timeline.\nconst events = [\n  { date: \"2026-05-04\", label: \"Bank holiday\" },\n  { date: \"2026-05-18\", label: \"Heatwave\" },\n]\n\nconst latest = chartData.at(-1)!\nconst peak = chartData.reduce((a, b) =>\n  (b.average ?? 0) > (a.average ?? 0) ? b : a\n)\nconst daysOver = chartData.filter(({ arrivals }) => arrivals > surge).length\nconst belowSurge = (latest.average ?? 0) < surge\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 ChartAreaEdArrivals() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>ED arrivals</CardTitle>\n        <CardDescription>\n          Daily, April to June, with the 7-day average; illustrative data\n        </CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {latest.average}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              a day, last 7 days\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {belowSurge ? (\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            {belowSurge ? \"Below surge\" : \"In surge\"}\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          <ComposedChart\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={[140, 260]}\n              ticks={[160, 200, 240]}\n              allowDataOverflow\n            />\n            <ChartTooltip\n              cursor={false}\n              content={\n                <ChartTooltipContent\n                  indicator=\"line\"\n                  labelFormatter={(value) =>\n                    formatDate(String(value), { weekday: \"short\" })\n                  }\n                />\n              }\n            />\n            {/* Each day faint, the average strong. */}\n            <Bar\n              dataKey=\"arrivals\"\n              fill=\"var(--color-arrivals)\"\n              fillOpacity={0.35}\n              radius={[2, 2, 0, 0]}\n            />\n            <Line\n              dataKey=\"average\"\n              type=\"monotone\"\n              stroke=\"var(--color-average)\"\n              strokeWidth={2}\n              dot={false}\n            />\n            <ReferenceLine\n              y={surge}\n              stroke=\"var(--muted-foreground)\"\n              strokeDasharray=\"4 4\"\n            >\n              <Label\n                value={`Surge ${surge}`}\n                position=\"insideTopRight\"\n                className=\"fill-muted-foreground\"\n                fontSize={11}\n              />\n            </ReferenceLine>\n            {events.map((event) => (\n              <ReferenceLine\n                key={event.date}\n                x={event.date}\n                stroke=\"var(--muted-foreground)\"\n              >\n                <Label\n                  value={event.label}\n                  position=\"insideTopLeft\"\n                  className=\"fill-foreground\"\n                  fontSize={11}\n                />\n              </ReferenceLine>\n            ))}\n            <ChartLegend content={<ChartLegendContent />} />\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          Average peaked at {peak.average} a day, week to{\" \"}\n          {formatDate(peak.date)}\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          {daysOver} days over the surge level; illustrative data\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "fullWidth": true
  },
  "docs": "ED arrivals area chart: https://organui.com/charts/area#chart-area-ed-arrivals",
  "categories": [
    "charts",
    "charts-area"
  ],
  "type": "registry:block"
}