import React from "react"; import { Tooltip } from "@mui/material"; import { getWeekDateRange } from "../utils/weeklyCalendar"; type WeeklyActivity = { date: string; count: number; level: number; }; type WeeklyHeatmapProps = { data: WeeklyActivity[]; color: string; }; const WeeklyHeatmap: React.FC = ({ data, color }) => { // Group data by month and year const groupedData = data.reduce((acc, activity) => { const date = new Date(activity.date); const yearMonth = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`; if (!acc[yearMonth]) { acc[yearMonth] = []; } acc[yearMonth].push(activity); return acc; }, {} as Record); // Get color intensity based on level const getColorIntensity = (level: number) => { if (level === 0) return '#161b22'; // Dark background for no activity const intensities = ['#0e4429', '#006d32', '#26a641', '#39d353']; return intensities[Math.min(level - 1, 3)] || color; }; // Get month names const getMonthName = (yearMonth: string) => { const [year, month] = yearMonth.split('-'); const date = new Date(parseInt(year), parseInt(month) - 1); return date.toLocaleDateString('en-US', { month: 'short', year: 'numeric' }); }; const sortedMonths = Object.keys(groupedData).sort(); return (
{sortedMonths.map((yearMonth) => { const monthData = groupedData[yearMonth]; return (
{getMonthName(yearMonth)}
{monthData.map((activity, index) => (
))}
); })}
{/* Legend */}
Less
{[0, 1, 2, 3, 4].map((level) => (
))}
More
); }; export default WeeklyHeatmap;