From b8d589bca1f93836fcefbdfceffd878e9df75637 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Sat, 31 Jan 2026 17:42:59 +0100 Subject: [PATCH] Enhance tooltips with YoY comparison and English labels --- components/WeeklyGrid.tsx | 72 +++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/components/WeeklyGrid.tsx b/components/WeeklyGrid.tsx index 209c546..6d9c4a7 100644 --- a/components/WeeklyGrid.tsx +++ b/components/WeeklyGrid.tsx @@ -50,21 +50,23 @@ const useDebounce = (value: string, delay: number) => { return debouncedValue; }; -// Tooltip component to show comparison details on hover +// Tooltip component to show comparison details on hover (WoW and YoY) const MetricDetailTooltip: React.FC<{ children: React.ReactNode; currentValue: number; previousValue: number; + yoyValue?: number; currentWeekLabel: string; previousWeekLabel: string; + yoyWeekLabel?: string; metricName: string; metricColor: string; formatValue?: (val: number) => string; -}> = ({ children, currentValue, previousValue, currentWeekLabel, previousWeekLabel, metricName, metricColor, formatValue }) => { +}> = ({ children, currentValue, previousValue, yoyValue, currentWeekLabel, previousWeekLabel, yoyWeekLabel, metricName, metricColor, formatValue }) => { const [isVisible, setIsVisible] = useState(false); - const growth = previousValue > 0 ? ((currentValue - previousValue) / previousValue) * 100 : (currentValue > 0 ? 100 : 0); - const isPositive = growth >= 0; + const wowGrowth = previousValue > 0 ? ((currentValue - previousValue) / previousValue) * 100 : (currentValue > 0 ? 100 : 0); + const yoyGrowth = yoyValue !== undefined && yoyValue > 0 ? ((currentValue - yoyValue) / yoyValue) * 100 : null; const format = formatValue || ((v: number) => v.toLocaleString('de-DE')); return ( @@ -75,12 +77,12 @@ const MetricDetailTooltip: React.FC<{ >
{children}
{isVisible && ( -
+
📊 {metricName} Comparison
-
+
{/* Current Week */}
{currentWeekLabel} @@ -93,18 +95,33 @@ const MetricDetailTooltip: React.FC<{ {format(previousValue)}
- {/* Divider */} -
+ {/* Same Week Last Year */} + {yoyValue !== undefined && yoyWeekLabel && (
- vs Semana Anterior - - {isPositive ? 'â–²' : 'â–¼'} {Math.abs(growth).toFixed(1)}% + {yoyWeekLabel} + {format(yoyValue)} +
+ )} + + {/* WoW Growth */} +
+
+ vs Previous Week + = 0 ? 'text-emerald-400' : 'text-red-400'}`}> + {wowGrowth >= 0 ? 'â–²' : 'â–¼'} {Math.abs(wowGrowth).toFixed(1)}%
-
- Comparado con la semana inmediatamente anterior -
+ + {/* YoY Growth */} + {yoyGrowth !== null && ( +
+ vs Same Week Last Year + = 0 ? 'text-emerald-400' : 'text-red-400'}`}> + {yoyGrowth >= 0 ? 'â–²' : 'â–¼'} {Math.abs(yoyGrowth).toFixed(1)}% + +
+ )}
{/* Arrow */} @@ -184,9 +201,16 @@ const WeeklyRow: React.FC<{ const gv = row.gvByWeek?.[week] || 0; const prevGv = row.gvByWeek?.[weeks[idx + 1]] || 0; - const weekNum = week.split('-')[1]; + // Parse week as YYYY-WW + const [year, weekNum] = week.split('-'); const prevWeekNum = weeks[idx + 1]?.split('-')[1] || '-'; + // Calculate same week last year key (e.g., 2026-05 -> 2025-05) + const lastYearWeek = `${parseInt(year) - 1}-${weekNum}`; + const yoyUnits = row.unitsByWeek[lastYearWeek] || 0; + const yoySpend = row.spendByWeek[lastYearWeek] || 0; + const yoyGv = row.gvByWeek?.[lastYearWeek] || 0; + return (
@@ -194,8 +218,10 @@ const WeeklyRow: React.FC<{ 0 ? yoyUnits : undefined} + currentWeekLabel={`Week ${weekNum} (${year})`} + previousWeekLabel={`Week ${prevWeekNum} (${year})`} + yoyWeekLabel={yoyUnits > 0 ? `Week ${weekNum} (${parseInt(year) - 1})` : undefined} metricName="Units" metricColor="text-white" > @@ -213,8 +239,10 @@ const WeeklyRow: React.FC<{ 0 ? yoySpend : undefined} + currentWeekLabel={`Week ${weekNum} (${year})`} + previousWeekLabel={`Week ${prevWeekNum} (${year})`} + yoyWeekLabel={yoySpend > 0 ? `Week ${weekNum} (${parseInt(year) - 1})` : undefined} metricName="Spend" metricColor="text-indigo-400" formatValue={(v) => `€${v.toLocaleString('de-DE', { minimumFractionDigits: 0, maximumFractionDigits: 0 })}`} @@ -233,8 +261,10 @@ const WeeklyRow: React.FC<{ 0 ? yoyGv : undefined} + currentWeekLabel={`Week ${weekNum} (${year})`} + previousWeekLabel={`Week ${prevWeekNum} (${year})`} + yoyWeekLabel={yoyGv > 0 ? `Week ${weekNum} (${parseInt(year) - 1})` : undefined} metricName="GV (Glance View)" metricColor="text-teal-400" >