const DEFAULT_INDICATOR_COLORS = [
'#2962FF',
'#FF6D00',
'#00C853',
'#D500F9',
'#FF1744',
'#00B8D4',
'#FFD600',
'#7C4DFF',
'#64DD17',
'#FF4081',
];
export function getNextIndicatorColor(usedColors: readonly string[]): string {
const normalizedUsedColors = new Set(usedColors.map((color) => color.toLowerCase()));
const freeColor = DEFAULT_INDICATOR_COLORS.find((color) => !normalizedUsedColors.has(color.toLowerCase()));
if (freeColor) {
return freeColor;
}
return generateColorByIndex(usedColors.length);
}
function generateColorByIndex(index: number): string {
const hue = (index * 137.508) % 360;
return `hsl(${Math.round(hue)}deg 72% 56%)`;
}
export function applyIndicatorColor(config: IndicatorConfig, color: string): IndicatorConfig {
return {
...config,
series: config.series.map((series) => {
const isVisibleLine = series.name === 'Line' && series.seriesOptions?.visible !== false;
if (!isVisibleLine) {
return series;
}
return {
...series,
seriesOptions: {
...series.seriesOptions,
color,
},
};
}),
};
}