UNPKG

1.48 kBJavaScriptView Raw
1/**
2 * @author SoldierAb
3 * @description 绘制光标箭头
4 */
5
6
7
8import getAngle from './getAngle';
9
10export default ({ cxt, x1, y1, x2, y2, color }) => {
11 console.log(x1, y1, x2, y2);
12 if (!x1) x1 = 0;
13 if (!x2) x2 = 0;
14 if (!color) color = 'red';
15 //角度获取
16 let { angle, xdis, ydis } = getAngle(x1, y1, x2, y2);
17 // let { angle, xdis, ydis } = getAngle(0,0, x2, y2);
18 // console.log('-------------------',angle,xdis,ydis);
19 //旋转角度计算
20 // if (xdis < 0 && ydis < 0) {
21 // if(angle) cxt.rotate(((angle) / 360) * Math.PI * 2);
22 // } else if (xdis < 0 && ydis > 0) {
23 // if(angle) cxt.rotate(((angle + 180) / 360) * Math.PI * 2);
24 // } else if (xdis > 0 && ydis > 0) {
25 // if(angle) cxt.rotate(((270 - angle) / 360) * Math.PI * 2);
26 // } else if (xdis > 0 && ydis < 0) {
27 // if(angle) cxt.rotate(((angle + 90) / 360) * Math.PI * 2);
28 // }
29
30 //渐变色设置
31 // let grd = cxt.createLinearGradient(x2, y2, x2+20, y2);
32 let grd = cxt.createLinearGradient(0, 0, 20, 0);
33 grd.addColorStop(0, 'white');
34 grd.addColorStop(1, "white");
35 cxt.fillStyle = grd;
36
37 //绘制图例样式
38 cxt.beginPath();
39 cxt.arc(x2, y2, 10, Math.PI * 0.5, Math.PI * 1.5);
40 cxt.lineTo(x2, y2-10);
41 cxt.lineTo(x2+20, y2-4); //尾巴,坐标同渐变结束点
42 cxt.lineTo(x2+20, y2+4); //尾巴,坐标同渐变结束点
43 cxt.lineTo(x2, y2+10);
44 cxt.fill();
45 cxt.closePath();
46}
\No newline at end of file