diff --git a/frontend/src/pages/CompanyDetail.tsx b/frontend/src/pages/CompanyDetail.tsx index c6b4604..375883a 100644 --- a/frontend/src/pages/CompanyDetail.tsx +++ b/frontend/src/pages/CompanyDetail.tsx @@ -703,8 +703,8 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte .filter((p) => p.bar_timestamp != null && p.close != null) .sort((a, b) => a.bar_timestamp - b.bar_timestamp); - // Filter prices to the selected window's time range - const windowPrices = sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs); + // Filter prices to the selected window's time range (use all prices if sparse) + const windowPrices = sortedPrices.length <= 20 ? sortedPrices : sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs); function findClosestPrice(ts: number): number | undefined { if (windowPrices.length === 0) return undefined; @@ -717,8 +717,16 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte bestDiff = diff; } } - // Only match if within 2 hours (for intraday) or 36 hours (for daily) - const maxGap = selectedWindow === 'intraday' ? 2 * 3600_000 : 36 * 3600_000; + // Match if within reasonable gap for the window type + // With sparse price data (~1 bar per 4-6 hours), use wider tolerances + const maxGapHours: Record = { + intraday: 6, + '1d': 12, + '7d': 36, + '30d': 72, + '90d': 168, + }; + const maxGap = (maxGapHours[selectedWindow] ?? 36) * 3600_000; return bestDiff <= maxGap ? best.close : undefined; }