{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo-01",
  "description": "Revenue by US state as a tile map on a single-hue scale, with the total and the top five states.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/geo.json",
    "https://www.dashboardblocks.com/r/radix/heatmap.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/leaderboard.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/geo/geo-01.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 { TileMap, US_STATE_TILES } from '@/registry/components/dashboardblocks/geo'\nimport { HeatmapLegend } from '@/registry/components/dashboardblocks/heatmap'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  Leaderboard,\n  LeaderboardBar,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport { formatCurrency, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Geo1Props extends BlockStateProps {\n  /** Defaults to a sentence about the leading states' share. */\n  description?: string\n  formatter?: (value: number) => string\n  title: string\n  valueLabel: string\n  /** By two-letter state code, including DC. Leave out, or pass none, to show the empty state. */\n  values?: Record<string, number>\n}\n\nconst currency = (value: number) => formatCurrency(value, { compact: true })\n\nconst exampleProps: Geo1Props = {\n  formatter: currency,\n  title: 'Revenue by state',\n  valueLabel: 'Revenue',\n  values: {\n    AK: 21_400,\n    AL: 98_600,\n    AR: 57_300,\n    AZ: 226_900,\n    CA: 1_842_300,\n    CO: 281_700,\n    CT: 139_500,\n    DC: 81_200,\n    DE: 33_900,\n    FL: 742_600,\n    GA: 325_800,\n    HI: 55_700,\n    IA: 76_100,\n    ID: 58_900,\n    IL: 458_200,\n    IN: 165_400,\n    KS: 74_300,\n    KY: 97_400,\n    LA: 94_100,\n    MA: 431_600,\n    MD: 224_800,\n    ME: 39_800,\n    MI: 268_900,\n    MN: 212_500,\n    MO: 159_300,\n    MS: 48_200,\n    MT: 30_600,\n    NC: 314_700,\n    ND: 18_900,\n    NE: 51_700,\n    NH: 61_900,\n    NJ: 369_400,\n    NM: 52_600,\n    NV: 111_800,\n    NY: 1_084_500,\n    OH: 297_300,\n    OK: 88_400,\n    OR: 189_600,\n    PA: 392_100,\n    RI: 36_700,\n    SC: 124_200,\n    SD: 21_600,\n    TN: 193_800,\n    TX: 1_016_200,\n    UT: 148_300,\n    VA: 327_400,\n    VT: 24_800,\n    WA: 512_900,\n    WI: 158_700,\n    WV: 26_300,\n    WY: 15_200,\n  },\n}\n\nconst Geo1 = (props: Geo1Props) => {\n  const {\n    formatter = currency,\n    errorMessage,\n    status,\n    title,\n    valueLabel,\n    values = {},\n  } = props\n  const total = Object.values(values).reduce((sum, value) => sum + value, 0)\n  const ranked = US_STATE_TILES.filter((tile) => values[tile.id] !== undefined).sort(\n    (a, b) => values[b.id] - values[a.id],\n  )\n  const top = ranked.slice(0, 5)\n  const topShare = top.reduce((sum, tile) => sum + values[tile.id], 0)\n  const share = (value: number) =>\n    formatPercent(total > 0 ? value / total : 0, { maximumFractionDigits: 0 })\n  const rankedValues = ranked.map((tile) => values[tile.id])\n  const max = rankedValues[0] ?? 1\n  const {\n    description = top.length > 0\n      ? `${top\n          .slice(0, 3)\n          .map((tile) => tile.name)\n          .join(', ')} bring in ${share(\n          top.slice(0, 3).reduce((sum, tile) => sum + values[tile.id], 0),\n        )} of ${valueLabel.toLowerCase()}.`\n      : undefined,\n  } = props\n  const state = getBlockState(status, ranked)\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                {description && (\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                )}\n              </BlockReady>\n            </header>\n            <div className='flex flex-col gap-6 border-t pt-4 @2xl:flex-row @2xl:items-start'>\n              <TileMap\n                className='w-full max-w-xl @2xl:flex-1'\n                describe={(tile, value) =>\n                  value === null\n                    ? `${tile.name}: no data`\n                    : `${tile.name}: ${formatter(value)}, ${share(value)} of total`\n                }\n                footer={\n                  rankedValues.length > 0 && (\n                    <HeatmapLegend\n                      high={formatter(Math.max(...rankedValues))}\n                      low={formatter(Math.min(...rankedValues))}\n                    />\n                  )\n                }\n                format={formatter}\n                label={title}\n                nameHeader='State'\n                scale='sqrt'\n                showShare\n                tiles={US_STATE_TILES}\n                valueHeader={valueLabel}\n                values={values}\n              />\n              <div className='flex flex-col gap-4 @2xl:w-60'>\n                <div className='flex flex-col gap-1'>\n                  <span className='text-muted-foreground text-sm'>\n                    Total {valueLabel.toLowerCase()}\n                  </span>\n                  <KPIValue value={total} format={formatter} />\n                </div>\n                {state === 'loading' && <BlockStateRows rows={5} />}\n                {!state && (\n                  <div className='flex flex-col gap-1.5'>\n                    <p className='text-muted-foreground text-xs'>\n                      Top {top.length}, {share(topShare)} of the total\n                    </p>\n                    <Leaderboard>\n                      {top.map((tile, index) => (\n                        <LeaderboardItem key={tile.id}>\n                          <LeaderboardBar\n                            delay={index * 100}\n                            value={(values[tile.id] / max) * 100}\n                          />\n                          <span\n                            aria-hidden\n                            className='text-muted-foreground w-6 shrink-0 font-mono text-xs'\n                          >\n                            {tile.code}\n                          </span>\n                          <LeaderboardLabel className='truncate'>\n                            {tile.name}\n                          </LeaderboardLabel>\n                          <LeaderboardValue>\n                            {formatter(values[tile.id])}\n                          </LeaderboardValue>\n                        </LeaderboardItem>\n                      ))}\n                    </Leaderboard>\n                  </div>\n                )}\n              </div>\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Geo1, exampleProps as geo1ExampleProps, type Geo1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/geo/geo-01.tsx"
    }
  ],
  "meta": {
    "shows": "Revenue by US state as a tile map on a single-hue scale, with the total and the top five states.",
    "size": "full",
    "usedWith": [
      "geo-02",
      "chart-panel-01"
    ],
    "component": "Geo1",
    "props": "{ description?: string; formatter?: (value: number) => string; title: string; valueLabel: string; values?: Record<string, number>; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
