瀏覽代碼

基本选择器添加;选择器抛出事件

haojianlong 4 年之前
父節點
當前提交
c2a072ec40

+ 2 - 2
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.12",
+    "version": "1.0.15",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.59"
+        "@saga-web/graph": "2.1.63"
     }
 }

+ 1 - 1
saga-web-draw/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/draw",
-    "version": "2.1.83",
+    "version": "2.1.84",
     "description": "上格云绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 2 - 2
saga-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.60",
+    "version": "2.1.63",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -41,6 +41,6 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "2.1.83"
+        "@saga-web/draw": "2.1.84"
     }
 }

+ 0 - 2
saga-web-graph/src/SGraphItem.ts

@@ -591,7 +591,5 @@ export class SGraphItem extends SObject {
         } else {
             scene.selectContainer.setItem(this);
         }
-
-        this.selected = true;
     } // Function clickSelect()
 } // Class SGraphItem

+ 14 - 14
saga-web-graph/src/SGraphScene.ts

@@ -139,20 +139,20 @@ export class SGraphScene {
 
     // =================================================================================================================
     // 事件
-    /**
-     * 鼠标单击事件
-     *
-     * @param   event   保存事件参数
-     * @return  boolean
-     */
-    onClick(event: SMouseEvent): boolean {
-        if (this.grabItem != null) {
-            return this.grabItem.onClick(
-                SGraphScene.toGrabItemMotionEvent(this.grabItem, event)
-            );
-        }
-        return this.root.onClick(event);
-    } // Function onClick()
+    // /**
+    //  * 鼠标单击事件
+    //  *
+    //  * @param   event   保存事件参数
+    //  * @return  boolean
+    //  */
+    // onClick(event: SMouseEvent): boolean {
+    //     if (this.grabItem != null) {
+    //         return this.grabItem.onClick(
+    //             SGraphScene.toGrabItemMotionEvent(this.grabItem, event)
+    //         );
+    //     }
+    //     return this.root.onClick(event);
+    // } // Function onClick()
 
     /**
      * 鼠标双击事件

+ 26 - 23
saga-web-graph/src/SGraphSelectContainer.ts

@@ -1,19 +1,19 @@
 import { SGraphItem } from "./SGraphItem";
+import { SObject } from "@saga-web/base/lib";
+import { SGraphLayoutType } from "./enums/SGraphLayoutType";
 
 /**
  * 基本选择器
  *
  * @author  郝建龙
  */
-export class SGraphSelectContainer {
+export class SGraphSelectContainer extends SObject {
     /** 选择对象list    */
     private itemList: SGraphItem[] = [];
-
-    /**
-     * 构造函数
-     *
-     * */
-    constructor() {} // Constructor
+    /** 统计选中item的数量 */
+    get count(): number {
+        return this.itemList.length;
+    }
 
     /**
      * 添加item到list
@@ -21,13 +21,14 @@ export class SGraphSelectContainer {
      * @param   item    当前选中的item
      * */
     addItem(item: SGraphItem): void {
-        for (let i = 0; i < this.itemList.length - 1; i++) {
+        for (let i = 0; i < this.itemList.length; i++) {
             if (this.itemList[i] == item) {
                 return;
             }
         }
         item.selected = true;
         this.itemList.push(item);
+        this.$emit("listChange", this.itemList);
     } // Function addItem()
 
     /**
@@ -36,12 +37,10 @@ export class SGraphSelectContainer {
      * @param   item    当前选中的item
      * */
     setItem(item: SGraphItem): void {
-        for (let i = 0; i < this.itemList.length - 1; i++) {
-            item.selected = false;
-        }
-        this.itemList.length = 0;
+        this.clear();
         item.selected = true;
         this.itemList.push(item);
+        this.$emit("listChange", this.itemList);
     } // Function setItem()
 
     /**
@@ -53,6 +52,7 @@ export class SGraphSelectContainer {
             t.selected = false;
         });
         this.itemList.length = 0;
+        this.$emit("listChange", this.itemList);
     } // Function clear()
 
     /**
@@ -61,19 +61,22 @@ export class SGraphSelectContainer {
      * @param   item    当前选中的item
      * */
     toggleItem(item: SGraphItem): void {
-        let index = -1;
-        for (let i = 0; i < this.itemList.length - 1; i++) {
+        for (let i = 0; i < this.itemList.length; i++) {
             if (this.itemList[i] == item) {
-                index = i;
-                item.selected = false;
-                break;
+                this.itemList[i].selected = false;
+                this.itemList.splice(i, 1);
+                return;
             }
         }
-        if (index > -1) {
-            this.itemList.splice(index, 1);
-        } else {
-            item.selected = true;
-            this.itemList.push(item);
-        }
+        item.selected = true;
+        this.itemList.push(item);
+        this.$emit("listChange", this.itemList);
     } // Function toggleItem()
+
+    /**
+     * 对齐
+     *
+     * @param   type    对齐方式
+     * */
+    layout(type: SGraphLayoutType): void {} // Function clear()
 } // Class SGraphSelectContainer

+ 12 - 11
saga-web-graph/src/SGraphView.ts

@@ -28,6 +28,7 @@ export class SGraphView extends SCanvasView {
         if (this._scene != null) {
             this._scene.view = this;
         }
+        this.update();
     } // Set scene
 
     /**
@@ -265,17 +266,17 @@ export class SGraphView extends SCanvasView {
         // DO NOTHING
     } // Function drawForeground()
 
-    /**
-     * 鼠标单击事件
-     *
-     * @param   event       事件参数
-     */
-    protected onClick(event: MouseEvent): void {
-        if (this.scene != null) {
-            let ce = this.toSceneMotionEvent(event);
-            this.scene.onClick(ce);
-        }
-    } // Function onClick()
+    // /**
+    //  * 鼠标单击事件
+    //  *
+    //  * @param   event       事件参数
+    //  */
+    // protected onClick(event: MouseEvent): void {
+    //     if (this.scene != null) {
+    //         let ce = this.toSceneMotionEvent(event);
+    //         this.scene.onClick(ce);
+    //     }
+    // } // Function onClick()
 
     /**
      * 鼠标双击事件

+ 23 - 0
saga-web-graph/src/enums/SGraphLayoutType.ts

@@ -0,0 +1,23 @@
+/**
+ * 布局对齐方式
+ *
+ * @author  郝建龙
+ */
+export enum SGraphLayoutType {
+    /** 垂直分布    */
+    Vertical,
+    /** 垂直分布    */
+    Horizontal,
+    /** 左对齐 */
+    Left,
+    /** 右对齐 */
+    Right,
+    /** 顶对齐 */
+    Top,
+    /** 底对齐 */
+    Bottom,
+    /** 水平居中    */
+    center,
+    /** 垂直居中    */
+    middle
+} // Enum SGraphLayoutType

+ 8 - 1
saga-web-graph/src/index.ts

@@ -31,5 +31,12 @@ import { SGraphItem } from "./SGraphItem";
 import { SGraphScene } from "./SGraphScene";
 import { SGraphView } from "./SGraphView";
 import { SGraphSelectContainer } from "./SGraphSelectContainer";
+import { SGraphLayoutType } from "./enums/SGraphLayoutType";
 
-export { SGraphItem, SGraphScene, SGraphView, SGraphSelectContainer };
+export {
+    SGraphItem,
+    SGraphScene,
+    SGraphView,
+    SGraphSelectContainer,
+    SGraphLayoutType
+};

+ 2 - 2
saga-web-graphy/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graphy",
-    "version": "2.1.58",
+    "version": "2.1.59",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -41,6 +41,6 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "2.1.81"
+        "@saga-web/draw": "2.1.84"
     }
 }