# Activity Heatmap

> Daily activity across a year as a calendar of shaded days.

Page: https://uicontext.com/docs/components/activity-heatmap

Group: Charts.

## When to use

Daily activity across a year as a calendar of shaded days. Use [Bar Chart](https://uicontext.com/docs/components/bar-chart.md) instead when the days don't matter, only the totals.

## Usage

```ts
import type { ChartDay } from "./ui/uicontext/components/charts/Data.ts"
import { Heatmap } from "./ui/uicontext/components/charts/Heatmap.ts"

const Message = UiSchema.TaggedEnum({
	SelectedDeployDay: { date: Schema.String },
})

export const DeployCalendar = (h: Html.H<typeof Message.Type>, days: ReadonlyArray<ChartDay>) =>
	Heatmap(h, {
		props: { label: "Production deploys", days, noun: { one: "deploy", other: "deploys" } },
		onEmit: {
			// list that day's deploys
			RequestedSelect: ({ date }) => Message.SelectedDeployDay({ date }),
			Highlighted: () => undefined,
			RequestedRetry: () => undefined,
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Deploys

The example the page opens with: Activity Heatmap in “Deploys”.

```ts title="src/demo.ts" source="www/src/examples/activity-heatmap/demo.ts"
import type { Html } from "effect/ui/html"
import { Heatmap } from "./ui/uicontext/components/charts/Heatmap.ts"
import { deployDays } from "./metrics.ts"

// A year of production deploys. Hover or tap a day, or focus the calendar and use the arrow keys:
// left and right move a week, up and down a day.
export const DeployCalendar = <M>(h: Html.H<M>) =>
	Heatmap(h, {
		props: { label: "Production deploys", days: deployDays, end: "2026-11-30", noun: { one: "deploy", other: "deploys" } },
		onEmit: { Highlighted: () => undefined, RequestedSelect: () => undefined, RequestedRetry: () => undefined },
	})
```

### Sample data

The examples above import these files.

```ts title="src/metrics.ts" source="www/src/examples/_shared/metrics.ts"
import type { ChartDatum, ChartDay, ChartSeries } from "./ui/uicontext/components/charts/Data.ts"

// Sample metrics for a software business: revenue, plans, support, deploys, latency and seats.
// Generated from a fixed seed, so every render and every screenshot shows the same numbers.

const seeded = (seed: number) => {
	let state = seed >>> 0
	return () => {
		state = (state * 1664525 + 1013904223) >>> 0
		return state / 2 ** 32
	}
}

const months = ["2025-12", "2026-01", "2026-02", "2026-03", "2026-04", "2026-05", "2026-06", "2026-07", "2026-08", "2026-09", "2026-10", "2026-11"]
const monthStart = (m: string) => `${m}-01`

/** Monthly recurring revenue by source, a year to November 2026. */
export const mrr: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(7)
	let base = 182_000
	let expansion = 21_000
	let added = 14_000
	const rows = months.map((m) => {
		base *= 1.018 + random() * 0.012
		expansion *= 1.03 + random() * 0.03
		added = added * (0.94 + random() * 0.16)
		return { x: monthStart(m), base: Math.round(base), expansion: Math.round(expansion), added: Math.round(added) }
	})
	return [
		{ id: "existing", label: "Existing", points: rows.map((r) => ({ x: r.x, y: r.base })) },
		{ id: "expansion", label: "Expansion", points: rows.map((r) => ({ x: r.x, y: r.expansion })) },
		{ id: "new", label: "New", points: rows.map((r) => ({ x: r.x, y: r.added })) },
	]
})()

/** Revenue this year, and last year's as a dashed comparison. */
export const revenueVsLastYear: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(11)
	let now = 168_000
	let before = 121_000
	const rows = months.map((m) => {
		now *= 1.02 + random() * 0.025
		before *= 1.015 + random() * 0.02
		return { x: monthStart(m), now: Math.round(now), before: Math.round(before) }
	})
	return [
		{ id: "2026", label: "This year", points: rows.map((r) => ({ x: r.x, y: r.now })) },
		{ id: "2025", label: "Last year", line: "dashed", color: "quiet", points: rows.map((r) => ({ x: r.x, y: r.before })) },
	]
})()

/** Revenue, then a forecast drawn dashed from the last actual month. */
export const revenueForecast: ReadonlyArray<ChartSeries> = (() => {
	const actual = revenueVsLastYear[0]?.points ?? []
	const last = actual[actual.length - 1]
	const ahead = ["2026-12-01", "2027-01-01", "2027-02-01", "2027-03-01"]
	let value = last?.y ?? 0
	return [
		{ id: "actual", label: "Revenue", points: [...actual, ...ahead.map((x) => ({ x, y: null }))] },
		{
			id: "forecast",
			label: "Forecast",
			line: "dashed",
			color: 1,
			points: [...actual.map((p, i) => ({ x: p.x, y: i === actual.length - 1 ? p.y : null })), ...ahead.map((x) => ({ x, y: Math.round((value *= 1.028)) }))],
		},
	]
})()

