Activity Terrain

A 3D contribution terrain that rises from daily activity — orbit it, drag it, and flip between flat and terrain views.

Activity Terrain

A 3D contribution terrain that rises from daily activity — orbit it, drag it, and flip between flat and terrain views.

The card starts flat, then tilts up into the terrain the first time it scrolls into view — the columns rise in a wave and the day labels fade as the ground lifts. Hover any column to read its day in the header, drag to orbit the board, or throw it and let the flick settle on whichever view it was heading toward. The Flat / Terrain pills switch views directly, and the arrow keys read the grid without a mouse.

Installation

Install the component with the Craft-UI Blocks CLI — it drops activity-terrain.tsx into your project and wires up its runtime dependencies:

npx mvpblocks add activity-terrain
pnpm dlx mvpblocks add activity-terrain
yarn dlx mvpblocks add activity-terrain
bunx mvpblocks add activity-terrain

File Structure

The CLI saves the component to your project's components/ui folder:

Import the default export from @/components/ui/activity-terrain. The prop type is exported as ActivityTerrainProps.

Usage

ActivityTerrain is a client component and every prop is optional — with no props it renders a deterministic 26-week demo. Drop it into any card slot:

"use client";

import ActivityTerrain from "@/components/ui/activity-terrain";

export function ActivityCard() {
  return <ActivityTerrain />;
}

Pass your own counts with data, oldest day first, and name the last day with endDate (YYYY-MM-DD, read in UTC). The grid lays days out Monday to Sunday, so the first value is shifted to the weekday of the computed start date; the header's total and week count come from the data and the laid-out columns:

const counts = [
  0, 3, 7, 2, 0, 0, 1,
  // ...one number per day
];

<ActivityTerrain
  data={counts}
  endDate="2026-10-11"
  title="Contributions"
/>

Start in the heatmap view with defaultFlat, and use className to fit the card into a tighter surface — it lands on the outer wrapper, so the max-w-2xl, radius, border, and background are all overridable:

<ActivityTerrain
  defaultFlat
  title="Reading log"
  className="max-w-md rounded-none border-0 bg-transparent"
/>

Theming

The card surface uses an exact zinc palette: rounded-3xl border-zinc-200 bg-white in light mode, inverting to dark:border-zinc-800 dark:bg-zinc-950. The title is text-zinc-900 (dark:text-zinc-100), the readout is text-zinc-500 tabular-nums (dark:text-zinc-400), the toggle track is bg-zinc-100 (dark:bg-zinc-900) with the active pill on bg-white (dark:bg-zinc-700), and the legend labels share the readout color.

The canvas itself is painted from CSS custom properties rather than Tailwind classes. Light mode ships:

--terrain-0: #f4f4f5;
--terrain-1: #d4d4d8;
--terrain-2: #a1a1aa;
--terrain-3: #52525b;
--terrain-4: #18181b;
--terrain-accent: #10b981;
--terrain-text: #a1a1aa;

and dark mode swaps in --terrain-0: #27272a, --terrain-1: #3f3f46, --terrain-2: #71717a, --terrain-3: #a1a1aa, --terrain-4: #f4f4f5, --terrain-accent: #34d399, and --terrain-text: #71717a. The five levels map to contribution levels 0–4, the accent paints the hovered column, and the text color paints the month and weekday labels. Override any of them through className:

<ActivityTerrain className="[--terrain-accent:#6366f1] [--terrain-4:#4338ca]" />

The palette is read from the canvas's computed style once and cached. It is re-read when the document theme changes — a class, style, or data-theme mutation on <html>, or a prefers-color-scheme change — so light/dark switching repaints automatically.

Animations

  • Intro: the board starts at 0 pitch and springs to 56° with a stiffness of 140 and critical damping, while the yaw coasts from straight on to 18° on a 160ms half-life. It only starts when the canvas first intersects the viewport.
  • Rise wave: each column's rise is offset by its distance from the origin, so the terrain grows outward as a wave instead of popping up at once. A 1.4 overshoot ease lets every column settle with a small bounce, and the origin is the grabbed column or the edge the view is entered from.
  • Hover bump: the hovered column lifts 0.45 cells on a spring (stiffness 400, 0.7 critical damping) while the terrain view is active; in flat view the column only changes color.
  • Orbit drag: dragging turns the board at 0.32° per pixel horizontally and 0.36° per pixel vertically, with rubber-band resistance past ±38° yaw and outside 0–66° pitch.
  • Flick: release velocity is sampled from the last few pointer moves. The pitch is projected 0.15s ahead to pick Flat or Terrain, and the yaw coasts on the same 160ms half-life before an edge spring pulls it back inside ±38°.
  • View toggle: Flat squares the yaw to 0 and springs the pitch down to 0; Terrain turns back in and tilts up to 56°. The rise wave starts from the right edge when flattening and the left edge when raising.
  • Offscreen pause: an IntersectionObserver and visibilitychange stop the animation loop when the card leaves the viewport or the tab is hidden, and resume it when it returns.
  • Reduced motion: the board snaps straight to its target pitch and yaw with no spin, rise travel, or bump, then draws once.

How it works

buildCells walks the data from endDate backwards, shifts the first day to its Monday-based weekday, and assigns each value a column (week) and row (day). A value's level is ceil(normalized × 4) for the legend and its height is 0.06 + normalized^0.85 × 4.2 cells, so zero days stay as small flat tiles while the busiest day becomes the tallest column.

Each frame projects the board with a simple yaw/pitch transform, fits the four board corners into the canvas with 28px of padding, and centers the result. Columns are sorted back to front by depth, then only the camera-facing walls plus the top face are drawn; walls get a 0.22 or 0.38 shade, the top stays unshaded, and a 0.6px stroke in the same color closes the seams between faces.

Hit testing walks the same sorted columns in reverse and point-tests the pointer against the visible face polygons, so hovering follows the actual 3D shapes rather than a flat grid. Month labels and the Mon / Wed / Fri row labels are painted on the ground and fade out as the board lifts (1 − lift × 1.6).

The header readout is aria-live="polite": hovering a day replaces the total with "n contributions on Sun, Oct 11", and leaving the canvas restores "n contributions in the last w weeks". The canvas is a focusable role="img" with a summary label; ArrowLeft / ArrowRight move one column, ArrowUp / ArrowDown move one row, starting from the latest day when nothing is hovered, and blurring the canvas clears the selection.

The canvas backing store is sized with a device-pixel ratio capped at 2 by a ResizeObserver, and the simulation only keeps a requestAnimationFrame loop alive while the card is visible and its springs still have energy.

Props

Prop

Type

Registry Bundle

Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: none — the terrain is drawn with the Canvas API and ships with no runtime packages beyond React.

Contact

If you find any bug or issue, feel free to raise an issue.

Last updated on