알림목록 백테스팅 차트에서 이동평균선, 일목균형표, 볼린저 그래프 표시
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { useCallback, useMemo, useRef, useState, type RefObject } from 'react';
|
||||
import type { IndicatorConfig } from '../types';
|
||||
import type { ChartManager } from '../utils/ChartManager';
|
||||
import type { ChartOverlayToggleKey } from '../utils/chartOverlayVisibility';
|
||||
import {
|
||||
applyPaperOverlayVisibility,
|
||||
DEFAULT_PAPER_OVERLAY_VISIBILITY,
|
||||
listPaperOverlayToggleItems,
|
||||
paperOverlayVisibilityToChart,
|
||||
type PaperOverlayToggleKey,
|
||||
type PaperOverlayVisibility,
|
||||
} from '../utils/paperChartOverlayVisibility';
|
||||
|
||||
/** 알림·백테스트 등 — 캔들 오버레이 표시/숨김 (세션만, DB 미저장) */
|
||||
export function useSessionCandleOverlayControls(
|
||||
managerRef: RefObject<ChartManager | null>,
|
||||
baseIndicators: IndicatorConfig[],
|
||||
) {
|
||||
const [overlayVisibility, setOverlayVisibility] = useState<PaperOverlayVisibility>(
|
||||
() => ({ ...DEFAULT_PAPER_OVERLAY_VISIBILITY }),
|
||||
);
|
||||
const overlayVisibilityRef = useRef(overlayVisibility);
|
||||
overlayVisibilityRef.current = overlayVisibility;
|
||||
|
||||
const indicators = useMemo(
|
||||
() => applyPaperOverlayVisibility(baseIndicators, overlayVisibility),
|
||||
[baseIndicators, overlayVisibility],
|
||||
);
|
||||
|
||||
const candleOverlayToggles = useMemo(
|
||||
() => listPaperOverlayToggleItems(baseIndicators, overlayVisibility),
|
||||
[baseIndicators, overlayVisibility],
|
||||
);
|
||||
|
||||
const syncToManager = useCallback((mgr: ChartManager) => {
|
||||
mgr.setChartOverlayVisibility(paperOverlayVisibilityToChart(overlayVisibilityRef.current));
|
||||
}, []);
|
||||
|
||||
const handleToggleCandleOverlay = useCallback((key: ChartOverlayToggleKey) => {
|
||||
const pKey = key as PaperOverlayToggleKey;
|
||||
if (!(pKey in DEFAULT_PAPER_OVERLAY_VISIBILITY)) return;
|
||||
setOverlayVisibility(prev => {
|
||||
const nextVisible = !prev[pKey];
|
||||
managerRef.current?.setChartOverlayGroupVisible(key, nextVisible);
|
||||
return { ...prev, [pKey]: nextVisible };
|
||||
});
|
||||
}, [managerRef]);
|
||||
|
||||
return {
|
||||
indicators,
|
||||
candleOverlayToggles,
|
||||
handleToggleCandleOverlay,
|
||||
syncToManager,
|
||||
overlayVisibility,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user