# Hatch Grid

A year of days as hand-drawn squares, one column a week, shaded in five levels from an empty box to solid ink.

Docs: https://ballpoint.st9wd.com/docs/hatch-grid

```bash
npx shadcn@latest add @ballpoint/hatch-grid
```

```tsx
import { HatchGrid } from "@/components/ui/hatch-grid"

<HatchGrid
  data={days} // { date: "2026-01-01", count: 3 }[]
  today="2026-10-06"
  summary="1,203 commits in 2026"
/>
```

Props:

- `data`: `{ date: string; count: number; level?: 0 | 1 | 2 | 3 | 4 }[]`. One entry a day. Level is worked out from count when left out: none, then quarters of the busiest day.
- `today`: `string`. Days after it are drawn dotted, still to come. Where the grid is wider than its box, it opens on this week.
- `unit`: `string | [string, string]` (default `"contribution"`). What's counted, for the hover label ("3 commits on Oct 6th, 2026"). The plural adds an s; pass [one, many] when it doesn't.
- `label`: `(day) => string`. What hovering a day says, in place of the unit's sentence. A function, so pass it from a client component.
- `summary`: `string`. What the grid shows, for screen readers; to them it's one image.

Pen settings: `draw`, `speed` (see Pen settings).

## Example

```tsx
import { createRng, hashSeed } from "@/lib/ink-sketch";
import { HatchGrid, type HatchGridDay } from "@/components/ui/hatch-grid";

// A made-up year of commits: busier midweek, with a few long weekends off.
const r = createRng(hashSeed("hatch-grid-demo"));
const days: HatchGridDay[] = Array.from({ length: 365 }, (_, i) => {
  const date = new Date(Date.UTC(2026, 0, 1 + i)).toISOString().slice(0, 10);
  const weekday = new Date(`${date}T00:00:00Z`).getUTCDay();
  const busy = weekday === 0 || weekday === 6 ? 0.25 : 0.8;
  return { date, count: r() < busy ? Math.round(r() ** 2 * 12) : 0 };
});
const total = days.filter((d) => d.date <= "2026-10-06").reduce((sum, d) => sum + d.count, 0);

export default function HatchGridDemo() {
  return (
    <div className="flex w-full max-w-full flex-col gap-2">
      <HatchGrid
        data={days}
        today="2026-10-06"
        unit="commit"
        summary={`${total} commits in 2026`}
      />
      <p className="text-sm text-ink-3">
        <span className="font-bold text-ink">{total}</span> commits in 2026
      </p>
    </div>
  );
}
```

## Your own levels and labels

Pass level per day to set the shading yourself, and label to write the hover line.

```tsx
"use client";

import { HatchGrid, type HatchGridDay } from "@/components/ui/hatch-grid";

// Twelve weeks of pages written: explicit levels, plus a custom hover line.
const pages = [0, 2, 5, 3, 0, 0, 1, 4, 6, 2, 0, 3, 1, 0, 7, 8, 2, 0, 0, 1, 3, 5, 0, 0];
const days: HatchGridDay[] = Array.from({ length: 84 }, (_, i) => {
  const count = pages[(i * 7) % pages.length] ?? 0;
  return {
    date: new Date(Date.UTC(2026, 6, 13 + i)).toISOString().slice(0, 10),
    count,
    level: count === 0 ? 0 : count < 3 ? 1 : count < 5 ? 2 : count < 7 ? 3 : 4,
  };
});

export default function HatchGridCustom() {
  return (
    <HatchGrid
      data={days}
      today="2026-10-03"
      unit={["page", "pages"]}
      label={(day) => (day.count === 0 ? `A day off, ${day.date}` : `${day.count} written on ${day.date}`)}
      summary="Pages written over twelve weeks"
    />
  );
}
```

## Several habits

The same half-year for three habits, each with its own unit and total.

```tsx
import { createRng, hashSeed } from "@/lib/ink-sketch";
import { HatchGrid, type HatchGridDay } from "@/components/ui/hatch-grid";

// Three made-up habits over the same half-year, each with its own rhythm.
const habits = [
  { name: "Write a page", chance: 0.8, peak: 4, unit: "page" },
  { name: "Draw something", chance: 0.4, peak: 3, unit: "drawing" },
  { name: "Read in bed", chance: 0.6, peak: 2, unit: ["chapter", "chapters"] as [string, string] },
];

function year(name: string, chance: number, peak: number): HatchGridDay[] {
  const r = createRng(hashSeed(name));
  return Array.from({ length: 182 }, (_, i) => {
    const date = new Date(Date.UTC(2026, 3, 1 + i)).toISOString().slice(0, 10);
    return { date, count: r() < chance ? 1 + Math.floor(r() ** 2 * peak) : 0 };
  });
}

export default function HatchGridHabits() {
  return (
    <div className="flex w-full flex-col gap-8">
      {habits.map(({ name, chance, peak, unit }) => {
        const data = year(name, chance, peak);
        const total = data.filter((d) => d.date <= "2026-09-30").reduce((n, d) => n + d.count, 0);
        return (
          <div key={name} className="flex flex-col gap-2">
            <div className="flex items-baseline justify-between">
              <span className="font-bold">{name}</span>
              <span className="text-sm text-ink-3 tabular-nums">{total} since April</span>
            </div>
            <HatchGrid data={data} today="2026-09-30" unit={unit} summary={`${name}: ${total} since April`} />
          </div>
        );
      })}
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
