From d6d844a0035e6eb2426454c563d9b2042cc709db Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Wed, 18 Feb 2026 15:23:11 +0100 Subject: [PATCH] fix: detect candle interval dynamically instead of hardcoded 60s Replace the hardcoded 60-second assumption in CandleChart.tsx with dynamic interval detection: compute interval as candles[1].time - candles[0].time when at least 2 candles are available, fall back to 60 otherwise. Used for span-to-prediction-time mapping iteration. Marks task 8.6 as done in tasks.md. Co-Authored-By: Claude Sonnet 4.6 --- openspec/changes/code-review-fix/tasks.md | 2 +- src/components/CandleChart.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openspec/changes/code-review-fix/tasks.md b/openspec/changes/code-review-fix/tasks.md index a3a149c..69766f4 100644 --- a/openspec/changes/code-review-fix/tasks.md +++ b/openspec/changes/code-review-fix/tasks.md @@ -75,7 +75,7 @@ - [x] 8.3 `[sonnet]` Remove `fitContent()` from reconciliation effect, only call on initial load (`src/components/SpanAnnotationManager.tsx:160`) - [x] 8.4 `[opus]` Implement incremental primitive updates in SpanAnnotationManager: update only selection state on selection change, full reconciliation only on annotation list changes (`src/components/SpanAnnotationManager.tsx:104-161`) - [x] 8.5 `[sonnet]` Add bounded prediction cache (max 100 entries, FIFO eviction) to `predictionCacheRef` (`src/app/page.tsx:195-199`) -- [ ] 8.6 `[sonnet]` Fix hardcoded 1-minute candle interval: detect interval from data, use for span iteration (`src/components/CandleChart.tsx:452`) +- [x] 8.6 `[sonnet]` Fix hardcoded 1-minute candle interval: detect interval from data, use for span iteration (`src/components/CandleChart.tsx:452`) - [ ] 8.7 `[haiku]` Extract magic numbers (8px, 60s, colors) to named constants in `CandleChart.tsx` - [ ] 8.8 `[haiku]` Move `new Set()` default prop to module-level constant in `CandleChart.tsx:125` diff --git a/src/components/CandleChart.tsx b/src/components/CandleChart.tsx index 7128fe6..791f3d9 100644 --- a/src/components/CandleChart.tsx +++ b/src/components/CandleChart.tsx @@ -472,11 +472,14 @@ const CandleChart = forwardRef( // Build candle price lookup for histogram values const candleMap = new Map(candles.map((c) => [c.time, c])); + // Detect candle interval from data (fall back to 60s if fewer than 2 candles) + const candleInterval = candles.length >= 2 ? candles[1].time - candles[0].time : 60; + // Build a map from prediction time to its span for disagreement lookup const predictionTimeToSpan = new Map(); predictionSpans.forEach((span) => { // Associate all times in the span with the span object - for (let t = span.start_time; t <= span.end_time; t += 60) { // Assuming 1-minute candles, adjust if needed + for (let t = span.start_time; t <= span.end_time; t += candleInterval) { predictionTimeToSpan.set(t, span); } });