SSpaceItemSS.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SSpaceItem = void 0;
  4. const lib_1 = require("@persagy-web/draw/lib");
  5. const __1 = require("../..");
  6. const __2 = require("../..");
  7. const lib_2 = require("@persagy-web/graph/lib");
  8. class SSpaceItem extends lib_2.SGraphItem {
  9. constructor(parent, data) {
  10. super(parent);
  11. this.pointArr = [];
  12. this.minX = Number.MAX_SAFE_INTEGER;
  13. this.maxX = Number.MIN_SAFE_INTEGER;
  14. this.minY = Number.MAX_SAFE_INTEGER;
  15. this.maxY = Number.MIN_SAFE_INTEGER;
  16. this.path = new lib_1.SPath2D();
  17. this._highLightFlag = false;
  18. this._showBaseName = false;
  19. this._nameSize = 10;
  20. this._nameTransform = false;
  21. this._nameColor = "#000000";
  22. this.data = data;
  23. this.zOrder = __1.ItemOrder.spaceOrder;
  24. let tempArr = this.data.OutLine;
  25. this.name = data.Name || "";
  26. if (tempArr && tempArr.length) {
  27. this.minX = tempArr[0][0].X;
  28. this.maxX = this.minX;
  29. this.minY = -tempArr[0][0].Y;
  30. this.maxY = this.minY;
  31. this.pointArr = tempArr.map((t) => {
  32. let temp = t.map((it) => {
  33. let x = it.X, y = -it.Y;
  34. if (x < this.minX) {
  35. this.minX = x;
  36. }
  37. if (y < this.minY) {
  38. this.minY = y;
  39. }
  40. if (x > this.maxX) {
  41. this.maxX = x;
  42. }
  43. if (y > this.maxY) {
  44. this.maxY = y;
  45. }
  46. return new lib_1.SPoint(x, y);
  47. });
  48. this.path.polygon(temp);
  49. return temp;
  50. });
  51. }
  52. }
  53. get highLightFlag() {
  54. return this._highLightFlag;
  55. }
  56. set highLightFlag(value) {
  57. this._highLightFlag = value;
  58. this.update();
  59. }
  60. get showBaseName() {
  61. return this._showBaseName;
  62. }
  63. set showBaseName(value) {
  64. this._showBaseName = value;
  65. this.update();
  66. }
  67. get nameSize() {
  68. return this._nameSize;
  69. }
  70. set nameSize(value) {
  71. this._nameSize = value;
  72. this.update();
  73. }
  74. get nameTransform() {
  75. return this._nameTransform;
  76. }
  77. set nameTransform(value) {
  78. this._nameTransform = value;
  79. this.update();
  80. }
  81. get nameColor() {
  82. return this._nameColor;
  83. }
  84. set nameColor(value) {
  85. this._nameColor = value;
  86. this.update();
  87. }
  88. boundingRect() {
  89. return new lib_1.SRect(this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY);
  90. }
  91. contains(x, y) {
  92. let arr = this.pointArr;
  93. if (arr.length < 1 || !lib_1.SPolygonUtil.pointIn(x, y, arr[0])) {
  94. return false;
  95. }
  96. for (let i = 1; i < arr.length; i++) {
  97. if (lib_1.SPolygonUtil.pointIn(x, y, arr[i])) {
  98. return false;
  99. }
  100. }
  101. return true;
  102. }
  103. onDraw(painter) {
  104. painter.pen.color = __2.ItemColor.spaceBorderColor;
  105. if (this.selected) {
  106. painter.brush.color = __2.ItemColor.selectColor;
  107. }
  108. else if (this.highLightFlag) {
  109. painter.brush.color = __2.ItemColor.spaceHighColor;
  110. }
  111. else {
  112. painter.brush.color = __2.ItemColor.spaceColor;
  113. }
  114. painter.pen.lineWidth = painter.toPx(1);
  115. painter.drawPath(this.path);
  116. if (this.showBaseName) {
  117. if (this.name && this.name != "null") {
  118. painter.brush.color = new lib_1.SColor(this.nameColor);
  119. if (this.nameTransform) {
  120. painter.font.size = this.nameSize;
  121. }
  122. else {
  123. painter.font.size = painter.toPx(this.nameSize);
  124. }
  125. painter.font.textAlign = lib_1.STextAlign.Center;
  126. painter.drawText(this.name, this.data.Location.Points[0].X, -this.data.Location.Points[0].Y);
  127. }
  128. }
  129. }
  130. }
  131. exports.SSpaceItem = SSpaceItem;