SImageLegendItem.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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);
  39. this.zOrder = ItemOrder.markOrder;
  40. this.data = data;
  41. this.id = data.ID;
  42. this.name = data.Name;
  43. this.moveTo(data.Pos.X, data.Pos.Y);
  44. if (data.Num) {
  45. this._num = data.Num;
  46. }
  47. if (data.Size) {
  48. this.width = data.Size.Width;
  49. this.height = data.Size.Height;
  50. }
  51. if (data.Num) {
  52. this.text = `${data.Name}${data.Num > 1?` × ${data.Num}`:''}`;
  53. }
  54. if (data.Properties && data.Properties.Url) {
  55. this.img.url = data.Properties.Url;
  56. }
  57. if (data.Properties && data.Properties.sWidth) {
  58. this.sWidth = data.Properties.sWidth;
  59. }
  60. if (data.Properties && data.Properties.sHeight) {
  61. this.sHeight = data.Properties.sHeight;
  62. }
  63. if (data.Properties && data.Properties.font) {
  64. this.font = new SFont("sans-serif", data.Properties.font);
  65. }
  66. if (data.Properties && data.Properties.color) {
  67. this.color = new SColor(data.Properties.color);
  68. }
  69. if (data.Properties.ImgPos) {
  70. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  71. }
  72. if (data.Properties.TextPos) {
  73. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  74. }
  75. }
  76. toData(): Legend {
  77. this.data.Pos = {X: this.x, Y: this.y};
  78. this.data.Size = {Width: this.width, Height: this.height};
  79. this.data.Name = this.name;
  80. this.data.Properties.Url = this.img.url;
  81. this.data.Properties.TextPos = {X: this.textItem.x, Y: this.textItem.y};
  82. this.data.Properties.ImgPos = {X: this.img.x, Y: this.img.y};
  83. this.data.Properties.sWidth = this.sWidth;
  84. this.data.Properties.sHeight = this.sHeight;
  85. this.data.Properties.font = this.font.size;
  86. this.data.Properties.color = this.color.value;
  87. return this.data;
  88. }
  89. } // Class SImageLegendItem