SImageLegendItem.ts 4.9 KB

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