|
@@ -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 场景中的横坐标
|