Heatmap Chart
boldkit/heatmap-chartFreeComponent
Heatmap grid for correlation and intensity data - custom CSS Grid implementation
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/heatmap-chart.jsonSource
1import * as React from 'react'2import { cn } from '@/lib/utils'3import { ChartEmpty } from './chart'45export interface HeatmapCellData {6 row: string7 col: string8 value: number9}1011export interface HeatmapChartProps extends React.HTMLAttributes<HTMLDivElement> {12 data: HeatmapCellData[]13 rows: string[]14 cols: string[]15 /** CSS color at 0 intensity (default: transparent primary) */16 colorLow?: string17 /** CSS color at max intensity (default: primary) */18 colorHigh?: string19 showLabels?: boolean20 showTooltip?: boolean21 cellSize?: number22 /** Accessible label for screen readers (default: "Heatmap chart") */23 ariaLabel?: string24 /** Fires when a cell is clicked or activated via keyboard (Enter/Space). */25 onCellClick?: (cell: HeatmapCellData) => void26 emptyState?: React.ReactNode27}2829function interpolateOpacity(value: number, min: number, max: number): number {30 if (max === min) return 0.531 return (value - min) / (max - min)32}3334/**35 * Compute cell background color from colorLow → colorHigh using CSS color-mix(),36 * which works with any valid CSS color string including hsl(var(--*)) tokens.37 * Falls back to primary-opacity when custom colors are not provided.38 */39function getCellColor(40 intensity: number,41 colorLow: string | undefined,42 colorHigh: string | undefined43): string {44 if (colorLow && colorHigh) {45 // color-mix interpolates in srgb space: at t=0 we want colorLow, at t=1 we want colorHigh.46 // color-mix(in srgb, colorHigh <t*100>%, colorLow) gives us colorHigh at t=1 and colorLow at t=0.47 const pct = Math.round(Math.max(0, Math.min(1, intensity)) * 100)48 return `color-mix(in srgb, ${colorHigh} ${pct}%, ${colorLow})`49 }50 // Default: vary opacity of primary from 0.08 (low) to 1 (high)51 return `hsl(var(--primary) / ${Math.max(0.08, intensity)})`52}5354const HeatmapChart = React.forwardRef<HTMLDivElement, HeatmapChartProps>(55 (56 {57 data,58 rows,59 cols,60 colorLow,61 colorHigh,62 showLabels = true,63 showTooltip = true,64 cellSize = 40,65 ariaLabel = 'Heatmap chart',66 onCellClick,67 emptyState,68 className,69 ...props70 },71 ref72 ) => {73 const [tooltip, setTooltip] = React.useState<{ x: number; y: number; row: string; col: string; value: number } | null>(null)74 const isInteractive = !!onCellClick75 const cellTabIndex = showTooltip || isInteractive ? 0 : undefined7677 const valueMap = React.useMemo(() => {78 const map = new Map<string, number>()79// … truncated
What it pulls in
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
