# Contribution Graph

> A composable calendar heatmap for showing daily activity across weeks and months.

Source: https://www.honestui.com/docs/charts/contribution-graph/static

### Basic Contribution Graph

```tsx
"use client";

import { ContributionGraph, type ChartConfig } from "honestui/charts";

// Scenario: A year of commits
const start = Date.UTC(2025, 0, 1);
const data = Array.from({ length: 365 }, (_, day) => {
  const date = new Date(start + day * 86_400_000);
  const weekday = date.getUTCDay();
  const isWeekend = weekday === 0 || weekday === 6;
  // Deterministic noise: a busy spring, a quiet August, lighter weekends.
  const noise = Math.abs(Math.sin(day * 12.9898) * 43758.5453) % 1;
  const season = 1 + Math.sin((day / 365) * Math.PI * 2 + 0.6) * 0.6;
  const holiday = day > 212 && day < 236 ? 0.15 : 1;
  const commits = noise < (isWeekend ? 0.7 : 0.18) ? 0 : Math.round(noise * 9 * season * holiday * (isWeekend ? 0.4 : 1));
  return { date: date.toISOString().slice(0, 10), commits };
});

const chartConfig = {
  commits: {
    label: "Commits",
    colors: {
      light: ["#16a34a"],
      dark: ["#22c55e"],
    },
  },
} satisfies ChartConfig;

export function ExampleContributionGraph() {
  return (
    <ContributionGraph
      data={data}
      config={chartConfig}
      dateKey="date"
      valueKey="commits"
      range={2025}
      className="h-full w-full p-4"
    >
      <ContributionGraph.Months />
      <ContributionGraph.Weekdays />
      <ContributionGraph.Legend />
      <ContributionGraph.Tooltip valueFormatter={(value) => `${value} ${value === 1 ? "commit" : "commits"}`} />
      <ContributionGraph.Cells />
    </ContributionGraph>
  );
}

```

## Overview [#overview]

Use a contribution graph to show daily activity over a long period: commits, workouts, orders, or support load. Each day is a cell in a week column, so streaks, weekly rhythms, quiet seasons, and holidays stand out at a glance. It answers "how consistent was this?" better than a line chart, which hides the day-of-week pattern.

## Anatomy [#anatomy]

`ContributionGraph` owns the daily data, the date range, the first day of the week, and the loading state. Every day in the range is drawn; days without data are empty. Add `Cells` for size, gaps, and levels, `Months` and `Weekdays` for labels, `Legend` for the "Less … More" scale, and `Tooltip` for the date and value of a day. Rows on the same day add up.

Cells take discrete levels from the value's `config` color: a single color steps from 30% to full opacity, and a multi-stop color uses one stop per level. The empty level is a faint wash of the foreground.

## Accessibility [#accessibility]

When `ariaLabel` is omitted, the generated name gives the date range, the total, and the number of active days. Levels differ in lightness as well as hue, and the legend shows every level in order. The tooltip is pointer-operated, so summarize streaks, totals, or busy days in nearby text when people need them.

## Installation [#installation]

<CommandBlock commands="[&#x22;honestui&#x22;]" />

## Usage [#usage]

The data has one row per day, or several rows per day that add up. `dateKey` holds a `YYYY-MM-DD` string, a timestamp, or a Date.

```tsx
import { ContributionGraph, type ChartConfig } from "honestui/charts";
```

```tsx
<ContributionGraph
  data={data}
  config={chartConfig}
  dateKey="date"
  valueKey="commits"
  range={2025}
>
  <ContributionGraph.Months />
  <ContributionGraph.Weekdays />
  <ContributionGraph.Legend />
  <ContributionGraph.Tooltip />
  <ContributionGraph.Cells />
</ContributionGraph>
```

Without `range`, the graph shows the 52 weeks ending on the latest day in `data`. Cells grow to fill the container's width, up to `maxSize`, and the whole block is centered.

### Thresholds and Week Start [#thresholds-and-week-start]

### thresholds and weekStart={1}

```tsx
"use client";

import { ContributionGraph, type ChartConfig } from "honestui/charts";

// Scenario: Daily running distance over six months, weeks starting Monday
const start = Date.UTC(2025, 3, 1);
const data = Array.from({ length: 183 }, (_, day) => {
  const weekday = new Date(start + day * 86_400_000).getUTCDay();
  const noise = Math.abs(Math.sin(day * 78.233) * 12345.6789) % 1;
  // Long runs on Sundays, rest days on Mondays, easy runs otherwise.
  const km = weekday === 1 ? 0 : weekday === 0 ? 14 + Math.round(noise * 10) : noise < 0.3 ? 0 : 4 + Math.round(noise * 6);
  return { day: new Date(start + day * 86_400_000).toISOString().slice(0, 10), km };
});

const chartConfig = {
  km: {
    label: "Distance",
    colors: {
      light: ["#fed7aa", "#fb923c", "#ea580c", "#9a3412"],
      dark: ["#7c2d12", "#c2410c", "#f97316", "#fdba74"],
    },
  },
} satisfies ChartConfig;

export function ExampleContributionGraph() {
  return (
    <ContributionGraph
      data={data}
      config={chartConfig}
      dateKey="day"
      valueKey="km"
      range={["2025-04-01", "2025-09-30"]}
      weekStart={1}
      className="h-full w-full p-4"
    >
      <ContributionGraph.Months />
      <ContributionGraph.Weekdays show="all" />
      <ContributionGraph.Legend lessLabel="Rest" moreLabel="Long run" />
      <ContributionGraph.Tooltip valueFormatter={(value) => `${value} km`} />
      <ContributionGraph.Cells thresholds={[1, 6, 9, 14]} maxSize={18} radius={3} />
    </ContributionGraph>
  );
}

```

