import React, { useRef, useEffect } from 'react'; import { Box } from '@mui/material'; export interface FibonacciFanObject { id: string; type: 'fibonacciFan'; startPrice: number; endPrice: number; startTime: number; endTime: number; settings: { color: string; lineWidth: number; lineStyle: 'solid' | 'dashed' | 'dotted'; levels: number[]; showLabels: boolean; }; } interface FibonacciFanProps { objects: FibonacciFanObject[]; chartWidth: number; chartHeight: number; totalChartHeight?: number; priceScale: { from: number; to: number; }; timeScale: { from: number; to: number; }; candleData: Array<{ time: string | number; open: number; high: number; low: number; close: number }>; timeToX: (time: number) => number | null; priceToY: (price: number) => number | null; onClick?: (objectId: string, event: React.MouseEvent) => void; onDoubleClick?: (objectId: string) => void; onDragStart?: (objectId: string, startX: number, startTime: number) => void; } const FibonacciFan: React.FC = ({ objects, chartWidth, chartHeight, totalChartHeight, priceScale, timeScale, candleData, timeToX, priceToY, onClick, onDoubleClick, onDragStart, }) => { const svgRef = useRef(null); const calculateFanLines = (startPrice: number, endPrice: number) => { const priceRange = endPrice - startPrice; const levels = [0.382, 0.5, 0.618]; // 기본 피보나치 팬 레벨 return levels.map(level => ({ level, price: startPrice + (priceRange * level) })); }; const renderFan = (fanObject: FibonacciFanObject) => { const startX = timeToX(fanObject.startTime); const endX = timeToX(fanObject.endTime); const startY = priceToY(fanObject.startPrice); if (startX === null || endX === null || startY === null) return null; const fanLines = calculateFanLines(fanObject.startPrice, fanObject.endPrice); return ( {fanLines.map((fanLine, index) => { const endY = priceToY(fanLine.price); if (endY === null) return null; const strokeDasharray = fanObject.settings.lineStyle === 'dashed' ? '5,5' : fanObject.settings.lineStyle === 'dotted' ? '2,2' : undefined; return ( onClick?.(fanObject.id, e)} onDoubleClick={() => onDoubleClick?.(fanObject.id)} /> {fanObject.settings.showLabels && ( {`${(fanLine.level * 100).toFixed(1)}%`} )} ); })} ); }; return ( {objects.map(renderFan)} ); }; export default FibonacciFan;