Fix export error by declaring removeIndicatorById as standalone function

Changed window.removeIndicatorById assignment to standalone function declaration
before assigning to window, allowing it to be properly exported. Added extra debug
logging to track which indicator type is being added to help diagnose duplicate additions.
This commit is contained in:
DiTus
2026-02-25 23:06:08 +01:00
parent 3602a572a5
commit ee7bfc9571

View File

@ -370,7 +370,7 @@ function setupEventListeners() {
e.stopPropagation(); e.stopPropagation();
const type = addBtn.dataset.type; const type = addBtn.dataset.type;
if (type && window.addIndicator) { if (type && window.addIndicator) {
console.log('[IndicatorPanel] Adding indicator:', type); console.log('[IndicatorPanel] Add button clicked for type:', type);
window.addIndicator(type); window.addIndicator(type);
} }
return; return;
@ -463,126 +463,9 @@ window.clearAllIndicators = function() {
configuringId = null; configuringId = null;
renderIndicatorPanel(); renderIndicatorPanel();
drawIndicatorsOnChart(); 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();
drawIndicatorsOnChart();
} }
window.toggleIndicatorExpand = function(id) { function removeIndicatorById(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) {
const idx = activeIndicators.findIndex(a => a.id === id); const idx = activeIndicators.findIndex(a => a.id === id);
if (idx < 0) return; if (idx < 0) return;
@ -598,11 +481,6 @@ window.removeIndicatorById = function(id) {
renderIndicatorPanel(); renderIndicatorPanel();
drawIndicatorsOnChart(); drawIndicatorsOnChart();
};
function removeIndicatorByIndex(index) {
if (index < 0 || index >= activeIndicators.length) return;
removeIndicatorById(activeIndicators[index].id);
} }
// Presets // Presets
@ -872,14 +750,12 @@ window.applyIndicatorConfig = function() {
// No-op - config is applied immediately // No-op - config is applied immediately
}; };
// Assign to window for backward compatibility // Assign functions to window for backward compatibility
window.addIndicator = addIndicator; window.addIndicator = window.addIndicator || addIndicator;
window.toggleIndicator = addIndicator; window.removeIndicator = function() {
window.removeIndicatorById = removeIndicatorById; if (!configuringId) return;
window.removeIndicatorByIndex = removeIndicatorByIndexWindow; removeIndicatorById(configuringId);
const removeIndicatorByIndexWindow = function(index) {
if (index < 0 || index >= activeIndicators.length) return;
removeIndicatorById(activeIndicators[index].id);
}; };
window.removeIndicatorByIndex = removeIndicatorByIndexWindow; window.removeIndicatorById = removeIndicatorById;
window.removeIndicatorByIndex = removeIndicatorByIndex;
window.drawIndicatorsOnChart = drawIndicatorsOnChart; window.drawIndicatorsOnChart = drawIndicatorsOnChart;