SImageLegendItem.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { SGraphItem } from "@saga-web/graph/lib";
  2. import { SIconTextItem } from '@saga-web/big/lib/items/SIconTextItem';
  3. import { Legend } from '../types/Legend';
  4. import { ItemOrder, SItemStatus } from '@saga-web/big/lib';
  5. import { SFont, SColor, SPainter, SRect } from '@saga-web/draw/lib';
  6. import { SMouseEvent } from "@saga-web/base/lib";
  7. /**
  8. * 图例节点Item(图标类型)
  9. *
  10. * * @author 张宇(taohuzy@163.com)
  11. */
  12. export class SImageLegendItem extends SIconTextItem {
  13. /** 图例节点对象数据 */
  14. data: Legend;
  15. /** 图例数量 */
  16. _num: number = 1;
  17. get num(): number {
  18. return this._num;
  19. }
  20. set num(v: number) {
  21. if (v) {
  22. this._num = v;
  23. this.data.Num = v;
  24. } else {
  25. this._num = 1;
  26. this.data.Num = 1;
  27. }
  28. this.data.Properties.Num = this._num;
  29. this.textItem.text = `${this.name}${this.num > 1 ? `×${this.num}` : ''}`;
  30. this.update();
  31. }
  32. get text(): string {
  33. return this.textItem.text;
  34. }
  35. set text(v: string) {
  36. this.name = v;
  37. this.data.Name = v;
  38. this.textItem.text = `${this.name}${this.num > 1 ? `×${this.num}` : ''}`;
  39. this.update();
  40. }
  41. /** 是否蒙版遮罩 */
  42. _maskFlag: boolean = false;
  43. get maskFlag(): boolean {
  44. return this._maskFlag;
  45. }
  46. set maskFlag(v: boolean) {
  47. if (v === this._maskFlag) {
  48. return
  49. }
  50. this._maskFlag = v;
  51. if (v) {
  52. this.textItem.visible = false;
  53. } else {
  54. this.textItem.visible = true;
  55. }
  56. this.update()
  57. }
  58. get selected() {
  59. return this._selected && this.selectable && this.enabled;
  60. }
  61. set selected(value) {
  62. if (this.selected == value) {
  63. return;
  64. }
  65. this._selected = value;
  66. if (value) {
  67. this.img.scale = 1.6;
  68. this.zOrder = ItemOrder.highLightOrder;
  69. }
  70. else {
  71. this.img.scale = 1;
  72. this.zOrder = ItemOrder.markOrder;
  73. }
  74. this.update();
  75. }
  76. /**
  77. * 构造函数
  78. *
  79. * @param parent 指向父对象
  80. * @param data 图例节点对象数据
  81. */
  82. constructor(parent: SGraphItem | null, data: Legend) {
  83. super(parent, data.AnchorList);
  84. this.isTransform = false;
  85. this.zOrder = ItemOrder.markOrder;
  86. this.data = data;
  87. this.id = data.ID;
  88. this.name = data.Name;
  89. this.text = data.Name;
  90. this.moveTo(data.Pos.X, data.Pos.Y);
  91. if (data.Num) {
  92. this.num = data.Num;
  93. }
  94. if (data.Size) {
  95. this.width = data.Size.Width;
  96. this.height = data.Size.Height;
  97. }
  98. if (data.Properties.Zorder) {
  99. this.zOrder = data.Properties.Zorder;
  100. }
  101. if (data.Properties && data.Properties.Url) {
  102. this.img.url = data.Properties.Url;
  103. }
  104. if (data.Properties && data.Properties.Size && data.Properties.Size.Width) {
  105. this.sWidth = data.Properties.Size.Width;
  106. }
  107. if (data.Properties && data.Properties.Size && data.Properties.Size.Height) {
  108. this.sHeight = data.Properties.Size.Height;
  109. }
  110. if (data.Properties.ImgPos) {
  111. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  112. }
  113. if (data.Properties && data.Properties.ImgRotate) {
  114. this.img.rotate = data.Properties.ImgRotate;
  115. }
  116. if (data.Properties && data.Properties.font) {
  117. this.font = new SFont("sans-serif", data.Properties.font);
  118. }
  119. if (data.Properties.TextPos) {
  120. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  121. } else {
  122. // 偏移二分之一文本高度
  123. this.textItem.moveTo((this.img.width * 0.5), -(this.font.size * 1.25 * 0.5));
  124. }
  125. if (data.Properties && data.Properties.color) {
  126. this.color = new SColor(data.Properties.color);
  127. }
  128. if (data.Properties && data.Properties.IsActive) {
  129. this.isActive = data.Properties.IsActive;
  130. }
  131. if (data.AttachObjectIds && data.AttachObjectIds.length) {
  132. this.isActive = true;
  133. }
  134. if (data.Properties && data.Properties.FrameColor) {
  135. this.activeColor = new SColor(data.Properties.FrameColor);
  136. }
  137. }
  138. /**
  139. * 鼠标按下事件
  140. *
  141. * @param event 保存事件参数
  142. * @return boolean
  143. */
  144. onMouseDown(event: SMouseEvent): boolean {
  145. if (event.buttons == 1)
  146. this.$emit("legendItemClick", event);
  147. return super.onMouseDown(event);
  148. } // Function onMouseDown()
  149. toData(): Legend {
  150. this.data.Pos = { X: this.x, Y: this.y };
  151. this.data.Size = { Width: this.width, Height: this.height };
  152. this.data.Name = this.name;
  153. this.data.Properties.Zorder = this.zOrder;
  154. this.data.Properties.Url = this.img.url;
  155. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  156. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  157. this.data.Properties.ImgRotate = this.img.rotate;
  158. this.data.Properties.Size = {
  159. Width: this.sWidth,
  160. Height: this.sHeight
  161. };
  162. this.data.Properties.font = this.font.size;
  163. this.data.Properties.color = this.color.value;
  164. this.data.Properties.Font = this.font.size;
  165. this.data.Properties.Coler = this.color.value;
  166. this.data.Properties.FrameColor = this.activeColor.value;
  167. this.data.Properties.IsActive = this.isActive;
  168. this.data.AnchorList = this.anchorList.map(t => {
  169. return {
  170. ID: t.id,
  171. Pos: {
  172. X: t.x,
  173. Y: t.y
  174. }
  175. }
  176. })
  177. return this.data;
  178. }
  179. /**
  180. * Item绘制框架
  181. *
  182. * @param painter painter对象
  183. * @param rect 绘制区域
  184. */
  185. onPaint(painter: SPainter, rect: SRect): void {
  186. super.onPaint(painter, rect);
  187. if (this.maskFlag && this.status == SItemStatus.Normal) {
  188. painter.pen.color = SColor.Transparent;
  189. painter.brush.color = new SColor("#ffffffa1");
  190. if (this.selected) {
  191. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0) * 1.25);
  192. } else {
  193. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  194. }
  195. }
  196. } // Function onPaint()
  197. } // Class SImageLegendItem