From f13beb1a9b3eee5554846b60a8e69f1b4c18f609 Mon Sep 17 00:00:00 2001 From: Innocent-akim Date: Thu, 8 Aug 2024 21:46:58 +0200 Subject: [PATCH] feat: Add custom legend with IDs and synchronize with ResponsiveCalendar --- .../integrations/activity-calendar/index.tsx | 128 +++++++++++------- 1 file changed, 77 insertions(+), 51 deletions(-) diff --git a/apps/web/lib/features/integrations/activity-calendar/index.tsx b/apps/web/lib/features/integrations/activity-calendar/index.tsx index 96e5ef7f1..10f6e9289 100644 --- a/apps/web/lib/features/integrations/activity-calendar/index.tsx +++ b/apps/web/lib/features/integrations/activity-calendar/index.tsx @@ -5,6 +5,7 @@ import { useEffect, useState } from 'react'; import { CalendarDatum, ResponsiveCalendar } from '@nivo/calendar'; import Skeleton from 'react-loading-skeleton'; import moment from 'moment'; +import Separator from '@components/ui/separator'; export function ActivityCalendar() { const { timerLogsDailyReport, timerLogsDailyReportLoading } = useTimeLogs(); @@ -15,48 +16,69 @@ export function ActivityCalendar() { ); }, [timerLogsDailyReport]); + const colorRange = [ + '#9370DB', + '#6A5ACD', + '#4169E1', + '#0000FF', + '#1E90FF', + '#87CEEB', + '#FFA500', + '#FF8C00', + '#FF4500', + '#FF0000' + ]; + return ( -
+
{timerLogsDailyReportLoading ? ( ) : ( -
+
- d.toLocaleString('en-US', { month: 'short' })} - /> - - +
+ ( +
+ + {value.day} +
+ )} + yearLegend={(value) => value} + data={calendarData} + from={moment().startOf('year').toDate()} + to={moment().startOf('year').toDate()} + emptyColor="#ffffff" + colors={colorRange} + yearSpacing={40} + monthBorderWidth={0} + dayBorderWidth={0} + daySpacing={2} + monthLegendPosition="before" + margin={{ top: 0, right: 5, bottom: 0, left: 5 }} + legends={[ + { + anchor: 'bottom-right', + direction: 'row', + translateY: 36, + itemCount: 4, + itemWidth: 70, + itemHeight: 20, + itemsSpacing: 14, + itemDirection: 'left-to-right', + symbolSize: 20, + data: [ + { color: '#9370DB', label: '0 - 4 Hours', id: 'legend-purple' }, + { color: '#0000FF', label: '4 - 10 Hours', id: 'legend-blue' }, + { color: '#FFA500', label: '10 - 18 Hours', id: 'legend-orange' }, + { color: '#FF0000', label: '18 - 24 Hours', id: 'legend-red' } + ] + } + ]} + monthSpacing={20} + monthLegend={(_, __, d) => d.toLocaleString('en-US', { month: 'short' })} + /> +
)}
@@ -84,24 +106,28 @@ function ActivityCalendarSkeleton() { function ActivityLegend() { return ( -
+

Legend

-
- - 8 Hours or more + +
+ + 0 - 4 Hours
-
- - 6 Hours + +
+ + 4 - 10 Hours
-
- - 4 Hours + +
+ + 10 - 18 Hours
-
- - 2 Hours + +
+ + 18 - 24 Hours
- ) + ); }