지표탭 추가

This commit is contained in:
Macbook
2026-05-27 09:32:26 +09:00
parent d0985f8f0f
commit 8876dbd752
12 changed files with 595 additions and 73 deletions
+55
View File
@@ -1,5 +1,9 @@
import type { IndicatorConfig } from '../types';
import { enrichIndicatorConfig, getIndicatorDef } from './indicatorRegistry';
import { normalizeSmaConfig, createDefaultSmaPlotVisibility } from './smaConfig';
import { normalizeIchimokuConfig } from './ichimokuConfig';
import type { PlotDef, HLineDef } from './indicatorRegistry';
import type { IchimokuCloudColors } from './ichimokuConfig';
/** 보조지표 인스턴스 복제 (새 id, 별도 pane) */
export function cloneIndicatorConfig(src: IndicatorConfig, newId: string): IndicatorConfig {
@@ -137,3 +141,54 @@ export function splitIndicatorPane(
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 GetVisual = (
type: string,
defaultPlots?: PlotDef[],
defaultHlines?: HLineDef[],
) => { plots: PlotDef[]; hlines: HLineDef[]; cloudColors?: IchimokuCloudColors };
/** 지표 타입 목록 → 차트에 추가할 IndicatorConfig 배열 (이미 활성인 type 제외) */
export function buildIndicatorConfigsFromTypes(
types: string[],
existing: IndicatorConfig[],
getParams: GetParams,
getVisualConfig: GetVisual,
newId: () => string,
): IndicatorConfig[] {
const seen = new Set(existing.map(i => i.type));
const out: IndicatorConfig[] = [];
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 } = getVisualConfig(type, def.plots, def.hlines);
let cfg: IndicatorConfig = {
id: newId(),
type: def.type,
params,
plots,
hlines,
...(cloudColors ? { cloudColors } : {}),
};
if (type === 'SMA') {
cfg = normalizeSmaConfig({
...cfg,
plotVisibility: cfg.plotVisibility ?? createDefaultSmaPlotVisibility(),
});
} else if (type === 'IchimokuCloud') {
cfg = normalizeIchimokuConfig(cfg);
}
out.push(cfg);
}
return out;
}