瀏覽代碼

Associated with #6012

David Catuhe 6 年之前
父節點
當前提交
3f647aed82
共有 2 個文件被更改,包括 19 次插入5 次删除
  1. 0 2
      nodeEditor/src/components/propertyTab/propertyTabComponent.tsx
  2. 19 3
      nodeEditor/src/graphEditor.tsx

+ 0 - 2
nodeEditor/src/components/propertyTab/propertyTabComponent.tsx

@@ -63,8 +63,6 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
                     </div>
                 </div>
                 <div>
-                    <LineContainerComponent title="PROPERTIES">
-                    </LineContainerComponent>
                     <LineContainerComponent title="GENERAL">
                         <ButtonLineComponent label="Reset to default" onClick={() => {
                             this.props.globalState.nodeMaterial!.setToDefault();

+ 19 - 3
nodeEditor/src/graphEditor.tsx

@@ -162,9 +162,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
         });
 
         this.props.globalState.onZoomToFitRequiredObservable.add(() => {
-            setTimeout(() => {
-                this._engine.zoomToFit();
-            });
+            this.zoomToFit();
         });
 
         this.props.globalState.onReOrganizedRequiredObservable.add(() => {
@@ -174,6 +172,24 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
         this.build(true);
     }
 
+    zoomToFit(retry = 0) {
+        const xFactor = this._engine.canvas.clientWidth / this._engine.canvas.scrollWidth;
+        const yFactor = this._engine.canvas.clientHeight / this._engine.canvas.scrollHeight;
+        const zoomFactor = xFactor < yFactor ? xFactor : yFactor;
+
+        if (zoomFactor === 1) {
+            return;
+        }
+
+        this._engine.diagramModel.setZoomLevel(this._engine.diagramModel.getZoomLevel() * zoomFactor);
+        this._engine.diagramModel.setOffset(0, 0);
+        this._engine.repaintCanvas();
+        retry++;
+        if (retry < 4) {
+            setTimeout(() => this.zoomToFit(retry), 1);
+        }
+    }
+
     distributeGraph() {
         let nodes = this.mapElements();
         let edges = this.mapEdges();