DateHeatmap
heatmap/date-heatmapFreeComponent
Date × hour matrix for zooming into a narrow time window with daily Sum column.
Live preview
live · rendered by the registry
Rendered by @heatmap on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://heatmap.chingru.com/r/date-heatmap.jsonSource
1import type { Locale } from "date-fns";2import { format } from "date-fns";3import type { CSSProperties, HTMLAttributes, ReactNode } from "react";4import { createContext, Fragment, use, useMemo } from "react";5import { cn } from "@/lib/utils";67function formatDateWithWeekday(8 date: Date | string,9 dateFormat: string = "EEE, MMM dd, yyyy",10 locale?: Locale,11): string {12 const d = typeof date === "string" ? new Date(date) : date;13 return format(d, dateFormat, locale ? { locale } : undefined);14}1516export type DateHour =17 | 018 | 119 | 220 | 321 | 422 | 523 | 624 | 725 | 826 | 927 | 1028 | 1129 | 1230 | 1331 | 1432 | 1533 | 1634 | 1735 | 1836 | 1937 | 2038 | 2139 | 2240 | 23;4142export type DateHourlyActivity = {43 date: string; // YYYY-MM-DD44 hour: number; // 0–2345 value: number;46};4748type DateHourlyActivityWithLevel = DateHourlyActivity & {49 level: number;50};5152export type DateExtraRowSpec = {53 label: ReactNode;54 compute: (data: DateHourlyActivity[]) => number[]; // length 2455};5657export type DateExtraColumnSpec = {58 label: ReactNode;59 compute: (data: DateHourlyActivity[], dates: string[]) => number[]; // length = dates.length60};6162type ResolvedDateExtraRow = {63 label: ReactNode;64 values: { hour: number; value: number; level: number }[];65};6667type ResolvedDateExtraColumn = {68 label: ReactNode;69 values: { date: string; value: number; level: number }[];70};7172type DateHeatmapContextType = {73 data: DateHourlyActivityWithLevel[];74 dates: string[]; // Sorted list of unique dates75 extraRow: ResolvedDateExtraRow | null;76 extraColumn: ResolvedDateExtraColumn | null;77 blockMargin: number;78 blockRadius: number;79 blockSize: number;80 blockAspectRatio: number;81 blockWidth: number;82 fontSize: number;83 labels: DateHeatmapLabels;84 labelWidth: number;85 labelHeight: number;86 levels: number;87 isNormalized: boolean;88 totalCount: number;89 width: number;90 height: number;91 dateFormat: string;92 locale?: Locale;93 colors?: ColorConfig;94};9596export type DateHeatmapLabels = {97 hours?: string[];98 endHour?: string | null; // null = hide the end hour label99 stat?: string; // Stat text template. Placeholder: {{value}}100 cellLabel?: string; // aria-label template. Placeholders: {{date}}, {{hour}}, {{value}}101 heatmapLabel?: string; // aria-label for the heatmap SVG102 legendLabel?: string; // aria-label for the legend fieldset103 legendLevelLabel?: string; // aria-label template for legend swatches. Placeholder: {{level}}104};105106export type ColorConfig = {107// … truncated
What it pulls in
npm packages
Files it writes
More from @heatmap
All 4 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| CalendarHeatmapcalendar-heatmap | @heatmap | Components | Free | 3 deps | |
| StatusHeatmapstatus-heatmap | @heatmap | Components | Free | 3 deps | |
| WeekdayHeatmapweekday-heatmap | @heatmap | Components | Free | 2 deps |
