diff --git a/src/components/CandleChart.tsx b/src/components/CandleChart.tsx index af13d26..e01dbbd 100644 --- a/src/components/CandleChart.tsx +++ b/src/components/CandleChart.tsx @@ -763,13 +763,16 @@ const CandleChart = forwardRef( const timestamp = typeof time === 'string' ? Date.parse(time) / 1000 : (time as number); // First, check for line hit using primitives' hitTest - let deleteLineHit: { id: number; primitive: TrendLine } | null = null; - linePrimitivesRef.current.forEach((primitive, id) => { - const hit = primitive.hitTest(timeCoordinate, priceCoordinate); - if (hit) { - deleteLineHit = { id, primitive }; - } - }); + const deleteLineHit = (() => { + let result: { id: number; primitive: TrendLine } | null = null; + linePrimitivesRef.current.forEach((primitive, id) => { + const hit = primitive.hitTest(timeCoordinate, priceCoordinate); + if (hit) { + result = { id, primitive }; + } + }); + return result as { id: number; primitive: TrendLine } | null; + })(); if (deleteLineHit) { // Delete the clicked line @@ -794,13 +797,16 @@ const CandleChart = forwardRef( } // Next, check for rectangle hit using primitives' hitTest - let rectangleHit: { id: number; primitive: RectangleDrawingPrimitive } | null = null; - rectanglePrimitivesRef.current.forEach((primitive, id) => { - const hit = primitive.hitTest(timeCoordinate, priceCoordinate); - if (hit) { - rectangleHit = { id, primitive }; - } - }); + const rectangleHit = (() => { + let result: { id: number; primitive: RectangleDrawingPrimitive } | null = null; + rectanglePrimitivesRef.current.forEach((primitive, id) => { + const hit = primitive.hitTest(timeCoordinate, priceCoordinate); + if (hit) { + result = { id, primitive }; + } + }); + return result as { id: number; primitive: RectangleDrawingPrimitive } | null; + })(); if (rectangleHit) { // Delete the clicked rectangle @@ -853,13 +859,16 @@ const CandleChart = forwardRef( // Handle line selection when no tool is active or delete tool is active if (!activeTool || activeTool === 'delete') { // Check if a line was clicked - let lineHit: { id: number; primitive: TrendLine } | null = null; - linePrimitivesRef.current.forEach((primitive, id) => { - const hit = primitive.hitTest(timeCoordinate, priceCoordinate); - if (hit && activeTool !== 'delete') { - lineHit = { id, primitive }; - } - }); + const lineHit = (() => { + let result: { id: number; primitive: TrendLine } | null = null; + linePrimitivesRef.current.forEach((primitive, id) => { + const hit = primitive.hitTest(timeCoordinate, priceCoordinate); + if (hit && activeTool !== 'delete') { + result = { id, primitive }; + } + }); + return result as { id: number; primitive: TrendLine } | null; + })(); if (lineHit && activeTool !== 'delete') { // Toggle selection diff --git a/src/plugins/trend-line.ts b/src/plugins/trend-line.ts index aa3f0f7..68cfec8 100644 --- a/src/plugins/trend-line.ts +++ b/src/plugins/trend-line.ts @@ -5,8 +5,8 @@ import { IChartApi, ISeriesApi, ISeriesPrimitive, - IPrimitivePaneRenderer, - IPrimitivePaneView, + ISeriesPrimitivePaneRenderer, + ISeriesPrimitivePaneView, Logical, SeriesOptionsMap, SeriesType, @@ -15,7 +15,7 @@ import { PrimitiveHoveredItem, } from 'lightweight-charts'; -class TrendLinePaneRenderer implements IPrimitivePaneRenderer { +class TrendLinePaneRenderer implements ISeriesPrimitivePaneRenderer { _p1: ViewPoint; _p2: ViewPoint; _text1: string; @@ -117,7 +117,7 @@ interface ViewPoint { y: Coordinate | null; } -class TrendLinePaneView implements IPrimitivePaneView { +class TrendLinePaneView implements ISeriesPrimitivePaneView { _source: TrendLine; _p1: ViewPoint = { x: null, y: null }; _p2: ViewPoint = { x: null, y: null };