import { SGraphItem } from "@saga-web/graph/lib"; import { SIconTextItem } from '@saga-web/big/lib/items/SIconTextItem'; import { Legend } from '../types/Legend'; import { ItemOrder } from '@saga-web/big/lib'; /** * 图例节点Item(图标类型) * * * @author 张宇(taohuzy@163.com) */ export class SImageLegendItem extends SIconTextItem { /** 图例节点对象数据 */ data: Legend; /** 图例数量 */ _num: number = 0; get num(): number { return this._num; } set num(v: number) { this._num = v; this.data.Num = v; this.update(); } /** * 构造函数 * * @param parent 指向父对象 * @param data 图例节点对象数据 */ constructor(parent: SGraphItem | null, data: Legend) { super(parent); this.zOrder = ItemOrder.markOrder; this.data = data; this.id = data.ID; this.name = data.Name; this.moveTo(data.Pos.X, data.Pos.Y); if (data.Num) { this._num = data.Num; } if (data.Size) { this.width = data.Size.Width; this.height = data.Size.Height; } if (data.Properties && data.Properties.Text) { this.text = `${data.Properties.Text}${data.Num?` × ${data.Num}`:''}`; } if (data.Properties && data.Properties.Url) { this.img.url = data.Properties.Url; } } toData(): Legend { this.data.Pos = {X: this.x, Y: this.y}; this.data.Size = {Width: this.width, Height: this.height}; this.data.Num = this.num; this.data.Properties.Text = this.text; this.data.Properties.Url = this.img.url; return this.data; } } // Class SImageLegendItem