SGraphyCircleItem.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * 线条
  3. */
  4. import SGraphyItem from '../SGraphyItem'
  5. import SRect from '../types/SRect';
  6. export default class SGraphyCircleItem extends SGraphyItem {
  7. /**
  8. * 构造函数
  9. *
  10. * @param X 圆中心点X
  11. * @param Y 圆中心点Y
  12. * @param Radius 圆的半径
  13. *
  14. * @param color 线的颜色
  15. * @param isVirtual 是否为虚线
  16. */
  17. constructor(X, Y, color, Radius, isSolid, name, parent = null) {
  18. super(parent)
  19. this.X = X
  20. this.Y = Y
  21. this.color = color
  22. this.Radius = Radius
  23. this.isSolid = isSolid
  24. this.minX = this.X - this.Radius
  25. this.minY = this.Y - this.Radius
  26. this.maxX = this.X + this.Radius
  27. this.maxY = this.Y + this.Radius
  28. this.sAngle = null || 0
  29. this.eAngle = null || 2 * Math.PI
  30. this.name = name
  31. this.type = 6
  32. this.lineWidth = null
  33. }
  34. /**
  35. * Item对象边界区域
  36. *
  37. * @return SRect
  38. */
  39. boundingRect() {
  40. return new SRect(this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY)
  41. }
  42. /**
  43. * 绘制线条
  44. *
  45. * @param canvas 画布
  46. * @param rect 绘制区域
  47. */
  48. onDraw(canvas, rect) {
  49. canvas.lineWidth = this.lineWidth || 240
  50. canvas.strokeStyle = this.color || '#000'
  51. canvas.fillStyle = this.color || '#000'
  52. canvas.beginPath();
  53. canvas.arc(this.X, this.Y, this.Radius, this.sAngle, this.eAngle);
  54. if (!!this.isSolid) {
  55. canvas.fillStyle = this.color; //填充颜色,默认是黑色
  56. canvas.fill(); //画实心圆
  57. }
  58. canvas.stroke()
  59. if (!!this.name) {
  60. canvas.font = "oblique small-caps bold " + this.lineWidth * 10 + "px Arial";
  61. // canvas.font = "oblique small-caps bold " + 10 + "px Arial";
  62. canvas.fillStyle = 'green'
  63. canvas.fillText(this.name, this.X, this.Y);
  64. }
  65. }
  66. }