SImageLegendItem.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /**
  7. * 图例节点Item(图标类型)
  8. *
  9. * * @author 张宇(taohuzy@163.com)
  10. */
  11. export class SImageLegendItem extends SIconTextItem {
  12. /** 图例节点对象数据 */
  13. data: Legend
  14. /** 图例数量 */
  15. _num: number = 1
  16. get num(): number {
  17. return this._num
  18. }
  19. set num(v: number) {
  20. if (v) {
  21. this._num = v
  22. this.data.Num = v
  23. } else {
  24. this._num = 1
  25. this.data.Num = 1
  26. }
  27. this.data.Properties.Num = this._num
  28. this.text = `${this.data.Name}${this.data.Num > 1 ? ` × ${this.data.Num}` : ''}`
  29. this.update()
  30. }
  31. /** 是否蒙版遮罩 */
  32. _maskFlag: boolean = false;
  33. get maskFlag(): boolean {
  34. return this._maskFlag;
  35. }
  36. set maskFlag(v: boolean) {
  37. if (v === this._maskFlag) {
  38. return
  39. }
  40. this._maskFlag = v;
  41. this.update()
  42. }
  43. /**
  44. * 构造函数
  45. *
  46. * @param parent 指向父对象
  47. * @param data 图例节点对象数据
  48. */
  49. constructor(parent: SGraphItem | null, data: Legend) {
  50. super(parent, data.AnchorList)
  51. this.isTransform = false
  52. this.zOrder = ItemOrder.markOrder
  53. this.data = data
  54. this.id = data.ID
  55. this.name = data.Name
  56. this.moveTo(data.Pos.X, data.Pos.Y)
  57. if (data.Num) {
  58. this._num = data.Num
  59. }
  60. if (data.Size) {
  61. this.width = data.Size.Width
  62. this.height = data.Size.Height
  63. }
  64. if (data.Num) {
  65. this.text = `${data.Name}${data.Num > 1 ? ` × ${data.Num}` : ''}`
  66. }
  67. if (data.Properties && data.Properties.Url) {
  68. this.img.url = data.Properties.Url
  69. }
  70. if (data.Properties.ImgPos) {
  71. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y)
  72. }
  73. if (data.Properties.TextPos) {
  74. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y)
  75. }
  76. if (data.Properties && data.Properties.sWidth) {
  77. this.sWidth = data.Properties.sWidth
  78. }
  79. if (data.Properties && data.Properties.sHeight) {
  80. this.sHeight = data.Properties.sHeight
  81. }
  82. if (data.Properties && data.Properties.font) {
  83. this.font = new SFont('sans-serif', data.Properties.font)
  84. }
  85. if (data.Properties && data.Properties.color) {
  86. this.color = new SColor(data.Properties.color)
  87. }
  88. if (data.Properties && data.Properties.IsActive) {
  89. this.isActive = data.Properties.IsActive
  90. }
  91. if (data.AttachObjectIds && data.AttachObjectIds.length) {
  92. this.isActive = true
  93. }
  94. if (data.Properties && data.Properties.FrameColor) {
  95. this.activeColor = new SColor(data.Properties.FrameColor)
  96. }
  97. }
  98. toData(): Legend {
  99. this.data.Pos = { X: this.x, Y: this.y }
  100. this.data.Size = { Width: this.width, Height: this.height }
  101. this.data.Name = this.name
  102. this.data.Properties.Url = this.img.url
  103. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y }
  104. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y }
  105. this.data.Properties.sWidth = this.sWidth
  106. this.data.Properties.sHeight = this.sHeight
  107. this.data.Properties.font = this.font.size
  108. this.data.Properties.color = this.color.value
  109. this.data.Properties.FrameColor = this.activeColor.value
  110. this.data.Properties.IsActive = this.isActive
  111. this.data.AnchorList = this.anchorList.map((t) => {
  112. return {
  113. ID: t.id,
  114. Pos: {
  115. X: t.x,
  116. Y: t.y,
  117. },
  118. }
  119. })
  120. return this.data
  121. }
  122. /**
  123. * Item绘制框架
  124. *
  125. * @param painter painter对象
  126. * @param rect 绘制区域
  127. */
  128. onPaint(painter: SPainter, rect: SRect): void {
  129. super.onPaint(painter, rect);
  130. if (this.maskFlag && this.status == SItemStatus.Normal) {
  131. painter.pen.color = SColor.Transparent;
  132. painter.brush.color = new SColor("#ffffffa1");
  133. if (this.selected) {
  134. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0) * 1.25);
  135. } else {
  136. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  137. }
  138. }
  139. } // Function onPaint()
  140. } // Class SImageLegendItem