{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-service-latency",
  "title": "Response-time budget",
  "author": "andongmin94",
  "description": "Daily p50 and p95 with service controls, budget breaches, 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-service-latency.tsx",
      "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { CartesianGrid, Line, LineChart, ReferenceLine, 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 samples: Record<\"API\" | \"Search\", Array<[number, number]>> = {\n  API: [\n    [80, 210],\n    [76, 195],\n    [95, 340],\n    [130, 470],\n    [100, 330],\n    [82, 240],\n    [79, 215],\n  ],\n  Search: [\n    [105, 270],\n    [112, 290],\n    [118, 310],\n    [110, 280],\n    [108, 260],\n    [102, 250],\n    [99, 245],\n  ],\n};\nconst days = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\nconst budget = 300;\nconst config = {\n  p50: { label: \"p50\", color: \"var(--foreground)\" },\n  p95: {\n    label: \"p95\",\n    // Keep the palette hue without losing the line against its background.\n    color: \"color-mix(in srgb, var(--chart-1) 50%, var(--foreground))\",\n  },\n} satisfies ChartConfig;\n\nexport default function Component() {\n  const [service, setService] = useState<keyof typeof samples>(\"API\");\n  const data = samples[service].map(([p50, p95], index) => ({ day: days[index], p50, p95 }));\n  const breaches = data.filter((row) => row.p95 > budget);\n  const worst = Math.max(...data.map((row) => row.p95));\n\n  return (\n    <Card className=\"h-full min-w-0\" data-chart-recipe=\"latency\">\n      <CardHeader>\n        <p className=\"font-mono text-xs uppercase tracking-widest\">03 / Watch the tail</p>\n        <CardTitle>\n          <h3>Response-time budget</h3>\n        </CardTitle>\n        <CardDescription>\n          Daily p50 and p95 against a 300 ms p95 budget. Illustrative measurements.\n        </CardDescription>\n      </CardHeader>\n      <CardContent className=\"grid min-w-0 gap-6\">\n        <ChartSelect\n          label=\"Service\"\n          value={service}\n          onValueChange={(value) => setService(value as keyof typeof samples)}\n          options={Object.keys(samples).map((value) => ({ value, label: value }))}\n        />\n        <dl className=\"grid grid-cols-2 gap-4 border-y-2 border-border py-4\" aria-live=\"polite\">\n          <div>\n            <dt className=\"text-xs text-foreground/75\">Worst daily p95</dt>\n            <dd className=\"mt-1 text-2xl font-heading tabular-nums\">{worst} ms</dd>\n          </div>\n          <div>\n            <dt className=\"text-xs text-foreground/75\">Days over budget</dt>\n            <dd className=\"mt-1 text-2xl font-heading tabular-nums\">\n              {breaches.length} / {data.length}\n            </dd>\n          </div>\n        </dl>\n        <figure className=\"min-w-0\" aria-label=\"Daily p50 and p95 response times in milliseconds\">\n          <ChartContainer config={config} className=\"h-64 w-full min-w-0 aspect-auto\">\n            <LineChart\n              accessibilityLayer\n              data={data}\n              margin={{ top: 12, right: 12, bottom: 0, left: 0 }}\n            >\n              <CartesianGrid vertical={false} />\n              <XAxis dataKey=\"day\" tickLine={false} axisLine={false} tickMargin={10} />\n              <YAxis domain={[0, 600]} tickLine={false} axisLine={false} width={36} />\n              <ReferenceLine y={budget} stroke=\"var(--foreground)\" strokeDasharray=\"3 4\" />\n              <ChartTooltip\n                content={\n                  <ChartTooltipContent formatter={(value, name) => `${name}: ${value} ms`} />\n                }\n              />\n              <Line\n                dataKey=\"p50\"\n                type=\"linear\"\n                stroke=\"var(--color-p50)\"\n                strokeDasharray=\"8 4\"\n                strokeWidth={2}\n                dot={false}\n                isAnimationActive={false}\n              />\n              <Line\n                dataKey=\"p95\"\n                type=\"linear\"\n                stroke=\"var(--color-p95)\"\n                strokeWidth={3}\n                dot={{ r: 3, fill: \"var(--color-p95)\" }}\n                isAnimationActive={false}\n              />\n            </LineChart>\n          </ChartContainer>\n        </figure>\n        <p className=\"text-xs leading-5 text-foreground/75\">\n          Solid + dots: p95 / long dash: p50 / dotted horizontal line: 300 ms budget.\n        </p>\n        <output className=\"border-l-4 border-main pl-3 text-sm leading-6\">\n          {breaches.length\n            ? `Daily p95 exceeded budget on ${breaches.map((row) => row.day).join(\", \")}.`\n            : \"Every daily p95 stayed within budget.\"}\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 latency data</summary>\n          <table className=\"mt-3 w-full text-left text-xs tabular-nums\">\n            <caption className=\"pb-3 text-left text-foreground/75\">\n              {service}, milliseconds. Daily percentiles are not a pooled weekly percentile.\n            </caption>\n            <thead>\n              <tr>\n                {[\"Day\", \"p50\", \"p95\", \"Budget\"].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.day}>\n                  <th scope=\"row\" className=\"py-2 pr-3\">\n                    {row.day}\n                  </th>\n                  <td className=\"pr-3\">{row.p50}</td>\n                  <td className=\"pr-3\">{row.p95}</td>\n                  <td>{row.p95 > budget ? \"Over\" : \"Within\"}</td>\n                </tr>\n              ))}\n            </tbody>\n          </table>\n        </details>\n      </CardContent>\n    </Card>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "data-display",
    "data-visualization",
    "recipe"
  ],
  "type": "registry:component"
}