{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "heatmap-02",
  "description": "The share of each weekly signup cohort still active in each week after signup, as a shaded grid.",
  "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/retention.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/heatmap/heatmap-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { HeatmapLegend } from '@/registry/components/dashboardblocks/heatmap'\nimport {\n  CohortTable,\n  type RetentionCohort,\n  getAverageRetention,\n} from '@/registry/components/dashboardblocks/retention'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Heatmap2Props extends BlockStateProps {\n  /** Oldest first, one per signup week. Leave out, or pass none, to show the empty state. */\n  cohorts?: RetentionCohort[]\n  /** Defaults to a sentence about week 1 retention. */\n  description?: string\n  title: string\n}\n\nconst COHORT_SIZES = [1_204, 1_318, 1_156, 1_402, 1_377, 1_511, 1_463]\n\nconst exampleProps: Heatmap2Props = {\n  cohorts: ['Aug 3', 'Aug 10', 'Aug 17', 'Aug 24', 'Aug 31', 'Sep 7', 'Sep 14'].map(\n    (label, index) => {\n      const size = COHORT_SIZES[index]\n      return {\n        label,\n        retained: [\n          size,\n          ...Array.from({ length: COHORT_SIZES.length - index - 1 }, (_, week) => {\n            const share = (58 + index * 1.5) * Math.exp(-week * 0.24) + 14 - week * 0.6\n            return Math.round((size * share) / 100)\n          }),\n        ],\n        size,\n      }\n    },\n  ),\n  title: 'Retention by cohort',\n}\n\nconst Heatmap2 = (props: Heatmap2Props) => {\n  const { cohorts = [], errorMessage, status, title } = props\n  const state = getBlockState(status, cohorts)\n  const averages = getAverageRetention(cohorts)\n  const firstWeek = averages[1]\n  const {\n    description = firstWeek == null\n      ? 'No cohort has reached its first week yet.'\n      : `${formatPercent(firstWeek, { maximumFractionDigits: 0 })} of each weekly signup cohort is still active a week later, on average.`,\n  } = props\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              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            {state ? (\n              <div className='border-t pt-4'>\n                <BlockStateRows rows={7} />\n              </div>\n            ) : (\n              <CohortTable\n                caption={`${title}: the share of each weekly signup cohort still active, by week since signup. The last row is the average, weighted by cohort size.`}\n                className='border-t pt-4'\n                cohorts={cohorts}\n                footer={<HeatmapLegend low='Fewer' high='More retained' />}\n                minWidth='32rem'\n                periodName='Week'\n                sizeHeader='Signups'\n              />\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Heatmap2, exampleProps as heatmap2ExampleProps, type Heatmap2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/heatmap/heatmap-02.tsx"
    }
  ],
  "meta": {
    "shows": "The share of each weekly signup cohort still active in each week after signup, as a shaded grid.",
    "size": "full",
    "usedWith": [
      "retention-02",
      "retention-04"
    ],
    "component": "Heatmap2",
    "props": "{ cohorts?: { label: string; size: number; retained: number[]; color?: string; icon?: ReactNode; eligible?: number[]; filling?: boolean }[]; description?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
