SImageLegendItem.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 } from '@saga-web/big/lib';
  5. import { SFont, SColor } 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. * 构造函数
  33. *
  34. * @param parent 指向父对象
  35. * @param data 图例节点对象数据
  36. */
  37. constructor(parent: SGraphItem | null, data: Legend) {
  38. super(parent, data.AnchorList);
  39. this.isTransform = false;
  40. this.zOrder = ItemOrder.markOrder;
  41. this.data = data;
  42. this.id = data.ID;
  43. this.name = data.Name;
  44. this.moveTo(data.Pos.X, data.Pos.Y);
  45. if (data.Num) {
  46. this._num = data.Num;
  47. }
  48. if (data.Size) {
  49. this.width = data.Size.Width;
  50. this.height = data.Size.Height;
  51. }
  52. if (data.Num) {
  53. this.text = `${data.Name}${data.Num > 1 ? ` × ${data.Num}` : ''}`;
  54. }
  55. if (data.Properties && data.Properties.Url) {
  56. this.img.url = data.Properties.Url;
  57. }
  58. if (data.Properties.ImgPos) {
  59. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  60. }
  61. if (data.Properties.TextPos) {
  62. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  63. }
  64. if (data.Properties && data.Properties.sWidth) {
  65. this.sWidth = data.Properties.sWidth;
  66. }
  67. if (data.Properties && data.Properties.sHeight) {
  68. this.sHeight = data.Properties.sHeight;
  69. }
  70. if (data.Properties && data.Properties.font) {
  71. this.font = new SFont("sans-serif", data.Properties.font);
  72. }
  73. if (data.Properties && data.Properties.color) {
  74. this.color = new SColor(data.Properties.color);
  75. }
  76. if (data.Properties && data.Properties.IsActive) {
  77. this.isActive = data.Properties.IsActive;
  78. }
  79. if (data.Properties && data.Properties.FrameColor) {
  80. this.activeColor = new SColor(data.Properties.FrameColor);
  81. }
  82. }
  83. toData(): Legend {
  84. this.data.Pos = { X: this.x, Y: this.y };
  85. this.data.Size = { Width: this.width, Height: this.height };
  86. this.data.Name = this.name;
  87. this.data.Properties.Url = this.img.url;
  88. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  89. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  90. this.data.Properties.sWidth = this.sWidth;
  91. this.data.Properties.sHeight = this.sHeight;
  92. this.data.Properties.font = this.font.size;
  93. this.data.Properties.color = this.color.value;
  94. this.data.Properties.FrameColor = this.activeColor.value;
  95. this.data.Properties.IsActive = this.isActive;
  96. this.data.AnchorList = this.anchorList.map(t => {
  97. return {
  98. ID: t.id,
  99. Pos: {
  100. X: t.x,
  101. Y: t.y
  102. }
  103. }
  104. })
  105. return this.data;
  106. }
  107. } // Class SImageLegendItem