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 {