From 32ea28b2f6a08c2150d0cd700fe97038b064865e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Thu, 22 Jan 2026 20:54:08 +0100 Subject: [PATCH] feat: improve activity chart on profile --- .../components/profiles/profile-activity.tsx | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/apps/start/src/components/profiles/profile-activity.tsx b/apps/start/src/components/profiles/profile-activity.tsx index a4e4a21a..f8509e1f 100644 --- a/apps/start/src/components/profiles/profile-activity.tsx +++ b/apps/start/src/components/profiles/profile-activity.tsx @@ -7,6 +7,7 @@ import { format, formatISO, isSameMonth, + isToday, startOfMonth, subMonths, } from 'date-fns'; @@ -18,15 +19,26 @@ import { WidgetTitle, } from '../overview/overview-widget'; import { Button } from '../ui/button'; +import { Tooltiper } from '../ui/tooltip'; type Props = { data: { count: number; date: string }[]; }; +function getOpacityLevel(count: number, maxCount: number): number { + if (count === 0 || maxCount === 0) return 0; + const ratio = count / maxCount; + if (ratio <= 0.25) return 0.25; + if (ratio <= 0.5) return 0.5; + if (ratio <= 0.75) return 0.75; + return 1; +} + const MonthCalendar = ({ month, data, -}: { month: Date; data: Props['data'] }) => ( + maxCount, +}: { month: Date; data: Props['data']; maxCount: number }) => (
{format(month, 'MMMM yyyy')}
@@ -37,14 +49,42 @@ const MonthCalendar = ({ const hit = data.find((item) => item.date.includes(formatISO(date, { representation: 'date' })), ); + const opacity = hit ? getOpacityLevel(hit.count, maxCount) : 0; return ( -
+ asChild + content={ +
+
{format(date, 'EEEE, MMM d')}
+ {hit ? ( +
+ {hit.count} {hit.count === 1 ? 'event' : 'events'} +
+ ) : ( +
No activity
+ )} +
+ } + > +
+
+
+ ); })}
@@ -53,6 +93,7 @@ const MonthCalendar = ({ export const ProfileActivity = ({ data }: Props) => { const [startDate, setStartDate] = useState(startOfMonth(new Date())); + const maxCount = Math.max(...data.map((item) => item.count), 0); return ( @@ -83,6 +124,7 @@ export const ProfileActivity = ({ data }: Props) => { key={offset} month={subMonths(startDate, offset)} data={data} + maxCount={maxCount} /> ))}