All files / src/utils drawCanvas.js

0% Statements 0/20
0% Branches 0/6
0% Functions 0/1
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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