ComponentUpdated in v15

Calendar Heatmap

A year of daily values as a grid of days.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrCalendarHeatmap } from 'ngwr/charts/calendar-heatmap';

@Component({ imports: [WrCalendarHeatmap] })
export class MyComponent {}

Basic

<wr-calendar-heatmap [data]="contributions" />

Tooltip

[tooltip]="false" falls back to the browser title.

<wr-calendar-heatmap [data]="contributions" [tooltip]="false" />

API

NameDescriptionTypeDefault
dataOne entry per day — { date, value }. Days you pass nothing for render as empty cells, so a sparse array is the normal shape rather than a gap.readonly WrHeatmapDatum[][]
ariaLabelAccessible name of the whole grid. Its cells are bare spans whose title a screen reader on a role-less element does not read, so the map used to be several hundred anonymous nodes with no name. Falls back to calendarHeatmap.label.string | nullnull
endDateLast day to render.string | Date | nulltoday
weeksNumber of weeks (columns) to render.number53
cellSizeCell side in CSS pixels.number11
cellGapPixel gap between cells.number2
colorCell fill colour at full intensity.stringprimary
emptyColorBackground colour for zero-value days.stringcolor-mix(in srgb, var(--wr-border-base) 50%, transparent)
showLabelsShow the weekday + month labels around the grid.booleantrue
tooltipShow a tooltip with the day and its count on hover. It is the sentence the square's title carried, so the title is written only while this is off — or the browser would open a second copy a moment later.booleantrue
valueFormatWrites each day's count in the tooltip and the title. null uses Intl.NumberFormat in LOCALE_ID.((value: number) => string) | nullnull

Types

interface WrHeatmapDatum {
  date: string | Date;
  value: number;
}
NameDescriptionTypeDefault
WrHeatmapDatumOne contribution cell.interface—
daterequiredISO date string (YYYY-MM-DD) or Date.string | Date—
valuerequiredCount for the day, shown as a shade.number—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/charts/calendar-heatmap's own element.

VariableDefaultDeclared on
--wr-calendar-heatmap-font-familyvar(--wr-font-family-base).wr-calendar-heatmap
--wr-calendar-heatmap-grid-gapvar(--wr-space-sm).wr-calendar-heatmap
--wr-calendar-heatmap-month-font-sizevar(--wr-text-xs).wr-calendar-heatmap
--wr-calendar-heatmap-weekday-font-sizevar(--wr-text-xs).wr-calendar-heatmap
--wr-calendar-heatmap-weekday-line-heightvar(--wr-leading-none).wr-calendar-heatmap

Dependencies

Built onngwr/date, Popover

See also