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 95aab20..d083b21 100644 --- a/src/api/dashboard/static/js/ui/indicators-panel-new.js +++ b/src/api/dashboard/static/js/ui/indicators-panel-new.js @@ -370,7 +370,7 @@ function setupEventListeners() { e.stopPropagation(); const type = addBtn.dataset.type; if (type && window.addIndicator) { - console.log('[IndicatorPanel] Adding indicator:', type); + console.log('[IndicatorPanel] Add button clicked for type:', type); window.addIndicator(type); } return; @@ -461,128 +461,11 @@ window.clearAllIndicators = function() { }); activeIndicators = []; configuringId = null; - renderIndicatorPanel(); - drawIndicatorsOnChart(); -}; - -function addIndicator(type) { - const IndicatorClass = IR?.[type]; - if (!IndicatorClass) return; - - const id = `${type}_${nextInstanceId++}`; - const instance = new IndicatorClass({ type, params: {}, name: '' }); - const metadata = instance.getMetadata(); - - const params = { - _lineType: 'solid', - _lineWidth: 2 - }; - metadata.plots.forEach((plot, idx) => { - params[`_color_${idx}`] = plot.color || getDefaultColor(activeIndicators.length + idx); - }); - metadata.inputs.forEach(input => { - params[input.name] = input.default; - }); - - activeIndicators.push({ - id, - type, - name: metadata.name, - params, - plots: metadata.plots, - series: [], - visible: true - }); - - configuringId = id; - renderIndicatorPanel(); +renderIndicatorPanel(); drawIndicatorsOnChart(); } -window.toggleIndicatorExpand = function(id) { - configuringId = configuringId === id ? null : id; - renderIndicatorPanel(); -}; - -window.toggleIndicatorVisibility = function(id) { - const indicator = activeIndicators.find(a => a.id === id); - if (!indicator) return; - - indicator.visible = indicator.visible === false ? true : false; - - indicator.series?.forEach(s => { - try { - s.applyOptions({ visible: indicator.visible }); - } catch(e) {} - }); - - renderIndicatorPanel(); -}; - -window.toggleFavorite = function(type) { - if (!userPresets) userPresets = {}; - if (!userPresets.favorites) userPresets.favorites = []; - - const favorites = userPresets.favorites; - const idx = favorites.indexOf(type); - - if (idx >= 0) { - favorites.splice(idx, 1); - } else { - favorites.push(type); - } - - userPresets.favorites = favorites; - saveUserPresets(); - renderIndicatorPanel(); -}; - -window.updateIndicatorColor = function(id, index, color) { - const indicator = activeIndicators.find(a => a.id === id); - if (!indicator) return; - - indicator.params[`_color_${index}`] = color; - - const preview = document.querySelector(`#color_${id}_${index} + .color-preview`); - if (preview) { - preview.style.background = color; - } - - drawIndicatorsOnChart(); -}; - -window.updateIndicatorSetting = function(id, key, value) { - const indicator = activeIndicators.find(a => a.id === id); - if (!indicator) return; - - indicator.params[key] = value; - drawIndicatorsOnChart(); -}; - -window.resetIndicator = function(id) { - const indicator = activeIndicators.find(a => a.id === id); - if (!indicator) return; - - const IndicatorClass = IR?.[indicator.type]; - if (!IndicatorClass) return; - - const instance = new IndicatorClass({ type: indicator.type, params: {}, name: indicator.name }); - const meta = instance.getMetadata(); - - meta.inputs.forEach(input => { - indicator.params[input.name] = input.default; - }); - - renderIndicatorPanel(); - drawIndicatorsOnChart(); -}; - -window.removeIndicator = function() { - if (!configuringId) return; - removeIndicatorById(configuringId); -}; - -window.removeIndicatorById = function(id) { +function removeIndicatorById(id) { const idx = activeIndicators.findIndex(a => a.id === id); if (idx < 0) return; @@ -598,11 +481,6 @@ window.removeIndicatorById = function(id) { renderIndicatorPanel(); drawIndicatorsOnChart(); -}; - -function removeIndicatorByIndex(index) { - if (index < 0 || index >= activeIndicators.length) return; - removeIndicatorById(activeIndicators[index].id); } // Presets @@ -872,14 +750,12 @@ window.applyIndicatorConfig = function() { // No-op - config is applied immediately }; -// Assign to window for backward compatibility -window.addIndicator = addIndicator; -window.toggleIndicator = addIndicator; -window.removeIndicatorById = removeIndicatorById; -window.removeIndicatorByIndex = removeIndicatorByIndexWindow; -const removeIndicatorByIndexWindow = function(index) { - if (index < 0 || index >= activeIndicators.length) return; - removeIndicatorById(activeIndicators[index].id); +// Assign functions to window for backward compatibility +window.addIndicator = window.addIndicator || addIndicator; +window.removeIndicator = function() { + if (!configuringId) return; + removeIndicatorById(configuringId); }; -window.removeIndicatorByIndex = removeIndicatorByIndexWindow; +window.removeIndicatorById = removeIndicatorById; +window.removeIndicatorByIndex = removeIndicatorByIndex; window.drawIndicatorsOnChart = drawIndicatorsOnChart; \ No newline at end of file