{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "distribution-01",
  "description": "Response times in buckets that widen as times grow, with p50, p95 and p99 lines, the buckets over the target in red and the share over it as the headline.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/distribution.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/distribution/distribution-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { ChartPanelTable } from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  DISTRIBUTION_THRESHOLD_COLOR,\n  type DistributionBin,\n  DistributionKey,\n  Histogram,\n  formatDistributionShare,\n  getShareAbove,\n  quantileFromBins,\n} from '@/registry/components/dashboardblocks/distribution'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Distribution1Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  bins?: DistributionBin[]\n  description: string\n  formatter?: (value: number) => string\n  limit?: { label: string; value: number }\n  title: string\n  /** @default 'requests' */\n  unit?: string\n}\n\nconst EDGES = [0, 25, 50, 75, 100, 150, 200, 300, 400, 600, 800, 1_200, 1_600, 2_400]\nconst COUNTS = [\n  1_820, 6_940, 11_260, 12_480, 18_950, 12_310, 11_870, 5_240, 3_120, 1_140, 620, 290,\n  105,\n]\n\nconst exampleProps: Distribution1Props = {\n  bins: COUNTS.map((count, index) => ({ count, x0: EDGES[index], x1: EDGES[index + 1] })),\n  description: 'API response times over the last 24 hours. Buckets widen as times grow.',\n  formatter: (value) =>\n    value >= 1_000\n      ? `${formatNumber(value / 1_000)} s`\n      : `${formatNumber(value, { maximumFractionDigits: 0 })} ms`,\n  limit: { label: 'SLO', value: 800 },\n  title: 'Response time distribution',\n  unit: 'requests',\n}\n\nconst Distribution1 = (props: Distribution1Props) => {\n  const {\n    bins = [],\n    description,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    limit,\n    errorMessage,\n    status,\n    title,\n    unit = 'requests',\n  } = props\n  const state = getBlockState(status, bins)\n  const blank = state === 'empty' || state === 'error'\n\n  const total = bins.reduce((sum, bin) => sum + bin.count, 0)\n  const percentiles = [\n    { label: 'p50', value: quantileFromBins(bins, 0.5) },\n    { label: 'p95', value: quantileFromBins(bins, 0.95) },\n    { label: 'p99', value: quantileFromBins(bins, 0.99) },\n  ]\n  const over = limit ? getShareAbove(bins, limit.value) : 0\n  const range = (bin: DistributionBin) => `${formatter(bin.x0)}–${formatter(bin.x1)}`\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <dl className='grid grid-cols-3 gap-x-6 gap-y-4 border-t pt-4 @md:grid-cols-4'>\n              {limit && (\n                <div className='col-span-3 flex flex-col gap-1 @md:col-span-1'>\n                  <dt className='text-muted-foreground text-sm'>\n                    Over the {limit.label}\n                  </dt>\n                  <dd>\n                    <KPIValue\n                      value={over}\n                      format={(value) =>\n                        formatPercent(value, { minimumFractionDigits: 1 })\n                      }\n                    />\n                  </dd>\n                  <BlockReady className='text-xs'>\n                    <dd className='text-muted-foreground text-xs'>\n                      of {formatNumber(total)} {unit} took over {formatter(limit.value)}\n                    </dd>\n                  </BlockReady>\n                </div>\n              )}\n              {percentiles.map(\n                (percentile, index) =>\n                  (!blank || (!limit && index === 0)) && (\n                    <div key={percentile.label} className='flex flex-col gap-1'>\n                      <dt className='text-muted-foreground text-sm'>\n                        {percentile.label}\n                      </dt>\n                      <dd>\n                        <KPIValue\n                          className={limit || index > 0 ? 'text-2xl' : undefined}\n                          value={percentile.value}\n                          format={formatter}\n                        />\n                      </dd>\n                    </div>\n                  ),\n              )}\n            </dl>\n            {!blank && (\n              <ul className='text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1 text-xs'>\n                <li className='flex items-center gap-1.5'>\n                  <DistributionKey shape='bar' />\n                  {unit.charAt(0).toUpperCase()}\n                  {unit.slice(1)}\n                </li>\n                {limit && (\n                  <li className='flex items-center gap-1.5'>\n                    <DistributionKey color={DISTRIBUTION_THRESHOLD_COLOR} shape='bar' />\n                    Over the {limit.label}\n                  </li>\n                )}\n                <li className='flex items-center gap-1.5'>\n                  <DistributionKey shape='median' />\n                  Percentiles\n                </li>\n              </ul>\n            )}\n            <Histogram\n              aria-label={`${title} chart`}\n              bins={bins}\n              className='h-64'\n              formatEdge={formatter}\n              markers={percentiles}\n              threshold={\n                limit\n                  ? {\n                      label: `${limit.label} ${formatter(limit.value)}`,\n                      value: limit.value,\n                    }\n                  : undefined\n              }\n              tickEvery={2}\n              unit={unit}\n            />\n            <ChartPanelTable\n              caption={`${title}: ${description} p50 ${formatter(percentiles[0].value)}, p95 ${formatter(percentiles[1].value)}, p99 ${formatter(percentiles[2].value)}.`}\n              columns={[\n                { key: 'label', label: 'Response time' },\n                { key: 'count', label: unit.charAt(0).toUpperCase() + unit.slice(1) },\n                { key: 'share', label: 'Share' },\n              ]}\n              rows={bins.map((bin) => ({\n                count: formatNumber(bin.count),\n                label: range(bin),\n                share: formatDistributionShare(bin.count / (total || 1)),\n              }))}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Distribution1,\n  exampleProps as distribution1ExampleProps,\n  type Distribution1Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/distribution/distribution-01.tsx"
    }
  ],
  "meta": {
    "shows": "Response times in buckets that widen as times grow, with p50, p95 and p99 lines, the buckets over the target in red and the share over it as the headline.",
    "size": "half",
    "usedWith": [
      "distribution-03",
      "alerts-02"
    ],
    "component": "Distribution1",
    "props": "{ bins?: { x0: number; x1: number; count: number }[]; description: string; formatter?: (value: number) => string; limit?: { label: string; value: number }; title: string; unit?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
