From b73471070edb511c6e4e8738688d6b6c89bb590e Mon Sep 17 00:00:00 2001 From: castrojo Date: Tue, 8 Sep 2026 14:30:46 +0000 Subject: [PATCH] fix(analytics): calculate and format hero deltas for the selected range Baseline the hero delta calculation on the first week of the selected hero range (heroFilteredWeeks[0]) instead of the all-time first week, so switching between 12-week/24-week/all-history ranges updates the delta baseline accordingly. Also format the sign conditionally so a negative delta renders as e.g. -4.2% instead of +-4.2%. Fixes projectbluefin/documentation#1087 Signed-off-by: castrojo --- .../analytics/CountmeAnalyticsCharts.tsx | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/components/analytics/CountmeAnalyticsCharts.tsx b/src/components/analytics/CountmeAnalyticsCharts.tsx index d7e489aa..f292be77 100644 --- a/src/components/analytics/CountmeAnalyticsCharts.tsx +++ b/src/components/analytics/CountmeAnalyticsCharts.tsx @@ -134,21 +134,24 @@ export default function CountmeAnalyticsCharts(): React.JSX.Element { return weeks; }, [weeks, heroRange]); - // Delta calculation for Bluefin fleet - const firstWeek = weeks[0] || ({} as CountmeWeek); + // Delta calculation for Bluefin fleet, baselined to the first week of the + // currently selected hero range (not the entire history). + const firstHeroWeek = heroFilteredWeeks[0] || ({} as CountmeWeek); const initialTotalBluefin = - (Number(firstWeek.bluefin) || 0) + - (Number(firstWeek["bluefin-lts"]) || 0) + - (Number(firstWeek.dakota) || 0) + - (Number(firstWeek.utah) || 0) || currentTotalBluefin; + (Number(firstHeroWeek.bluefin) || 0) + + (Number(firstHeroWeek["bluefin-lts"]) || 0) + + (Number(firstHeroWeek.dakota) || 0) + + (Number(firstHeroWeek.utah) || 0) || currentTotalBluefin; - const bluefinDeltaPct = + const bluefinDeltaPctValue = initialTotalBluefin > 0 - ? ( - ((currentTotalBluefin - initialTotalBluefin) / initialTotalBluefin) * - 100 - ).toFixed(1) - : "0.0"; + ? ((currentTotalBluefin - initialTotalBluefin) / initialTotalBluefin) * + 100 + : 0; + + const bluefinDeltaPct = bluefinDeltaPctValue.toFixed(1); + const bluefinDeltaPctSigned = + bluefinDeltaPctValue >= 0 ? `+${bluefinDeltaPct}` : bluefinDeltaPct; // Filtered weeks for comparative time-series charts const filteredWeeks = useMemo(() => { @@ -440,7 +443,7 @@ export default function CountmeAnalyticsCharts(): React.JSX.Element {
- +{bluefinDeltaPct}% overall + {bluefinDeltaPctSigned}% overall latest week ({latestWeek.week})
@@ -486,7 +489,7 @@ export default function CountmeAnalyticsCharts(): React.JSX.Element { = 0 ? "up" : "down"} ${Math.abs(bluefinDeltaPctValue).toFixed(1)}% across ${heroFilteredWeeks.length} tracked weeks.`} points={realHeroPoints} minPoints={2} height={320}