fix: company charts X-axis now adjusts to selected window time range
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/build-1 Pipeline was successful
ci/woodpecker/push/build-3 Pipeline was successful
ci/woodpecker/push/finalize Pipeline was successful
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled

The trend history chart was showing all historical data regardless of
which window was selected — only filtering by window name but not by
time range. Now filters both trend data and price data to the time
range matching the selected window (e.g., 7d shows last 7 days only,
30d shows last 30 days).
This commit is contained in:
Celes Renata
2026-04-29 16:59:23 +00:00
parent 24c753f6e6
commit 531e33b0ce
+19 -5
View File
@@ -590,9 +590,9 @@ function TrendTooltip({ active, payload, label }: Record<string, unknown>) {
function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices }: { trends: TrendSummary[]; latestTrends: TrendSummary[]; ticker: string; marketPrices: MarketPrice[] }) {
const [selectedWindow, setSelectedWindow] = useState('7d');
// Use history data for charts
// Use history data for charts — filter to selected window and time range
const filtered = (trends ?? [])
.filter((t) => t.entity_id === ticker && t.window === selectedWindow)
.filter((t) => t.entity_id === ticker && t.window === selectedWindow && new Date(t.generated_at).getTime() >= cutoffTs)
.sort((a, b) => new Date(a.generated_at).getTime() - new Date(b.generated_at).getTime());
// Build a price lookup — match by closest timestamp to each trend point
@@ -600,11 +600,25 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices }: { tre
.filter((p) => p.bar_timestamp != null && p.close != null)
.sort((a, b) => a.bar_timestamp - b.bar_timestamp);
// Determine the time range for the selected window to filter prices
const windowHours: Record<string, number> = {
intraday: 12,
'1d': 24,
'7d': 7 * 24,
'30d': 30 * 24,
'90d': 90 * 24,
};
const hoursBack = windowHours[selectedWindow] ?? 7 * 24;
const cutoffTs = Date.now() - hoursBack * 3600_000;
// Filter prices to the selected window's time range
const windowPrices = sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs);
function findClosestPrice(ts: number): number | undefined {
if (sortedPrices.length === 0) return undefined;
let best = sortedPrices[0];
if (windowPrices.length === 0) return undefined;
let best = windowPrices[0];
let bestDiff = Math.abs(ts - best.bar_timestamp);
for (const p of sortedPrices) {
for (const p of windowPrices) {
const diff = Math.abs(ts - p.bar_timestamp);
if (diff < bestDiff) {
best = p;