단순이동평균선 이름 표시방식 변경
This commit is contained in:
@@ -40,10 +40,49 @@ export function smaPeriodKey(maIndex: number): string {
|
||||
return `period${maIndex}`;
|
||||
}
|
||||
|
||||
/** 설정 기간 → 표시명 MA5일 (보조지표·차트·전략 공통) */
|
||||
export function formatSmaPeriodDisplayLabel(
|
||||
period: number | string | boolean | undefined,
|
||||
fallback = SMA_DEFAULT_PERIODS[0],
|
||||
): string {
|
||||
const raw = typeof period === 'number' ? period : Number(period);
|
||||
const p = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : fallback;
|
||||
return `MA${p}일`;
|
||||
}
|
||||
|
||||
export function resolveSmaMaPeriod(
|
||||
params: Record<string, number | string | boolean> | undefined,
|
||||
maIndex: number,
|
||||
): number {
|
||||
const slot = Math.max(1, Math.min(SMA_MA_COUNT, Math.floor(maIndex)));
|
||||
const raw = params?.[smaPeriodKey(slot)];
|
||||
if (typeof raw === 'number' && raw > 0) return Math.floor(raw);
|
||||
return SMA_DEFAULT_PERIODS[slot - 1];
|
||||
}
|
||||
|
||||
/** MA 슬롯(1~11) + params → MA5일 */
|
||||
export function formatSmaMaDisplayLabel(
|
||||
params: Record<string, number | string | boolean> | undefined,
|
||||
maIndex: number,
|
||||
): string {
|
||||
return formatSmaPeriodDisplayLabel(resolveSmaMaPeriod(params, maIndex));
|
||||
}
|
||||
|
||||
/** params 변경 시 plot.title 을 MA{period}일 로 동기화 */
|
||||
export function syncSmaPlotTitles(
|
||||
params: Record<string, number | string | boolean>,
|
||||
plots: PlotDef[],
|
||||
): PlotDef[] {
|
||||
return plots.map((plot, i) => ({
|
||||
...plot,
|
||||
title: formatSmaMaDisplayLabel(params, i + 1),
|
||||
}));
|
||||
}
|
||||
|
||||
export function createDefaultSmaPlots(): PlotDef[] {
|
||||
return SMA_DEFAULT_PERIODS.map((_, i) => ({
|
||||
return SMA_DEFAULT_PERIODS.map((period, i) => ({
|
||||
id: smaPlotId(i),
|
||||
title: `MA${i + 1}`,
|
||||
title: formatSmaPeriodDisplayLabel(period),
|
||||
color: SMA_DEFAULT_COLORS[i],
|
||||
type: 'line',
|
||||
lineWidth: 2,
|
||||
@@ -114,7 +153,7 @@ export function normalizeSmaConfig(config: IndicatorConfig): IndicatorConfig {
|
||||
const plots: PlotDef[] = defaultPlots.map((def, i) => {
|
||||
const saved = savedById.get(def.id) ?? config.plots?.[i];
|
||||
return saved
|
||||
? { ...def, ...saved, id: def.id, title: `MA${i + 1}`, type: 'line' as const }
|
||||
? { ...def, ...saved, id: def.id, title: formatSmaMaDisplayLabel(params, i + 1), type: 'line' as const }
|
||||
: def;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user