import { SGraphItem } from "@saga-web/graph/lib"; import { SIconTextItem } from '@saga-web/big/lib/items/SIconTextItem'; import { Legend } from '../types/Legend'; /** * 图例节点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(); } set name(v: string) { this.data.Name = v; } set x(v: number) { this.data.Pos.X = v; } set y(v: number) { this.data.Pos.Y = v; } set width(v: number) { if (this.data.Size) { this.data.Size.Width = v; } } set height(v: number) { if (this.data.Size) { this.data.Size.Height = v; } } /** * 构造函数 * * @param parent 指向父对象 * @param data 图例节点对象数据 */ constructor(parent: SGraphItem | null, data: Legend) { super(parent); this.data = data; this.id = data.ID; 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) { if (data.Properties.Text instanceof String) { this.text = `${data.Properties.Text}${data.Num?` × ${data.Num}`:''}`; } } if (data.Properties && data.Properties.Url) { if (data.Properties.Url instanceof String) { this.img.url = data.Properties.Url; } } } } // Class SImageLegendItem