monitorPoint.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { getFont, Pen } from "@meta2d/core";
  2. export interface MonitorPointPen extends Pen {
  3. pointName?: string;
  4. pointTemperature?: string;
  5. pointHumidity?: string;
  6. }
  7. export function monitorPoint(
  8. ctx: CanvasRenderingContext2D,
  9. pen: MonitorPointPen
  10. ): void {
  11. const { x, y, width, height } = pen.calculative.worldRect;
  12. const { pointName, pointTemperature, pointHumidity } = pen;
  13. const isLock = meta2d.data().locked;
  14. const isNormal = true;
  15. ctx.save();
  16. // 状态图标中心坐标
  17. const iconX = x + width / 2;
  18. const iconY = y + height / 2;
  19. const iconColor = !isLock || isNormal ? "103, 194, 58" : "245, 108, 108"; // 正常状态 - 绿色、异常状态 - 红色
  20. // 绘制三个同心圆
  21. // 最大圆(直径24)
  22. ctx.beginPath();
  23. ctx.arc(iconX, iconY, 12, 0, Math.PI * 2);
  24. ctx.fillStyle = `rgba(${iconColor}, 0.3)`;
  25. ctx.fill();
  26. // 中圆(直径12)
  27. ctx.beginPath();
  28. ctx.arc(iconX, iconY, 6, 0, Math.PI * 2);
  29. ctx.fillStyle = `rgba(${iconColor}, 0.6)`;
  30. ctx.fill();
  31. // 最小圆(直径6)
  32. ctx.beginPath();
  33. ctx.arc(iconX, iconY, 3, 0, Math.PI * 2);
  34. ctx.fillStyle = `rgba(${iconColor}, 1)`;
  35. ctx.fill();
  36. ctx.font = getFont({
  37. fontWeight: "500",
  38. fontSize: 12,
  39. lineHeight: 22,
  40. });
  41. ctx.fillStyle = "rgba(0, 0, 0, 0.65)";
  42. ctx.textBaseline = "middle";
  43. // 绘制右侧文字
  44. if (!isLock) {
  45. ctx.fillText(pointName, iconX + 25, iconY);
  46. }
  47. // 绘制下方文字
  48. if (isLock && !isNormal) {
  49. ctx.textAlign = "center";
  50. ctx.fillText(`${pointTemperature}℃|${pointHumidity}%`, iconX, iconY + 35);
  51. }
  52. ctx.restore();
  53. }
  54. export const monitorPointData: MonitorPointPen = {
  55. name: "monitorPoint",
  56. width: 214,
  57. height: 140,
  58. pointTemperature: "-",
  59. pointHumidity: "-",
  60. };