/** New signups each week, by plan. */
export const signupsByPlan: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(23)
	const weeks = Array.from({ length: 12 }, (_, i) => new Date(Date.UTC(2026, 8, 7 + i * 7)).toISOString().slice(0, 10))
	const plan = (id: string, label: string, base: number, growth: number) => {
		let v = base
		return { id, label, points: weeks.map((x) => ({ x, y: Math.round((v *= growth + (random() - 0.5) * 0.18)) })) }
	}
	return [plan("free", "Free", 420, 1.02), plan("pro", "Pro", 160, 1.035), plan("team", "Team", 64, 1.05), plan("enterprise", "Enterprise", 9, 1.04)]
})()

/** Active customers by plan, for a share-of-total donut. */
export const customersByPlan: ReadonlyArray<ChartDatum> = [
	{ id: "free", label: "Free", value: 8_412 },
	{ id: "pro", label: "Pro", value: 2_960 },
	{ id: "team", label: "Team", value: 1_184 },
	{ id: "enterprise", label: "Enterprise", value: 96 },
]

/** Support tickets this week, by status and by day. */
export const ticketsByStatus: ReadonlyArray<ChartSeries> = (() => {
	const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
	const opened = [42, 51, 38, 47, 55, 12, 9]
	const pending = [18, 22, 19, 25, 21, 8, 6]
	const solved = [61, 58, 64, 52, 70, 15, 11]
	return [
		{ id: "open", label: "Open", points: days.map((x, i) => ({ x, y: opened[i] ?? 0 })) },
		{ id: "pending", label: "Pending", points: days.map((x, i) => ({ x, y: pending[i] ?? 0 })) },
		{ id: "solved", label: "Solved", points: days.map((x, i) => ({ x, y: solved[i] ?? 0 })) },
	]
})()

/** Open tickets by queue: long names, for sideways bars. */
export const ticketsByQueue: ReadonlyArray<ChartSeries> = [
	{
		id: "open",
		label: "Open tickets",
		points: [
			{ x: "Billing and invoices", y: 184 },
			{ x: "Account access and sign-in", y: 142 },
			{ x: "Integrations", y: 97 },
			{ x: "Data import and export", y: 66 },
			{ x: "Mobile app", y: 41 },
			{ x: "Feature requests", y: 23 },
		],
	},
]

/** Production deploys per day for 90 days, and how many failed. */
export const deploysPerDay: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(31)
	const days = Array.from({ length: 90 }, (_, i) => new Date(Date.UTC(2026, 8, 2 + i)))
	const rows = days.map((d) => {
		const weekend = d.getUTCDay() === 0 || d.getUTCDay() === 6
		const total = weekend ? Math.round(random() * 3) : Math.round(8 + random() * 14)
		const failed = Math.round(total * random() * 0.18)
		return { x: d.toISOString().slice(0, 10), succeeded: total - failed, failed }
	})
	return [
		{ id: "succeeded", label: "Succeeded", points: rows.map((r) => ({ x: r.x, y: r.succeeded })) },
		{ id: "failed", label: "Failed", color: 8, points: rows.map((r) => ({ x: r.x, y: r.failed })) },
	]
})()

/** Deploys per day as a calendar of activity: a year to Nov 30, 2026. */
export const deployDays: ReadonlyArray<ChartDay> = (() => {
	const random = seeded(37)
	return Array.from({ length: 364 }, (_, i) => {
		const d = new Date(Date.UTC(2025, 11, 2 + i))
		const weekend = d.getUTCDay() === 0 || d.getUTCDay() === 6
		const busy = random()
		const value = weekend ? (busy > 0.8 ? Math.round(random() * 3) : 0) : busy < 0.08 ? 0 : Math.round(2 + busy * busy * 18)
		return { date: d.toISOString().slice(0, 10), value }
	})
})()

/** API latency every 5 minutes for 24 hours: p50 and p95, in milliseconds. */
export const latency: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(41)
	const start = Date.UTC(2026, 10, 30, 0, 0)
	const rows = Array.from({ length: 288 }, (_, i) => {
		const hour = (i * 5) / 60
		const load = 0.6 + 0.4 * Math.sin(((hour - 9) / 24) * Math.PI * 2)
		const spike = i > 180 && i < 192 ? 2.4 : 1
		const p50 = (82 + load * 30 + random() * 12) * (spike > 1 ? 1.4 : 1)
		return { x: start + i * 300_000, p50: Math.round(p50), p95: Math.round((p50 * (2.1 + random() * 0.5)) * spike) }
	})
	return [
		{ id: "p50", label: "p50", points: rows.map((r) => ({ x: r.x, y: r.p50 })) },
		{ id: "p95", label: "p95", points: rows.map((r) => ({ x: r.x, y: r.p95 })) },
	]
})()

/** Hours of use per seat this month, for the busiest seats. */
export const usagePerSeat: ReadonlyArray<ChartSeries> = [
	{
		id: "hours",
		label: "Hours this month",
		points: [
			{ x: "Priya Raman", y: 128 },
			{ x: "Mateo Alvarez", y: 117 },
			{ x: "Hana Kobayashi", y: 96 },
			{ x: "Ben Okafor", y: 88 },
			{ x: "Aleksandra Wiśniewska-Kowalczyk", y: 74 },
			{ x: "Sam Lee", y: 31 },
			{ x: "Jo", y: 4 },
		],
	},
]

