Skip to content

Commit

Permalink
Merge pull request zhandouxiaojiji#13 from 91Act/pull_request1
Browse files Browse the repository at this point in the history
保存、撤销、恢复执行后视图保持不变
  • Loading branch information
zhandouxiaojiji authored Sep 22, 2022
2 parents 1df5042 + 36e1a5c commit 194720a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions render-process/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Settings from "../../main-process/Settings";

import "./Editor.css";
import { clipboard } from "electron";
import { Matrix } from '@antv/g6/lib/types';

export interface EditorProps {
filepath: string;
Expand All @@ -25,6 +26,7 @@ export interface EditorProps {
interface EditorState {
curNodeId?: string;
blockNodeSelectChange?: boolean;
viewportMatrix?: Matrix
}

export default class Editor extends React.Component<EditorProps, EditorState> {
Expand Down Expand Up @@ -115,6 +117,12 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
},
});

graph.on("viewportchange", (data: any) => {
if (data.action == 'translate' || data.action == 'zoom') {
this.state.viewportMatrix = data.matrix
}
})

graph.on("contextmenu", (e: G6GraphEvent) => {
require("@electron/remote").Menu.getApplicationMenu().popup();
});
Expand Down Expand Up @@ -287,6 +295,15 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.forceUpdate();
}

/**
* remember the last matrix that triggered by Translate or Zoom action , and restore that matrix where the graph is reconstruct.
*/
restoreViewport() {
if (this.state.viewportMatrix) {
this.graph.getGroup().setMatrix(this.state.viewportMatrix);
}
}

onSelectNode(curNodeId: string | null) {
const graph = this.graph;

Expand Down Expand Up @@ -373,7 +390,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.graph.set("animate", false);
this.graph.changeData(Utils.createTreeData(root, this.settings));
this.graph.layout();
this.graph.fitCenter();
this.restoreViewport();
this.graph.set("animate", true);
}

Expand Down Expand Up @@ -431,7 +448,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.graph.set("animate", false);
this.graph.changeData(Utils.createTreeData(data, this.settings));
this.graph.layout();
this.graph.fitCenter();
this.restoreViewport();
this.graph.set("animate", true);

this.props.onChangeSaveState(true);
Expand Down

0 comments on commit 194720a

Please sign in to comment.