By default, levels split the range from zero to the busiest day evenly. Pass `thresholds` to set the lower bound of each level yourself, which keeps levels stable as data changes. This example starts weeks on Monday, labels every weekday, uses a four-stop color, and renames the legend ends.

### Loading State [#loading-state]

### isLoading='true'

```tsx
"use client";

import { ContributionGraph, type ChartConfig } from "honestui/charts";

const chartConfig = {
  commits: { label: "Commits", colors: { light: ["#16a34a"], dark: ["#22c55e"] } },
} satisfies ChartConfig;

export function LoadingContributionGraph() {
  return (
    <ContributionGraph
      data={[]}
      config={chartConfig}
      dateKey="date"
      valueKey="commits"
      range={2025}
      isLoading
      className="h-full w-full p-4"
    >
      <ContributionGraph.Months />
      <ContributionGraph.Weekdays />
      <ContributionGraph.Legend />
      <ContributionGraph.Cells />
    </ContributionGraph>
  );
}

```

Pass `isLoading` to reserve the layout with a neutral cell pattern and the same loading treatment as the other Honest UI charts.

## API Reference [#api-reference]

<ApiHeading>
  ContributionGraph
</ApiHeading>


  ### `data`

type: `TData[]`

Rows with a day and a value. Several rows on one day add up.

  ### `config`

type: `ChartConfig`

Defines the label and theme colors for `valueKey`.

  ### `dateKey`

type: `keyof TData & string`

The field holding each row's day: a `YYYY-MM-DD` string, a timestamp, or a Date.

  ### `valueKey`

type: `keyof TData & string`

The numeric field counted on each day.

  ### `range`

type: `number | [start, end]`

A year, or a pair of days. Defaults to the 52 weeks ending on the latest day in `data`.

  ### `weekStart`

type: `0 | 1 | 2 | 3 | 4 | 5 | 6` · default: `0`

First day of each week column, where 0 is Sunday and 1 is Monday.

  ### `className`

type: `string`

Additional CSS classes for the chart container. Give the chart an explicit height.

  ### `animation`

type: `boolean` · default: `true`

Enables the intro animation. Reduced-motion preferences disable it automatically.

  ### `isLoading`

type: `boolean` · default: `false`

Replaces the data with a neutral cell pattern and a progress label.

  ### `ariaLabel`

type: `string`

Accessible name for the canvas chart. A summary of the range and total is generated when omitted.

  ### `onDayClick`



) => void">
    Fires when a day is selected and `Cells` has `isClickable`.

  ### `chartOptions`



">
    Escape hatch merged over the generated ECharts option object.


<ApiHeading>
  Cells
</ApiHeading>


  ### `radius`

type: `number` · default: `2`

Cell corner radius in pixels.

  ### `gap`

type: `number` · default: `2`

Space between cells in pixels.

  ### `levels`

type: `number` · default: `4`

Number of colored levels above the empty level.

  ### `thresholds`

type: `number[]`

Lower bound of each colored level, ascending. Overrides `levels`.

  ### `maxSize`

type: `number` · default: `14`

Largest cell size in pixels. Cells shrink to fit the container.

  ### `isClickable`

type: `boolean` · default: `false`

Enables the pointer cursor and `onDayClick`.


<ApiHeading>
  Months
</ApiHeading>


  ### `tickFormatter`



string">
    Formats a month label, given the month index (0 is January) and year.


<ApiHeading>
  Weekdays
</ApiHeading>


  ### `show`

type: `&#x22;alternate&#x22; | &#x22;all&#x22;` · default: `&#x22;alternate&#x22;`

Labels every other row, like Mon, Wed, Fri, or every row.

  ### `labels`

type: `string[]`

Seven day labels, Sunday first.


<ApiHeading>
  Legend
</ApiHeading>


  ### `lessLabel`

type: `string` · default: `&#x22;Less&#x22;`

Label before the lowest level.

  ### `moreLabel`

type: `string` · default: `&#x22;More&#x22;`

Label after the highest level.

  ### `align`

type: `&#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;right&#x22;`

Aligns the legend to the grid's left or right edge.


<ApiHeading>
  Tooltip
</ApiHeading>


  ### `variant`

type: `&#x22;default&#x22; | &#x22;frosted-glass&#x22;` · default: `&#x22;default&#x22;`

Tooltip surface treatment.

  ### `roundness`

type: `&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;` · default: `&#x22;lg&#x22;`

Tooltip corner radius.

  ### `position`

type: `&#x22;fixed&#x22; | &#x22;variable&#x22;` · default: `&#x22;variable&#x22;`

Pins the tooltip to the top or lets it follow the pointer.

  ### `valueFormatter`



string">
    Formats the value shown in the tooltip.

  ### `dateFormatter`



string">
    Formats the day shown as the tooltip title.
