Browse Source

版本升级;增加适配item列表至屏幕中心

haojianlong 5 years ago
parent
commit
4686c69404
2 changed files with 25 additions and 1 deletions
  1. 1 1
      saga-web-graphy/package.json
  2. 24 0
      saga-web-graphy/src/SGraphyView.ts

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graphy",
-    "version": "2.1.40",
+    "version": "2.1.42",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 24 - 0
saga-web-graphy/src/SGraphyView.ts

@@ -7,6 +7,7 @@ import {
     SSvgPaintEngine
 } from "@saga-web/draw/lib";
 import { SGraphyScene } from "./SGraphyScene";
+import { SGraphyItem } from "../lib";
 
 /**
  * Graphy图形引擎视图类
@@ -113,6 +114,29 @@ export class SGraphyView extends SCanvasView {
     } // Function fitSelectedToSize()
 
     /**
+     * 适配任意对象在视图中可见
+     */
+    fitItemToView(itemList: SGraphyItem[]): void {
+        if (null == this.scene) {
+            return;
+        }
+        let rect: SRect | null = null;
+
+        // 依次取item列中的所有item。将所有item的边界做并焦处理。
+        for (let item of itemList) {
+            if (rect == null) {
+                rect = item.boundingRect().translated(item.pos.x, item.pos.y);
+            } else {
+                rect.union(
+                    item.boundingRect().translated(item.pos.x, item.pos.y)
+                );
+            }
+        }
+        // 场景中无对象
+        this.fitRectToSize(this.width, this.height, rect);
+    } // Function fitItemToView()
+
+    /**
      * 将场景中的xy坐标转换成视图坐标。
      *
      * @param   x       场景中的横坐标