he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
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
47
48
49
50
51
52
53
54
55
56
import Circle from "./Circle";
class PeakValueCircle extends Circle {
  constructor(el) {
    super(el);
    this.startState = false;
    this.startAngle = Math.PI * 5 / 4;
    this.stepAngle = Math.PI * 1 / 180;
  }
  draw() {
    let ctx = this.context;
    // 绘制外轮廓
    let radius1 = this.radius * 3 / 5;
    this.strokeCircle(radius1, Math.PI * 37 / 36, Math.PI * 71 / 36, "#00FFFF", 6);
    this.strokeCircle(radius1, Math.PI * 1 / 36, Math.PI * 35 / 36, "#00FFFF", 6);
    // 绘制圆环边框
    let radius2 = radius1 - 10;
    this.strokeCircle(radius2, 0, Math.PI * 2, "#FEF000", 1);
    // 设置内层的圆环
    let angle1 = this.startAngle;
    let angle2 = this.getAngle(angle1);
    let angle3 = this.getAngle(angle2);
    let angle4 = this.getAngle(angle3);
    this.strokeCircle(radius2 - 3, angle1, angle2, "#FEF000", 6);
    this.strokeCircle(radius2 - 3, angle3, angle4, "#FEF000", 6);
    // 绘制内层的实心圆
    let radius3 = radius2 - 8;
    let grd = ctx.createLinearGradient(0, 0, 0, radius3 * 3);
    grd.addColorStop(0, "#FDDA99");
    grd.addColorStop(1, "#fe7a2c");
    this.fillCircle(radius3, 0, Math.PI * 2, grd);
  }
  start(start) {
    if (start) {
      console.log('已经启动持续更新');
      this.startState = true;
    }
    // 停止更新
    if (!this.startState) {
      return;
    }
    this.clear();
    // 启动动画
    this.startAngle = this.getAngle(this.startAngle, this.stepAngle);
    this.draw();
    // 持续更新函数
    let self = this;
    requestAnimationFrame(function () {
      self.start();
    });
  }
  stop() {
    this.startState = false;
    console.log('已经停止持续更新');
  }
}
export default PeakValueCircle;