diff --git a/components/dashboard/Chart.tsx b/components/dashboard/Chart.tsx index 2725168..f065aed 100644 --- a/components/dashboard/Chart.tsx +++ b/components/dashboard/Chart.tsx @@ -11,7 +11,6 @@ import { Tooltip, ResponsiveContainer, ReferenceLine, - Label, } from 'recharts' import type { TooltipProps } from 'recharts' import { formatNumber, formatDuration } from '@/lib/utils/format' @@ -169,6 +168,15 @@ function formatAxisValue(value: number): string { return String(value) } +// * Compact duration for Y-axis ticks (avoids truncation: "5m" not "5m 0s") +function formatAxisDuration(seconds: number): string { + if (!seconds) return '0s' + const m = Math.floor(seconds / 60) + const s = Math.floor(seconds % 60) + if (m > 0) return s > 0 ? `${m}m ${s}s` : `${m}m` + return `${s}s` +} + // * Returns human-readable label for the previous comparison period (e.g. "Feb 10" or "Jan 5 – Feb 4") function getPrevDateRangeLabel(dateRange: { start: string; end: string }): string { const startDate = new Date(dateRange.start) @@ -368,7 +376,7 @@ export default function Chart({ const chartMetric = metric const metricLabel = metrics.find(m => m.id === metric)?.label || 'visitors' const prevPeriodLabel = prevData?.length ? getPrevDateRangeLabel(dateRange) : '' - const trendContext = prevStats ? getTrendContext(dateRange) : '' + const trendContext = getTrendContext(dateRange) const avg = chartData.length ? chartData.reduce((s, d) => s + (d[chartMetric] as number), 0) / chartData.length @@ -425,26 +433,30 @@ export default function Chart({ {item.value} - {item.trend !== null && ( - 0 - ? 'text-emerald-600 dark:text-emerald-500' - : (item.invertTrend ? -item.trend : item.trend) < 0 - ? 'text-red-600 dark:text-red-500' - : 'text-neutral-500' - }`}> - {(item.invertTrend ? -item.trend : item.trend) > 0 ? ( - - ) : (item.invertTrend ? -item.trend : item.trend) < 0 ? ( - - ) : null} - {Math.abs(item.trend)}% - - )} + + {item.trend !== null ? ( + <> + 0 + ? 'text-emerald-600 dark:text-emerald-500' + : (item.invertTrend ? -item.trend : item.trend) < 0 + ? 'text-red-600 dark:text-red-500' + : 'text-neutral-500' + }> + {(item.invertTrend ? -item.trend : item.trend) > 0 ? ( + + ) : (item.invertTrend ? -item.trend : item.trend) < 0 ? ( + + ) : null} + {Math.abs(item.trend)}% + + + ) : ( + + )} + - {trendContext && item.trend !== null && ( -

{trendContext}

- )} +

{trendContext}

{hasData && (
@@ -516,7 +528,7 @@ export default function Chart({ {showComparison && prevPeriodLabel && ( @@ -558,9 +570,26 @@ export default function Chart({

Try selecting another metric or date range

) : ( -
- - +
+ {/* * Vertical Y-axis label (text reads bottom-to-top) */} +
+ + {metricLabel} + +
+
+ + @@ -584,19 +613,13 @@ export default function Chart({ tickLine={false} axisLine={false} domain={[0, 'auto']} + width={48} tickFormatter={(val) => { if (metric === 'bounce_rate') return `${val}%` - if (metric === 'avg_duration') return formatDuration(val) + if (metric === 'avg_duration') return formatAxisDuration(val) return formatAxisValue(val) }} - > - - + + +
)}