SImageLegendItem.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /**
  6. * 图例节点Item(图标类型)
  7. *
  8. * * @author 张宇(taohuzy@163.com)
  9. */
  10. export class SImageLegendItem extends SIconTextItem {
  11. /** 图例节点对象数据 */
  12. data: Legend;
  13. /** 图例数量 */
  14. _num: number = 0;
  15. get num(): number {
  16. return this._num;
  17. }
  18. set num(v: number) {
  19. this._num = v;
  20. this.data.Num = v;
  21. this.update();
  22. }
  23. /**
  24. * 构造函数
  25. *
  26. * @param parent 指向父对象
  27. * @param data 图例节点对象数据
  28. */
  29. constructor(parent: SGraphItem | null, data: Legend) {
  30. super(parent);
  31. this.zOrder = ItemOrder.markOrder;
  32. this.data = data;
  33. this.id = data.ID;
  34. this.name = data.Name;
  35. this.moveTo(data.Pos.X, data.Pos.Y);
  36. if (data.Num) {
  37. this._num = data.Num;
  38. }
  39. if (data.Size) {
  40. this.width = data.Size.Width;
  41. this.height = data.Size.Height;
  42. }
  43. if (data.Properties && data.Properties.Text) {
  44. this.text = `${data.Properties.Text}${data.Num?` × ${data.Num}`:''}`;
  45. }
  46. if (data.Properties && data.Properties.Url) {
  47. this.img.url = data.Properties.Url;
  48. }
  49. }
  50. toData(): Legend {
  51. this.data.Pos = {X: this.x, Y: this.y};
  52. this.data.Size = {Width: this.width, Height: this.height};
  53. this.data.Num = this.num;
  54. this.data.Properties.Text = this.text;
  55. this.data.Properties.Url = this.img.url;
  56. return this.data;
  57. }
  58. } // Class SImageLegendItem