Add proper ES6 exports for indicator panel modules
- Export addIndicator for module imports - Export removeIndicatorById for module imports - Export removeIndicatorByIndex for module imports - Fix circular reference issues with window assignments - Simplify export statements to work with ES6 modules This fixes the 'does not provide export named addIndicator' error.
This commit is contained in:
@ -701,128 +701,25 @@ window.showIndicatorConfig = function(id) {
|
|||||||
window.applyIndicatorConfig = function() {
|
window.applyIndicatorConfig = function() {
|
||||||
// No-op - config is applied immediately
|
// No-op - config is applied immediately
|
||||||
};
|
};
|
||||||
window.showIndicatorConfigByIndex = function(index) {
|
|
||||||
if (index >= 0 && index < activeIndicators.length) {
|
|
||||||
configuringId = activeIndicators[index].id;
|
|
||||||
renderIndicatorPanel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function renderIndicatorOnPane(indicator, meta, instance, candles, paneIndex, lineStyleMap) {
|
|
||||||
const results = instance.calculate(candles);
|
|
||||||
indicator.series = [];
|
|
||||||
|
|
||||||
const lineStyle = lineStyleMap[indicator.params._lineType] || LightweightCharts.LineStyle.Solid;
|
|
||||||
const lineWidth = indicator.params._lineWidth || 2;
|
|
||||||
|
|
||||||
const firstNonNull = results?.find(r => r !== null && r !== undefined);
|
|
||||||
const isObjectResult = firstNonNull && typeof firstNonNull === 'object';
|
|
||||||
|
|
||||||
meta.plots.forEach((plot, plotIdx) => {
|
|
||||||
if (isObjectResult) {
|
|
||||||
const hasData = results.some(r => r && r[plot.id] !== undefined && r[plot.id] !== null);
|
|
||||||
if (!hasData) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const plotColor = indicator.params[`_color_${plotIdx}`] || plot.color || '#2962ff';
|
|
||||||
|
|
||||||
const data = [];
|
|
||||||
for (let i = 0; i < candles.length; i++) {
|
|
||||||
let value;
|
|
||||||
if (isObjectResult) {
|
|
||||||
value = results[i]?.[plot.id];
|
|
||||||
} else {
|
|
||||||
value = results[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value !== null && value !== undefined) {
|
|
||||||
data.push({
|
|
||||||
time: candles[i].time,
|
|
||||||
value: value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.length === 0) return;
|
|
||||||
|
|
||||||
let series;
|
|
||||||
|
|
||||||
let plotLineStyle = lineStyle;
|
|
||||||
if (plot.style === 'dashed') plotLineStyle = LightweightCharts.LineStyle.Dashed;
|
|
||||||
else if (plot.style === 'dotted') plotLineStyle = LightweightCharts.LineStyle.Dotted;
|
|
||||||
else if (plot.style === 'solid') plotLineStyle = LightweightCharts.LineStyle.Solid;
|
|
||||||
|
|
||||||
if (plot.type === 'histogram') {
|
|
||||||
series = window.dashboard.chart.addSeries(LightweightCharts.HistogramSeries, {
|
|
||||||
color: plotColor,
|
|
||||||
priceFormat: { type: 'price', precision: 4, minMove: 0.0001 },
|
|
||||||
priceLineVisible: false,
|
|
||||||
lastValueVisible: false
|
|
||||||
}, paneIndex);
|
|
||||||
} else if (plot.type === 'baseline') {
|
|
||||||
series = window.dashboard.chart.addSeries(LightweightCharts.BaselineSeries, {
|
|
||||||
baseValue: { type: 'price', price: plot.baseValue || 0 },
|
|
||||||
topLineColor: plot.topLineColor || plotColor,
|
|
||||||
topFillColor1: plot.topFillColor1 || plotColor,
|
|
||||||
topFillColor2: '#00000000',
|
|
||||||
bottomFillColor1: '#00000000',
|
|
||||||
bottomColor: plot.bottomColor || '#00000000',
|
|
||||||
lineWidth: plot.width !== undefined ? plot.width : lineWidth,
|
|
||||||
lineStyle: plotLineStyle,
|
|
||||||
title: plot.title || '',
|
|
||||||
priceLineVisible: false,
|
|
||||||
lastValueVisible: plot.lastValueVisible !== false
|
|
||||||
}, paneIndex);
|
|
||||||
} else {
|
|
||||||
series = window.dashboard.chart.addSeries(LightweightCharts.LineSeries, {
|
|
||||||
color: plotColor,
|
|
||||||
lineWidth: plot.width !== undefined ? plot.width : lineWidth,
|
|
||||||
lineStyle: plotLineStyle,
|
|
||||||
title: plot.title || '',
|
|
||||||
priceLineVisible: false,
|
|
||||||
lastValueVisible: plot.lastValueVisible !== false
|
|
||||||
}, paneIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
series.setData(data);
|
|
||||||
indicator.series.push(series);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let indicatorPanes = new Map();
|
|
||||||
let nextPaneIndex = 1;
|
|
||||||
|
|
||||||
// Legacy support
|
|
||||||
window.renderIndicatorList = function() {
|
|
||||||
renderIndicatorPanel();
|
|
||||||
};
|
|
||||||
|
|
||||||
window.renderIndicatorConfig = function(indicator) {
|
|
||||||
// Called by chart.js, redirect to new panel
|
|
||||||
const meta = getIndicatorMeta(indicator);
|
|
||||||
if (!meta) return;
|
|
||||||
|
|
||||||
const configEl = document.getElementById('configForm');
|
|
||||||
if (configEl) {
|
|
||||||
configEl.innerHTML = renderIndicatorConfig(indicator, meta);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.applyIndicatorConfig = function() {
|
|
||||||
// No-op - config is applied immediately
|
|
||||||
};
|
|
||||||
|
|
||||||
window.removeIndicator = function() {
|
window.removeIndicator = function() {
|
||||||
if (!configuringId) return;
|
if (!configuringId) return;
|
||||||
removeIndicatorById(configuringId);
|
removeIndicatorById(configuringId);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.removeIndicatorByIndex = function(index) {
|
// Export functions for module imports
|
||||||
|
export const addIndicator = window.addIndicator;
|
||||||
|
export const removeIndicatorById = window.removeIndicatorById;
|
||||||
|
|
||||||
|
// Helper function for remove by index
|
||||||
|
function removeIndicatorByIndex(index) {
|
||||||
if (index < 0 || index >= activeIndicators.length) return;
|
if (index < 0 || index >= activeIndicators.length) return;
|
||||||
removeIndicatorById(activeIndicators[index].id);
|
removeIndicatorById(activeIndicators[index].id);
|
||||||
};
|
}
|
||||||
|
|
||||||
window.addIndicator = addIndicator;
|
// Assign to window for backward compatibility
|
||||||
window.toggleIndicator = addIndicator;
|
window.toggleIndicator = window.addIndicator;
|
||||||
window.removeIndicatorById = removeIndicatorById;
|
window.removeIndicatorByIndex = removeIndicatorByIndex;
|
||||||
window.drawIndicatorsOnChart = drawIndicatorsOnChart;
|
window.drawIndicatorsOnChart = drawIndicatorsOnChart;
|
||||||
|
|
||||||
|
// No additional window assignments needed - functions are already on window
|
||||||
|
// Exports are now available for module import
|
||||||
Reference in New Issue
Block a user