From 780ecfdfb515c1911fc9ae10bca9d6cedef8485a Mon Sep 17 00:00:00 2001 From: DiTus Date: Sun, 1 Mar 2026 21:15:24 +0100 Subject: [PATCH] improved indicator redraw on new candles with error handling --- src/api/dashboard/static/js/ui/chart.js | 11 ++-- .../static/js/ui/indicators-panel-new.js | 52 ++++++++++--------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/api/dashboard/static/js/ui/chart.js b/src/api/dashboard/static/js/ui/chart.js index 26dc63c..79c7a1a 100644 --- a/src/api/dashboard/static/js/ui/chart.js +++ b/src/api/dashboard/static/js/ui/chart.js @@ -366,10 +366,7 @@ if (data.candles && data.candles.length > 0) { this.updateStats(latest); } - // Always try to redraw indicators after candles are set - if (window.drawIndicatorsOnChart) { - window.drawIndicatorsOnChart(); - } + window.drawIndicatorsOnChart?.(); } catch (error) { console.error('Error loading data:', error); } finally { @@ -431,10 +428,8 @@ async loadNewData() { this.updateStats(latest); - // Update indicators - for new candles, update series; for initial loads, redraw - if (window.drawIndicatorsOnChart) { - window.drawIndicatorsOnChart(); - } + console.log('[Chart] Calling drawIndicatorsOnChart after new data'); + window.drawIndicatorsOnChart?.(); await this.loadSignals(); diff --git a/src/api/dashboard/static/js/ui/indicators-panel-new.js b/src/api/dashboard/static/js/ui/indicators-panel-new.js index f2f087c..15f44fc 100644 --- a/src/api/dashboard/static/js/ui/indicators-panel-new.js +++ b/src/api/dashboard/static/js/ui/indicators-panel-new.js @@ -842,30 +842,31 @@ export function updateIndicatorCandles() { // Chart drawing export function drawIndicatorsOnChart() { - if (!window.dashboard || !window.dashboard.chart) { - return; - } - - const currentInterval = window.dashboard.currentInterval; - const candles = window.dashboard?.allData?.get(currentInterval); - - if (!candles || candles.length === 0) { - console.log('[Indicators] No candles available'); - return; - } - - console.log(`[Indicators] ========== drawIndicatorsOnChart START ==========`); - console.log(`[Indicators] Candles from allData: ${candles.length}`); - console.log(`[Indicators] First candle time: ${candles[0]?.time} (${new Date(candles[0]?.time * 1000).toLocaleDateString()})`); - console.log(`[Indicators] Last candle time: ${candles[candles.length - 1]?.time} (${new Date(candles[candles.length - 1]?.time * 1000).toLocaleDateString()})`); - - const oldestTime = candles[0]?.time; - const newestTime = candles[candles.length - 1]?.time; - const oldestDate = oldestTime ? new Date(oldestTime * 1000).toLocaleDateString() : 'N/A'; - const newestDate = newestTime ? new Date(newestTime * 1000).toLocaleDateString() : 'N/A'; - -console.log(`[Indicators] ========== Redrawing ==========`); - console.log(`[Indicators] Candles: ${candles.length} | Time range: ${oldestDate} (${oldestTime}) to ${newestDate} (${newestTime})`); + try { + if (!window.dashboard || !window.dashboard.chart) { + return; + } + + const currentInterval = window.dashboard.currentInterval; + const candles = window.dashboard?.allData?.get(currentInterval); + + if (!candles || candles.length === 0) { + console.log('[Indicators] No candles available'); + return; + } + + console.log(`[Indicators] ========== drawIndicatorsOnChart START ==========`); + console.log(`[Indicators] Candles from allData: ${candles.length}`); + console.log(`[Indicators] First candle time: ${candles[0]?.time} (${new Date(candles[0]?.time * 1000).toLocaleDateString()})`); + console.log(`[Indicators] Last candle time: ${candles[candles.length - 1]?.time} (${new Date(candles[candles.length - 1]?.time * 1000).toLocaleDateString()})`); + + const oldestTime = candles[0]?.time; + const newestTime = candles[candles.length - 1]?.time; + const oldestDate = oldestTime ? new Date(oldestTime * 1000).toLocaleDateString() : 'N/A'; + const newestDate = newestTime ? new Date(newestTime * 1000).toLocaleDateString() : 'N/A'; + + console.log(`[Indicators] ========== Redrawing ==========`); + console.log(`[Indicators] Candles: ${candles.length} | Time range: ${oldestDate} (${oldestTime}) to ${newestDate} (${newestTime})`); const activeIndicators = getActiveIndicators(); @@ -950,6 +951,9 @@ console.log(`[Indicators] ========== Redrawing ==========`); }); console.log(`[Indicators] ========== drawIndicatorsOnChart END ==========`); + } catch (error) { + console.error('[Indicators] Error drawing indicators:', error); + } } function resetIndicator(id) {