{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "heatmap-01",
  "description": "When visitors arrive, as a grid of weekday by hour, darker where there are more.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/heatmap.json",
    "https://www.dashboardblocks.com/r/radix/stat-group.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/heatmap/heatmap-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  HeatmapGrid,\n  HeatmapLegend,\n  getColumnTotals,\n  getPeak,\n} from '@/registry/components/dashboardblocks/heatmap'\nimport {\n  Stat,\n  StatGroup,\n  StatLabel,\n  StatValue,\n} from '@/registry/components/dashboardblocks/stat-group'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Heatmap1Props extends BlockStateProps {\n  /** Defaults to a sentence about the busiest time. */\n  description?: string\n  title: string\n  unit: string\n  /** Seven rows, Monday first, of 24 hourly values. Leave out to show the empty state. */\n  values?: number[][]\n}\n\nconst DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']\nconst DAY_NAMES = [\n  'Monday',\n  'Tuesday',\n  'Wednesday',\n  'Thursday',\n  'Friday',\n  'Saturday',\n  'Sunday',\n]\nconst HOURS = Array.from({ length: 24 }, (_, hour) => String(hour).padStart(2, '0'))\n\nconst exampleProps: Heatmap1Props = {\n  title: 'When people visit',\n  unit: 'sessions',\n  values: DAYS.map((_, day) =>\n    HOURS.map((_, hour) => {\n      const weekend = day >= 5\n      const workday = Math.exp(-((hour - 14) ** 2) / 18) * (weekend ? 0.45 : 1)\n      const evening = Math.exp(-((hour - 21) ** 2) / 6) * (weekend ? 0.8 : 0.5)\n      const night = hour < 6 ? 0.04 : 0\n      return Math.round(40 + 1_240 * (workday + evening + night) * (1 - day * 0.03))\n    }),\n  ),\n}\n\nconst hourRange = (hour: number) =>\n  `${HOURS[hour]}:00–${String((hour + 1) % 24).padStart(2, '0')}:00`\n\nconst Heatmap1 = (props: Heatmap1Props) => {\n  const { errorMessage, status, title, unit, values = [] } = props\n  const peak = getPeak(values)\n  const byHour = getColumnTotals(values)\n  const peakHour = byHour.reduce(\n    (top, value, hour) => (value > byHour[top] ? hour : top),\n    0,\n  )\n  const week = byHour.reduce((sum, value) => sum + value, 0)\n  const weekend = values\n    .slice(5)\n    .flat()\n    .reduce((sum, value) => sum + value, 0)\n  const unitName = unit.charAt(0).toUpperCase() + unit.slice(1)\n  const {\n    description = peak\n      ? `${DAY_NAMES[peak.row]} at ${HOURS[peak.column]}:00 is the busiest hour of an average week, with ${formatNumber(peak.value)} ${unit}.`\n      : undefined,\n  } = props\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, peak)}>\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              <BlockReady className='text-sm'>\n                {description && (\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                )}\n              </BlockReady>\n            </header>\n            <StatGroup className='grid-cols-2 @xl:grid-cols-3'>\n              <Stat className='col-span-2 @xl:col-span-1'>\n                <StatLabel>{unitName} in an average week</StatLabel>\n                <StatValue>{formatNumber(week)}</StatValue>\n              </Stat>\n              <Stat className='justify-end'>\n                <StatLabel>Busiest hour of the day</StatLabel>\n                <StatValue className='text-2xl'>{HOURS[peakHour]}:00</StatValue>\n              </Stat>\n              <Stat className='justify-end'>\n                <StatLabel>On weekends</StatLabel>\n                <StatValue className='text-2xl'>\n                  {formatPercent(week > 0 ? weekend / week : 0, {\n                    maximumFractionDigits: 0,\n                  })}\n                </StatValue>\n              </Stat>\n            </StatGroup>\n            <HeatmapGrid\n              cellClassName='h-5'\n              cellName={({ column, row }) => `${DAYS[row]}, ${hourRange(column)}`}\n              columnLabelEvery={3}\n              columnSummary={{\n                highlightIndex: peakHour,\n                label: `${unitName} by hour of the day, all week: most at ${HOURS[peakHour]}:00, with ${formatNumber(byHour[peakHour])}`,\n                labels: HOURS.map((_, hour) => `${hourRange(hour)}, all week`),\n                values: byHour,\n              }}\n              columns={HOURS}\n              describe={({ column, row }, value) =>\n                `${DAY_NAMES[row]}, ${hourRange(column)}: ${value === null ? 'no data' : formatNumber(value)} ${unit}`\n              }\n              footer={<HeatmapLegend />}\n              label={`${title}: average ${unit} by weekday and hour`}\n              rowHeader='Day'\n              rowNames={DAY_NAMES}\n              rows={DAYS}\n              valueName={unitName}\n              values={values}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Heatmap1, exampleProps as heatmap1ExampleProps, type Heatmap1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/heatmap/heatmap-01.tsx"
    }
  ],
  "meta": {
    "shows": "When visitors arrive, as a grid of weekday by hour, darker where there are more.",
    "size": "full",
    "usedWith": [
      "stat-group-03",
      "geo-04",
      "retention-03"
    ],
    "component": "Heatmap1",
    "props": "{ description?: string; title: string; unit: string; values?: number[][]; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
