(
{
ctx, start, end, isFlipped, squareSize
}:{ ctx: CanvasRenderingContext2D,
start: string,
end: string,
isFlipped: boolean,squareSize: number}
)
| 18 | return rowIndex * squareSize + squareSize / 2; |
| 19 | }; |
| 20 | export const drawArrow = ( |
| 21 | { |
| 22 | ctx, start, end, isFlipped, squareSize |
| 23 | }:{ ctx: CanvasRenderingContext2D, |
| 24 | start: string, |
| 25 | end: string, |
| 26 | isFlipped: boolean,squareSize: number} |
| 27 | ) => { |
| 28 | const startX = calculateX(start, isFlipped, squareSize); |
| 29 | const startY = calculateY(start, isFlipped, squareSize); |
| 30 | const endX = calculateX(end, isFlipped, squareSize); |
| 31 | const endY = calculateY(end, isFlipped, squareSize); |
| 32 | |
| 33 | // Draw arrow |
| 34 | ctx.beginPath(); |
| 35 | ctx.moveTo(startX, startY); |
| 36 | ctx.lineTo(endX, endY); |
| 37 | ctx.strokeStyle = '#EC923F'; |
| 38 | ctx.lineWidth = 2; |
| 39 | ctx.stroke(); |
| 40 | |
| 41 | // Draw arrowhead |
| 42 | const angle = Math.atan2(endY - startY, endX - startX); |
| 43 | const arrowheadSize = 15; // Adjust arrowhead size as needed |
| 44 | const arrowheadX1 = endX - arrowheadSize * Math.cos(angle - Math.PI / 6); |
| 45 | const arrowheadY1 = endY - arrowheadSize * Math.sin(angle - Math.PI / 6); |
| 46 | const arrowheadX2 = endX - arrowheadSize * Math.cos(angle + Math.PI / 6); |
| 47 | const arrowheadY2 = endY - arrowheadSize * Math.sin(angle + Math.PI / 6); |
| 48 | |
| 49 | ctx.beginPath(); |
| 50 | ctx.moveTo(endX, endY); |
| 51 | ctx.lineTo(arrowheadX1, arrowheadY1); |
| 52 | ctx.moveTo(endX, endY); |
| 53 | ctx.lineTo(arrowheadX2, arrowheadY2); |
| 54 | ctx.strokeStyle = '#EC923F'; |
| 55 | ctx.lineWidth = 2; |
| 56 | ctx.stroke(); |
| 57 | }; |
no test coverage detected