/** Weekly revenue as bars and paying customers as a line, on their own axes. */
export const revenueAndCustomers: ReadonlyArray<ChartSeries> = (() => {
	const random = seeded(53)
	const weeks = Array.from({ length: 10 }, (_, i) => new Date(Date.UTC(2026, 8, 21 + i * 7)).toISOString().slice(0, 10))
	let revenue = 41_000
	let customers = 3_820
	const rows = weeks.map((x) => ({ x, revenue: Math.round((revenue *= 1 + (random() - 0.35) * 0.1)), customers: Math.round((customers *= 1.008 + random() * 0.01)) }))
	return [
		{ id: "revenue", label: "Revenue", mark: "bar", format: { style: "currency", currency: "USD", digits: 0 }, points: rows.map((r) => ({ x: r.x, y: r.revenue })) },
		{ id: "customers", label: "Paying customers", mark: "line", axis: "end", format: { style: "number" }, points: rows.map((r) => ({ x: r.x, y: r.customers })) },
	]
})()

/** Trial to paid, step by step, last 30 days. */
export const trialFunnel: ReadonlyArray<ChartDatum> = [
	{ id: "visited", label: "Visited pricing", value: 48_210 },
	{ id: "started", label: "Started a trial", value: 6_904 },
	{ id: "invited", label: "Invited a teammate", value: 2_871 },
	{ id: "connected", label: "Connected a repository", value: 1_966 },
	{ id: "paid", label: "Upgraded to paid", value: 742 },
]

/** A long run for the performance demo: 10,000 readings, one a minute. */
export const tenThousand = (seed = 5): ReadonlyArray<ChartSeries> => {
	const random = seeded(seed)
	const start = Date.UTC(2026, 10, 24)
	let cpu = 42
	let memory = 61
	const xs = Array.from({ length: 10_000 }, (_, i) => start + i * 60_000)
	return [
		{ id: "cpu", label: "CPU", points: xs.map((x) => ({ x, y: Math.round((cpu = Math.max(2, Math.min(98, cpu + (random() - 0.5) * 6 + (random() > 0.998 ? 30 : 0)))) * 10) / 10 })) },
		{ id: "memory", label: "Memory", points: xs.map((x) => ({ x, y: Math.round((memory = Math.max(20, Math.min(96, memory + (random() - 0.5) * 2))) * 10) / 10 })) },
	]
}
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | — |
| `days` (required) | `ChartDay[]` | — | — |
| `end` | `string` | `days` | The last day shown, "2026-11-30"; the latest day in `days` by default |
| `weeks` | `number` | `53` | How many weeks back; 53 by default, a year |
| `noun` | `{ one, other }` | — | What a value counts: { one: "deploy", other: "deploys" } |
| `format` | `ChartFormat` | — | — |
| `tableToggle` | `boolean` | — | — |
| `status` | `ChartStatus` | — | — |
| `error` | `string` | — | — |
| `locale` | `string` | — | — |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `Highlighted` | `{ date: string \| null }` | — |
| `RequestedSelect` | `{ date: string }` | — |
| `RequestedRetry` | `{}` | — |

## Keyboard and accessibility

- Tab to the calendar: Left and Right move a week, Up and Down a day, and each day is announced with its count.
- The shade is never the only cue: the tooltip, the announcement and the table give every day's number.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/activity-heatmap
```

With npm: `npx shadcn@latest add checkfu/uicontext/activity-heatmap`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/activity-heatmap`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/activity-heatmap`.

It writes these files:

- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/charts/Data.ts`
- `src/ui/uicontext/components/charts/Format.ts`
- `src/ui/uicontext/components/charts/Frame.ts`
- `src/ui/uicontext/components/charts/Heatmap.ts`
- `src/ui/uicontext/components/charts/Scale.ts`
- `src/ui/uicontext/components/charts/chart.stylex.ts`
- `src/ui/uicontext/components/charts/slots.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/charts/Heatmap.ts](https://github.com/checkfu/uicontext/blob/main/src/charts/Heatmap.ts)

## Related

- [Chart Foundations](https://uicontext.com/docs/components/chart-foundations.md) (`chart-foundations`): The scales, formats, legend and tooltip every chart shares.
- [Line Chart](https://uicontext.com/docs/components/line-chart.md) (`line-chart`): Values over time for one or many series, with dashed comparisons and forecasts.
- [Area Chart](https://uicontext.com/docs/components/area-chart.md) (`area-chart`): Totals over time and what makes them up, stacked or as shares of 100%.
- [Bar Chart](https://uicontext.com/docs/components/bar-chart.md) (`bar-chart`): Compare categories with grouped, stacked or sideways bars.
- [Combo Chart](https://uicontext.com/docs/components/combo-chart.md) (`combo-chart`): Bars and a line on one time axis, each read against its own scale.
- [Donut Chart](https://uicontext.com/docs/components/donut-chart.md) (`donut-chart`): Shares of one total, with the total in the middle.
