전략평가 화면 수정
This commit is contained in:
@@ -4653,6 +4653,67 @@ export class ChartManager {
|
||||
return t === null ? null : (t as number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 전략 평가 — 클라이언트 좌표 → rawBars 내 가장 가까운 봉 index.
|
||||
* 캔들·보조지표 pane 클릭 허용, 가격축·시간축·플롯 밖 제외.
|
||||
*/
|
||||
resolveNearestBarIndexAtClientPoint(clientX: number, clientY: number): number {
|
||||
const rect = this.container.getBoundingClientRect();
|
||||
const chartX = clientX - rect.left;
|
||||
const chartY = clientY - rect.top;
|
||||
|
||||
if (
|
||||
chartX < 0 || chartY < 0
|
||||
|| chartX > this.container.clientWidth
|
||||
|| chartY > this.container.clientHeight
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
if (this.isOnPriceAxis(chartX, chartY) || this.isOnTimeAxis(chartY)) return -1;
|
||||
|
||||
const layouts = this.getPaneLayouts();
|
||||
const inPane = layouts.some(
|
||||
l => chartY >= l.topY && chartY < l.topY + l.height && l.height >= 4,
|
||||
);
|
||||
if (!inPane || this.rawBars.length === 0) return -1;
|
||||
|
||||
const bar = this._barAtChartX(chartX);
|
||||
if (!bar) return -1;
|
||||
|
||||
const idx = this.rawBars.findIndex(b => (b.time as number) === (bar.time as number));
|
||||
return idx >= 0 ? idx : -1;
|
||||
}
|
||||
|
||||
/** LWC 클릭 — 전략선택봉 이동 (캔들 pane 클릭) */
|
||||
subscribeBarSelectClick(onSelect: (barIndex: number) => void): () => void {
|
||||
const handler = (param: MouseEventParams<Time>) => {
|
||||
if (param.time == null || this.rawBars.length === 0) return;
|
||||
const time = param.time as number;
|
||||
let idx = this.rawBars.findIndex(b => (b.time as number) === time);
|
||||
if (idx < 0) {
|
||||
let bestIdx = 0;
|
||||
let bestDist = Number.POSITIVE_INFINITY;
|
||||
for (let i = 0; i < this.rawBars.length; i++) {
|
||||
const dist = Math.abs((this.rawBars[i].time as number) - time);
|
||||
if (dist < bestDist) {
|
||||
bestDist = dist;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
idx = bestIdx;
|
||||
}
|
||||
if (idx >= 0) onSelect(idx);
|
||||
};
|
||||
this.chart.subscribeClick(handler);
|
||||
return () => {
|
||||
try {
|
||||
this.chart.unsubscribeClick(handler);
|
||||
} catch {
|
||||
/* ok */
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
yToPrice(y: number): number | null {
|
||||
const p = this.mainSeries?.coordinateToPrice(y);
|
||||
return p === null || p === undefined ? null : p;
|
||||
|
||||
Reference in New Issue
Block a user