diff --git a/ANNOTATE/web/static/js/chart_manager.js b/ANNOTATE/web/static/js/chart_manager.js index 44da8f6..485d9e9 100644 --- a/ANNOTATE/web/static/js/chart_manager.js +++ b/ANNOTATE/web/static/js/chart_manager.js @@ -3090,13 +3090,35 @@ class ChartManager { targetPrice = currentPrice + priceChange; - // Sanity check: Don't let target price go to 0 or negative + // CRITICAL VALIDATION: Filter out invalid trend lines that would break chart zoom + // Don't draw if: + // 1. Target price is <= 0 or not finite + // 2. Target price is more than 10% away from current price (likely bad prediction) + // 3. Price change is too extreme (> 50% of current price) + const priceChangePercent = Math.abs((targetPrice - currentPrice) / currentPrice); + if (targetPrice <= 0 || !isFinite(targetPrice)) { - console.warn('Invalid target price calculated:', targetPrice, 'using current price instead'); - targetPrice = currentPrice; + console.warn('Skipping trend line: Invalid target price:', targetPrice); + return; // Don't draw this trend line } - // Draw trend ray + if (priceChangePercent > 0.10) { + console.warn('Skipping trend line: Price change too large:', + `${(priceChangePercent * 100).toFixed(1)}% (${currentPrice.toFixed(2)} -> ${targetPrice.toFixed(2)})`); + return; // Don't draw this trend line + } + + // Additional check: Ensure target price is within reasonable bounds + const minReasonablePrice = currentPrice * 0.5; // 50% below + const maxReasonablePrice = currentPrice * 1.5; // 50% above + + if (targetPrice < minReasonablePrice || targetPrice > maxReasonablePrice) { + console.warn('Skipping trend line: Target price out of reasonable bounds:', + `${targetPrice.toFixed(2)} (current: ${currentPrice.toFixed(2)})`); + return; // Don't draw this trend line + } + + // All validations passed - draw the trend ray shapes.push({ type: 'line', x0: lastTimestamp,