백테스팅 차트 색상 오류 수정

This commit is contained in:
Macbook
2026-06-08 12:09:38 +09:00
parent c20c806c19
commit 9fde6868e2
5 changed files with 89 additions and 89 deletions
+51 -29
View File
@@ -142,16 +142,18 @@ export function layoutKey(inds: IndicatorConfig[]): string {
return inds.map(i => `${i.id}>${i.mergedWith ?? ''}`).join(';');
}
type GetParams = (
type: string,
defaults?: Record<string, number | string | boolean>,
) => Record<string, number | string | boolean>;
type ParamRecord = Record<string, number | string | boolean>;
type GetParams = (type: string, defaults?: ParamRecord) => ParamRecord;
type GetVisual = (
type: string,
defaultPlots?: PlotDef[],
defaultHlines?: HLineDef[],
) => { plots: PlotDef[]; hlines: HLineDef[]; cloudColors?: IchimokuCloudColors; bandBackground?: import('../types').HlinesBackground };
) => {
plots: PlotDef[];
hlines: HLineDef[];
cloudColors?: IchimokuCloudColors;
bandBackground?: import('../types').HlinesBackground;
};
/** 탭 전체 추가 — 기존 차트 지표를 제거하고 types 목록만 새로 구성 */
export function replaceIndicatorConfigsFromTypes(
@@ -163,6 +165,47 @@ export function replaceIndicatorConfigsFromTypes(
return buildIndicatorConfigsFromTypes(types, [], getParams, getVisualConfig, newId);
}
/** DB 보조지표 설정(파라미터·색상·선굵기·유형)을 반영한 단일 IndicatorConfig */
export function buildChartIndicatorConfig(
type: string,
id: string,
getParams: GetParams,
getVisualConfig: GetVisual,
extras: Partial<IndicatorConfig> = {},
): IndicatorConfig | null {
const def = getIndicatorDef(type);
if (!def) return null;
const params = getParams(type, def.defaultParams as ParamRecord);
const { plots, hlines, cloudColors, bandBackground } = getVisualConfig(
type,
def.plots,
def.hlines ?? [],
);
let cfg: IndicatorConfig = {
id,
type: def.type,
params,
plots,
hlines,
...(cloudColors ? { cloudColors } : {}),
...(bandBackground ? { bandBackground } : {}),
...extras,
};
if (type === 'SMA') {
cfg = normalizeSmaConfig({
...cfg,
plotVisibility: cfg.plotVisibility ?? createDefaultSmaPlotVisibility(),
});
} else if (type === 'IchimokuCloud') {
cfg = normalizeIchimokuConfig(cfg);
}
return enrichIndicatorConfig(cfg);
}
/** 지표 타입 목록 → 차트에 추가할 IndicatorConfig 배열 (이미 활성인 type 제외) */
export function buildIndicatorConfigsFromTypes(
types: string[],
@@ -176,30 +219,9 @@ export function buildIndicatorConfigsFromTypes(
for (const type of types) {
if (seen.has(type)) continue;
const def = getIndicatorDef(type);
if (!def) continue;
seen.add(type);
const params = getParams(type, def.defaultParams);
const { plots, hlines, cloudColors, bandBackground } = getVisualConfig(type, def.plots, def.hlines);
let cfg: IndicatorConfig = {
id: newId(),
type: def.type,
params,
plots,
hlines,
...(cloudColors ? { cloudColors } : {}),
...(bandBackground ? { bandBackground } : {}),
};
if (type === 'SMA') {
cfg = normalizeSmaConfig({
...cfg,
plotVisibility: cfg.plotVisibility ?? createDefaultSmaPlotVisibility(),
});
} else if (type === 'IchimokuCloud') {
cfg = normalizeIchimokuConfig(cfg);
}
out.push(cfg);
const cfg = buildChartIndicatorConfig(type, newId(), getParams, getVisualConfig);
if (cfg) out.push(cfg);
}
return out;
}