{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-revenue-target",
  "title": "Revenue vs target",
  "author": "andongmin94",
  "description": "Weekly revenue with period controls, target variance, and an exact data table.",
  "dependencies": [
    "recharts@^3.10.1"
  ],
  "registryDependencies": [
    "https://neobrutal-ui.andongmin.com/r/chart.json",
    "https://neobrutal-ui.andongmin.com/r/card.json"
  ],
  "files": [
    {
      "path": "src/components/ui/chart-revenue-target.tsx",
      "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { Bar, CartesianGrid, ComposedChart, Line, XAxis, YAxis } from \"recharts\";\n\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport {\n  ChartContainer,\n  ChartSelect,\n  ChartTooltip,\n  ChartTooltipContent,\n  type ChartConfig,\n} from \"@/components/ui/chart\";\n\nconst weeks = [\n  { week: \"W1\", revenue: 12400, target: 14000 },\n  { week: \"W2\", revenue: 15100, target: 14000 },\n  { week: \"W3\", revenue: 13800, target: 15000 },\n  { week: \"W4\", revenue: 17200, target: 15000 },\n  { week: \"W5\", revenue: 16400, target: 16000 },\n  { week: \"W6\", revenue: 18900, target: 16000 },\n  { week: \"W7\", revenue: 17600, target: 17000 },\n  { week: \"W8\", revenue: 21400, target: 17000 },\n];\nconst config = {\n  revenue: { label: \"Revenue\", color: \"var(--chart-1)\" },\n  target: { label: \"Target\", color: \"var(--foreground)\" },\n} satisfies ChartConfig;\nconst money = new Intl.NumberFormat(\"en-US\", {\n  style: \"currency\",\n  currency: \"USD\",\n  maximumFractionDigits: 0,\n});\n\nexport default function Component() {\n  const [range, setRange] = useState(\"4\");\n  const data = weeks.slice(-Number(range));\n  const revenue = data.reduce((total, row) => total + row.revenue, 0);\n  const target = data.reduce((total, row) => total + row.target, 0);\n  const gap = revenue - target;\n  const belowTarget = data.filter((row) => row.revenue < row.target).length;\n\n  return (\n    <Card className=\"h-full min-w-0\" data-chart-recipe=\"revenue\">\n      <CardHeader>\n        <p className=\"font-mono text-xs uppercase tracking-widest\">01 / Plan and compare</p>\n        <CardTitle>\n          <h3>Revenue vs target</h3>\n        </CardTitle>\n        <CardDescription>\n          Weekly revenue against an explicit plan. Sample data in USD.\n        </CardDescription>\n      </CardHeader>\n      <CardContent className=\"grid min-w-0 gap-6\">\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <ChartSelect\n            label=\"Revenue period\"\n            value={range}\n            onValueChange={setRange}\n            options={[\n              { value: \"4\", label: \"Last 4 weeks\" },\n              { value: \"8\", label: \"All 8 weeks\" },\n            ]}\n          />\n          <p className=\"text-xs leading-5 text-foreground/75\">\n            Bars: revenue / dashed line: target\n          </p>\n        </div>\n        <dl className=\"grid gap-4 border-y-2 border-border py-4 sm:grid-cols-3\" aria-live=\"polite\">\n          {[\n            [\"Revenue\", money.format(revenue)],\n            [\"Target\", money.format(target)],\n            [\"Variance\", `${gap >= 0 ? \"+\" : \"−\"}${money.format(Math.abs(gap))}`],\n          ].map(([label, value]) => (\n            <div key={label}>\n              <dt className=\"text-xs text-foreground/75\">{label}</dt>\n              <dd className=\"mt-1 text-2xl font-heading tabular-nums\">{value}</dd>\n            </div>\n          ))}\n        </dl>\n        <figure className=\"min-w-0\" aria-label=\"Weekly revenue and target\">\n          <ChartContainer config={config} className=\"h-64 w-full min-w-0 aspect-auto\">\n            <ComposedChart\n              accessibilityLayer\n              data={data}\n              margin={{ top: 12, right: 8, bottom: 0, left: 0 }}\n            >\n              <CartesianGrid vertical={false} />\n              <XAxis dataKey=\"week\" tickLine={false} axisLine={false} tickMargin={10} />\n              <YAxis\n                tickLine={false}\n                axisLine={false}\n                width={48}\n                tickFormatter={(value) => `$${Number(value) / 1000}k`}\n                domain={[0, \"auto\"]}\n              />\n              <ChartTooltip\n                content={\n                  <ChartTooltipContent\n                    formatter={(value, name) =>\n                      `${name === \"revenue\" ? \"Revenue\" : \"Target\"}: ${money.format(Number(value))}`\n                    }\n                  />\n                }\n              />\n              <Bar\n                dataKey=\"revenue\"\n                fill=\"var(--color-revenue)\"\n                maxBarSize={48}\n                radius={[3, 3, 0, 0]}\n                isAnimationActive={false}\n              />\n              <Line\n                dataKey=\"target\"\n                type=\"linear\"\n                stroke=\"var(--color-target)\"\n                strokeWidth={2}\n                strokeDasharray=\"6 4\"\n                dot={false}\n                isAnimationActive={false}\n              />\n            </ComposedChart>\n          </ChartContainer>\n        </figure>\n        <output className=\"border-l-4 border-main pl-3 text-sm leading-6\">\n          {((revenue / target) * 100).toFixed(1)}% of target achieved. {belowTarget} of{\" \"}\n          {data.length} weeks below plan.\n        </output>\n        <details className=\"min-w-0 border-t-2 border-border pt-4\">\n          <summary className=\"cursor-pointer text-sm font-heading\">View revenue data</summary>\n          {/* oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- Keyboard access to the data-table scroll area. */}\n          <section tabIndex={0} aria-label=\"Revenue values\" className=\"mt-3 overflow-x-auto\">\n            <table className=\"w-full text-left text-xs tabular-nums\">\n              <caption className=\"pb-3 text-left text-foreground/75\">\n                The same {data.length} weeks shown in the chart. USD.\n              </caption>\n              <thead>\n                <tr>\n                  {[\"Week\", \"Revenue\", \"Target\", \"Variance\"].map((label) => (\n                    <th key={label} scope=\"col\" className=\"border-b-2 border-border py-2 pr-3\">\n                      {label}\n                    </th>\n                  ))}\n                </tr>\n              </thead>\n              <tbody>\n                {data.map((row) => (\n                  <tr key={row.week}>\n                    <th scope=\"row\" className=\"py-2 pr-3\">\n                      {row.week}\n                    </th>\n                    <td className=\"pr-3\">{money.format(row.revenue)}</td>\n                    <td className=\"pr-3\">{money.format(row.target)}</td>\n                    <td>{money.format(row.revenue - row.target)}</td>\n                  </tr>\n                ))}\n              </tbody>\n            </table>\n          </section>\n        </details>\n      </CardContent>\n    </Card>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "data-display",
    "data-visualization",
    "recipe"
  ],
  "type": "registry:component"
}