WeekdayHeatmap
heatmap/weekday-heatmapFreeComponent
Weekday × hour-of-day matrix with Sum row/column and independent colour scales.
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/weekday-heatmap.jsonSource
1import type { Locale, Day as WeekDay } 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";67export type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;89export type WeekdayHour =10 | 011 | 112 | 213 | 314 | 415 | 516 | 617 | 718 | 819 | 920 | 1021 | 1122 | 1223 | 1324 | 1425 | 1526 | 1627 | 1728 | 1829 | 1930 | 2031 | 2132 | 2233 | 23;3435export type WeekdayHourlyActivity = {36 weekday: number; // 0–6 (Sun–Sat)37 hour: number; // 0–2338 value: number;39};4041type WeekdayHourlyActivityWithLevel = WeekdayHourlyActivity & {42 level: number;43};4445export type WeekdayExtraRowSpec = {46 label: ReactNode;47 compute: (data: WeekdayHourlyActivity[]) => number[]; // length 2448};4950export type WeekdayExtraColumnSpec = {51 label: ReactNode;52 compute: (data: WeekdayHourlyActivity[]) => number[]; // length 7, indexed by weekday 0–653};5455type ResolvedExtraRow = {56 label: ReactNode;57 values: { hour: number; value: number; level: number }[];58};5960type ResolvedExtraColumn = {61 label: ReactNode;62 values: { weekday: number; value: number; level: number }[];63};6465type WeekdayHeatmapContextType = {66 data: WeekdayHourlyActivityWithLevel[];67 extraRow: ResolvedExtraRow | null;68 extraColumn: ResolvedExtraColumn | null;69 blockMargin: number;70 blockRadius: number;71 blockSize: number;72 blockAspectRatio: number;73 blockWidth: number;74 fontSize: number;75 labels: WeekdayHeatmapLabels;76 labelWidth: number;77 labelHeight: number;78 levels: number;79 isNormalized: boolean;80 totalCount: number;81 width: number;82 height: number;83 weekStart: WeekDay;84 colors?: ColorConfig;85};8687export type WeekdayHeatmapLabels = {88 hours?: string[];89 endHour?: string | null;90 weekdays?: string[];91 stat?: string; // Stat text template. Placeholder: {{value}}92 cellLabel?: string; // aria-label template. Placeholders: {{weekday}}, {{hour}}, {{value}}93 heatmapLabel?: string; // aria-label for the heatmap SVG94 legendLabel?: string; // aria-label for the legend fieldset95 legendLevelLabel?: string; // aria-label template for legend swatches. Placeholder: {{level}}96};9798export type ColorConfig = {99 empty?: string;100 scale?: string;101};102103// Non-normalized: 1 empty + (levels-1) colored steps. Normalized: levels colored steps, no empty.104const colorStepCount = (levels: number, isNormalized: boolean) =>105// … 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 | |
| DateHeatmapdate-heatmap | @heatmap | Components | Free | 3 deps | |
| StatusHeatmapstatus-heatmap | @heatmap | Components | Free | 3 deps |
