# Activity Heatmap

> Plots daily counts across up to twelve weeks with a five-step intensity scale and a readable data list.

- Kind: ui · Category: Data display · Interactivity: native
- Install: `npx shadcn@latest add @haze/activity-heatmap`
- File: `src/components/haze/ui/activity-heatmap.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/activity-heatmap

## Use when
- Daily activity varies enough to show trends by weekday.
- You need a compact view plus the option to read exact daily counts.

## Avoid when
- Events are best understood in chronological detail with descriptions.

## Alternatives
- [timeline](https://hazeui.com/ui/timeline.md)
- [sparkline](https://hazeui.com/ui/sparkline.md)
- [uptime-tracker](https://hazeui.com/ui/uptime-tracker.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| label | `string` | Deployment activity | no | Title for the chart. |
| unit | `string` | deployments | no | Name of the measured activity. |
| unitSingular | `string` |  | no | Singular form of unit, used for a count of 1. Defaults to unit without a trailing "s" (not for -ss or -us). Pass it for irregular plurals such as "series". |
| samples | `Sample[]` | [] | no | Dated counts. Missing dates are bucketed as zero. |
| end | `string` |  | no | Last day to display in YYYY-MM-DD format. |
| weeks | `number` | 8 | no | Number of Monday-aligned weeks, clamped to 1–12. |
| maxCount | `number` |  | no | Optional positive input for the darkest color band. |
| class | `string` |  | no | Classes for the chart panel. |

## Accessibility
- The disclosure includes each date and count in text.
- Future cells in the final week are blank and excluded from the count list.
- Key Enter / Space: Expand or collapse the daily data.
- Key Tab: Focus the scrollable list.
- Key Arrow keys: Scroll the list of counts.

## Agent prompts

### Install and use

Install the Haze UI component "Activity Heatmap" with `npx shadcn@latest add @haze/activity-heatmap`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ActivityHeatmap from "@/components/haze/ui/activity-heatmap.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/activity-heatmap.md

### Customize with real content

Adapt the Haze activity-heatmap ui for our product. Replace the demo values of these props with our real content: label, unit, unitSingular, samples, end, weeks, maxCount, class. Keep the layout, the heading level rules and these accessibility details: The disclosure includes each date and count in text. Future cells in the final week are blank and excluded from the count list. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using activity-heatmap, check it fits: use it when daily activity varies enough to show trends by weekday.; you need a compact view plus the option to read exact daily counts.. Avoid it when events are best understood in chronological detail with descriptions.. Alternatives: @haze/timeline, @haze/sparkline, @haze/uptime-tracker.

## Example requests that should lead here
- Visualize deployment frequency over the last eight weeks.
- Add a compact calendar heatmap for daily signups.

## Source

```astro
---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Sample { date: string; count: number }
interface Props {
  label?: string;
  unit?: string;
  /** Singular form of unit, used when a count is 1. Defaults to unit without a trailing "s" (not for -ss or -us). */
  unitSingular?: string;
  samples?: Sample[];
  end?: string;
  weeks?: number;
  maxCount?: number;
  class?: string;
}

const {
  label = "Deployment activity", unit = "deployments", unitSingular, end, weeks = 8, maxCount,
  samples = [], class: className,
} = Astro.props;
const countByDate = new Map(samples.map(({ date, count }) => [date, Number.isFinite(count) ? Math.max(0, count) : 0]));
const day = 86_400_000;
const newest = end ?? Array.from(countByDate.keys()).sort().at(-1);
const parsed = Date.parse(`${newest}T00:00:00Z`);
const last = Number.isFinite(parsed) ? parsed : Math.floor(Date.now() / day) * day;
const weekCount = Number.isFinite(weeks) ? Math.max(1, Math.min(12, Math.round(weeks))) : 8;
const mondayOffset = (new Date(last).getUTCDay() + 6) % 7;
const first = last - (mondayOffset + (weekCount - 1) * 7) * day;
const dates = Array.from({ length: weekCount * 7 }, (_, index) => {
  const stamp = first + index * day;
  const iso = new Date(stamp).toISOString().slice(0, 10);
  return { stamp, iso, count: countByDate.get(iso) ?? 0, future: stamp > last };
});
const peak = maxCount && Number.isFinite(maxCount) && maxCount > 0 ? maxCount : Math.max(1, ...dates.filter(({ future }) => !future).map(({ count }) => count));
const dateLabel = new Intl.DateTimeFormat("en", { month: "short", day: "numeric", timeZone: "UTC" });
const colors = ["bg-foreground/8", "bg-brand/24", "bg-brand/42", "bg-brand/64", "bg-brand"];
const numberLabel = new Intl.NumberFormat("en");
const singular = unitSingular ?? (/[^su]s$/.test(unit) ? unit.slice(0, -1) : unit);
const unitFor = (count: number) => (count === 1 ? singular : unit);
---

<figure class={cn("grid min-w-0 gap-3 rounded-xl border border-border bg-card p-4.5 text-card-foreground", className)}>
  <figcaption class="grid gap-0.5">
    <span class="text-[0.9375rem]/5 font-medium tracking-[-0.01em]">{label}</span>
    <span class="text-[0.8125rem]/5 text-muted-foreground">{dateLabel.format(first)} to {dateLabel.format(last)}</span>
  </figcaption>
  <div aria-hidden="true" class="grid grid-cols-[auto_minmax(0,1fr)] gap-2">
    <div class="grid grid-rows-7 gap-1 text-xs/4 text-muted-foreground">
      <span>Mon</span><span class="row-start-3">Wed</span><span class="row-start-5">Fri</span><span class="row-start-7">Sun</span>
    </div>
    <div class="grid auto-cols-fr grid-flow-col grid-rows-7 gap-1">
      {dates.map(({ stamp, count, future }) => (
        <div title={future ? undefined : `${dateLabel.format(stamp)} · ${numberLabel.format(count)} ${unitFor(count)}`}
          class={cn("min-h-4 min-w-0 rounded-sm", future ? "bg-transparent" : colors[Math.min(4, Math.ceil(Math.min(1, count / peak) * 4))])}></div>
      ))}
    </div>
  </div>
  <div aria-hidden="true" class="flex min-w-0 flex-wrap items-center justify-end gap-1 text-xs/4 text-muted-foreground">
    <span class="me-1">Less</span>
    {colors.map((color) => <span class={cn("size-2.5 shrink-0 rounded-sm", color)}></span>)}
    <span class="ms-1">More</span>
  </div>
  <details class="group border-t border-border pt-2">
    <summary class="flex min-h-7 cursor-pointer list-none items-center justify-between gap-2 rounded-sm text-[0.8125rem]/5 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
      View daily counts
      <ChevronDown aria-hidden="true" class="size-3.5 transition-[rotate] duration-200 ease-snappy group-open:rotate-180" />
    </summary>
    <div role="region" aria-label={`Daily ${unit}`} tabindex="0"
      class="mt-2 max-h-40 overflow-auto rounded-md border border-frame px-2 py-1 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring">
      <dl class="divide-y divide-border text-[0.8125rem]/5">
        {dates.filter(({ future }) => !future).reverse().map(({ stamp, iso, count }) => (
          <div class="flex min-w-0 flex-wrap items-start justify-between gap-x-2 py-1">
            <dt><time datetime={iso} class="text-muted-foreground">{dateLabel.format(stamp)}</time></dt>
            <dd class="wrap-anywhere text-end tabular-nums">{numberLabel.format(count)} {unitFor(count)}</dd>
          </div>
        ))}
      </dl>
    </div>
  </details>
</figure>
```
