RelationItem.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2020. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphyItem } from "@saga-web/graphy/lib";
  21. import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  22. import { Relation } from "../types/Relation";
  23. import { SMouseEvent } from "@saga-web/base/lib";
  24. /**
  25. * 关系item
  26. *
  27. * @author 郝建龙
  28. */
  29. export class RelationItem extends SGraphyItem {
  30. /** 关系数据 */
  31. data: Relation | null = null;
  32. /** 折点信息 */
  33. pointList: SPoint[] = [];
  34. /** X坐标最小值 */
  35. private minX = Number.MAX_SAFE_INTEGER;
  36. /** X坐标最大值 */
  37. private maxX = Number.MIN_SAFE_INTEGER;
  38. /** Y坐标最小值 */
  39. private minY = Number.MAX_SAFE_INTEGER;
  40. /** Y坐标最大值 */
  41. private maxY = Number.MIN_SAFE_INTEGER;
  42. constructor(parent: SGraphyItem | null, data: Relation) {
  43. super(parent);
  44. this.data = data;
  45. this.pointList = data.pointList;
  46. data.pointList.forEach(it => {
  47. let x = it.x,
  48. y = it.y;
  49. if (x < this.minX) {
  50. this.minX = x;
  51. }
  52. if (y < this.minY) {
  53. this.minY = y;
  54. }
  55. if (x > this.maxX) {
  56. this.maxX = x;
  57. }
  58. if (y > this.maxY) {
  59. this.maxY = y;
  60. }
  61. });
  62. } // Constructor
  63. /**
  64. * Item对象边界区域
  65. *
  66. * @return SRect
  67. */
  68. boundingRect(): SRect {
  69. return new SRect(
  70. this.minX,
  71. this.minY,
  72. this.maxX - this.minX,
  73. this.maxY - this.minY
  74. );
  75. } // Function boundingRect()
  76. /**
  77. * 点击事件
  78. *
  79. */
  80. onClick(event: SMouseEvent): boolean {
  81. if (this.selectable) {
  82. this.selected = !this.selected;
  83. }
  84. this.$emit("click", event);
  85. return true;
  86. } // Function onClick
  87. /**
  88. * Item绘制操作
  89. *
  90. * @param painter painter对象
  91. */
  92. onDraw(painter: SPainter): void {
  93. painter.pen.lineWidth = 50;
  94. painter.drawPolyline(this.pointList);
  95. } // Function onDraw()
  96. } // Class RelationItem