Browse Source

graph:feat:数据存储功能添加

haojianlong 4 years ago
parent
commit
b985661f89
2 changed files with 25 additions and 1 deletions
  1. 1 1
      persagy-web-graph/package.json
  2. 24 0
      persagy-web-graph/src/SGraphItem.ts

+ 1 - 1
persagy-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/graph",
-    "version": "2.2.24",
+    "version": "2.2.25",
     "description": "博锐尚格二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 24 - 0
persagy-web-graph/src/SGraphItem.ts

@@ -201,6 +201,17 @@ export class SGraphItem extends SObject {
     /** 保存上一次的 grabItem */
     private _lastGrab: SGraphItem | null = null;
 
+    /** 外层自定义数据 */
+    private _data: any | null = null;
+    set data(d: any) {
+        this._data = d;
+        this.initData();
+        this.update();
+    }
+    get data(): any | null {
+        return this._data;
+    }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 函数
     /**
@@ -457,6 +468,7 @@ export class SGraphItem extends SObject {
                 console.log(e);
             }
         }
+        this.$emit("onMouseDown", event);
         // 移动
         if (this.moveable) {
             this._mouseDownPos = new SPoint(event.x, event.y);
@@ -488,6 +500,7 @@ export class SGraphItem extends SObject {
                 return true;
             }
         }
+        this.$emit("onMouseMove", event);
         if (this.scene && this.scene.view) {
             this.scene.view.cursor = this.cursor;
         }
@@ -546,6 +559,7 @@ export class SGraphItem extends SObject {
             select = this.clickSelect(event);
         }
 
+        this.$emit("onMouseUp", event);
         this._isMoving = false;
         this.releaseItem();
         if (this.scene) {
@@ -561,6 +575,7 @@ export class SGraphItem extends SObject {
      * @return 是否处理事件
      */
     onMouseEnter(event: SMouseEvent): boolean {
+        this.$emit("onMouseEnter", event);
         return false;
     }
 
@@ -571,6 +586,7 @@ export class SGraphItem extends SObject {
      * @return 是否处理事件
      */
     onMouseLeave(event: SMouseEvent): boolean {
+        this.$emit("onMouseLeave", event);
         return false;
     }
 
@@ -592,6 +608,7 @@ export class SGraphItem extends SObject {
                 return true;
             }
         }
+        this.$emit("onContextMenu", event);
         return false;
     }
 
@@ -631,6 +648,13 @@ export class SGraphItem extends SObject {
     }
 
     /**
+     * 初始化数据
+     */
+    initData(): void {
+        // do nothing
+    }
+
+    /**
      * 移动 item 后的处理,计算其他信息,将原点置为场景原点
      *
      * @param x   x 坐标