Ver código fonte

修改图例节点图例类型和线类型派生item

zhangyu 4 anos atrás
pai
commit
8d0ba351d0

+ 12 - 30
src/lib/items/SImageLegendItem.ts

@@ -22,30 +22,6 @@ export class SImageLegendItem extends SIconTextItem {
         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;
-        }
-    }
-
     /**
      * 构造函数
      *
@@ -56,6 +32,7 @@ export class SImageLegendItem extends SIconTextItem {
         super(parent);
         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;
@@ -65,14 +42,19 @@ export class SImageLegendItem extends SIconTextItem {
             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}`:''}`;
-            }
+            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;
-            }
+            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

+ 25 - 81
src/lib/items/SLineLegendItem.ts

@@ -13,75 +13,6 @@ export class SLineLegendItem extends SPolylineItem {
     /** 图例节点对象数据 */
     data: Legend;
 
-    /** x轴缩放属性 */
-    // _scaleX: number = 1;
-    // get scaleX(): number {
-    //     return this._scaleX;
-    // }
-    // set scaleX(v: number) {
-    //     this._scaleX = v;
-    //     if (this.data.Scale) {
-    //         this.data.Scale.X = v;
-    //     }
-    //     this.update();
-    // }
-
-    /** y轴缩放属性 */
-    // _scaleY: number = 1;
-    // get scaleY(): number {
-    //     return this._scaleY;
-    // }
-    // set scaleY(v: number) {
-    //     this._scaleY = v;
-    //     if (this.data.Scale) {
-    //         this.data.Scale.Y = v;
-    //     }
-    //     this.update();
-    // }
-
-    /** y轴旋转属性 */
-    // _rolate: number = 0;
-    // get rolate(): number {
-    //     return this._rolate;
-    // }
-    // set rolate(v: number) {
-    //     this._rolate = v;
-    //     if (this.data.Rolate) {
-    //         this.data.Rolate.Z = v;
-    //     }
-    //     this.update();
-    // }
-
-    set name(v: string) {
-        this.data.Name = v;
-    }
-
-    set line(arr: SPoint[]) {
-        if (this.data.Properties) {
-            this.data.Properties.Line = arr;
-        }
-    }
-
-    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;
-        }
-    }
-
     /**
      * 构造函数
      *
@@ -92,20 +23,33 @@ export class SLineLegendItem extends SPolylineItem {
         super(parent,[]);
         this.data = data;
         this.id = data.ID;
+        this.name = data.Name;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        // if (data.Scale) {
-        //     this.scaleX = data.Scale.X;
-        //     this.scaleY = data.Scale.Y;
-        // }
-        // if (data.Rolate && this.data.Rolate.Z) {
-        //     this.rolate = data.Rolate.Z;
-        // }
-        if (data.Size) {
-            this.width = data.Size.Width;
-            this.height = data.Size.Height;
-        }
         if (data.Properties && data.Properties.Line) {
-            this.line = data.Properties.Line;
+            let setPointList: SPoint[];
+            setPointList = data.Properties.Line.map(i => {
+                return new SPoint(i.x, i.y)
+            })
+            this.pointList = setPointList;
+        }
+        if (data.Properties && data.Properties.LineWidth) {
+            this.lineWidth = data.Properties.LineWidth;
+        }
+        if (data.Properties && data.Properties.StrokeColor) {
+            this.strokeColor = data.Properties.StrokeColor;
         }
     }
+
+    toData(): Legend {
+        this.data.Pos = {X: this.x, Y: this.y};
+        this.data.Properties.Line = this.pointList.map(pos => {
+            return {
+                X: pos.x,
+                Y: pos.y
+            }
+        });
+        this.data.Properties.LineWidth = this.lineWidth;
+        this.data.Properties.StrokeColor = this.strokeColor;
+        return this.data;
+    }
 } // Class SLineLegendItem

+ 4 - 0
src/lib/items/SNoneLegendItem.ts

@@ -21,4 +21,8 @@ export class SNoneLegendItem extends SGraphItem {
         this.data = data;
         this.id = data.ID;
     }
+
+    toData(): Legend {
+        return this.data;
+    }
 } // Class SNoneLegendItem