SGraphyVirtualItem.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * 线条
  3. */
  4. import SGraphyItem from '../../node-templete/SGraphy/SGraphyItem'
  5. import SRect from '../../node-templete/SGraphy/types/SRect';
  6. export default class SGraphyLineItem extends SGraphyItem {
  7. /**
  8. * 构造函数
  9. *
  10. * @param startX 线的起始x坐标
  11. * @param startY 线的起始y坐标
  12. * @param endX 线的终止x坐标
  13. * @param endY 线的终止y坐标
  14. * @param width 线的宽度
  15. *
  16. * @param color 线的颜色
  17. * @param isVirtual 是否为虚线
  18. *
  19. * @param canMove 移动
  20. */
  21. constructor(startX, startY, endX, endY, color, width, isVirtual, canMove, parent = null) {
  22. super(parent)
  23. this.startX = startX
  24. this.startY = startY
  25. this.endX = endX
  26. this.endY = endY
  27. this.color = color
  28. this.width = width
  29. this.isVirtual = isVirtual
  30. this.minX = Math.min(this.startX, this.endX)
  31. this.minY = Math.min(this.startY, this.endY)
  32. this.maxX = Math.max(this.startX, this.endX)
  33. this.maxY = Math.max(this.startY, this.endY)
  34. this.type = 4
  35. // this.canMove = true
  36. }
  37. /**
  38. * Item对象边界区域
  39. *
  40. * @return SRect
  41. */
  42. boundingRect() {
  43. return new SRect(this.minX, this.minY, (this.maxX - this.minX), (this.maxY - this.minY))
  44. }
  45. /**
  46. * 绘制线条
  47. *
  48. * @param canvas 画布
  49. * @param rect 绘制区域
  50. */
  51. onDraw(canvas, rect) {
  52. if (this.isVirtual) {
  53. canvas.setLineDash([240, 240])
  54. }
  55. canvas.lineWidth = 240
  56. canvas.strokeStyle = this.color || '#000'
  57. canvas.beginPath();
  58. canvas.moveTo(this.startX, this.startY)
  59. canvas.lineTo(this.endX, this.endY)
  60. canvas.stroke()
  61. }
  62. }