From 167750bb99629f2e0453eece5b276ddd1bd4096a Mon Sep 17 00:00:00 2001 From: zhandouxiaojiji Date: Tue, 27 Oct 2020 11:28:51 +0800 Subject: [PATCH] add animate --- render-process/Editor/index.tsx | 14 +++++++++++++- render-process/index.tsx | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index 920ee76..2dacd52 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -42,7 +42,7 @@ export default class Editor extends React.Component { container: this.ref.current, width: window.screen.width * 0.66, height: window.screen.height, - animate: false, + animate: true, // fitCenter: true, modes: { default: [ @@ -56,6 +56,7 @@ export default class Editor extends React.Component { onChange: (item, collapsed) => { const data = item.getModel(); data.collapsed = collapsed; + this.onSelectNode(item.getID()); return true; }, }, @@ -112,6 +113,14 @@ export default class Editor extends React.Component { } }); + graph.on('node:click', (e: G6GraphEvent) => { + if (e.target.get('name') === 'collapse-icon') { + e.item.getModel().collapsed = !e.item.getModel().collapsed; + graph.setItemState(e.item, 'collapsed', e.item.getModel().collapsed as boolean); + graph.layout(); + } + }); + const clearDragDstState = () => { if (this.dragDstId) { graph.setItemState(this.dragDstId, 'dragRight', false); @@ -237,8 +246,10 @@ export default class Editor extends React.Component { } // console.log("cur data", graph.findDataById('1')); + graph.set('animate', false); graph.changeData(); graph.layout(); + graph.set('animate', true); }); const str = fs.readFileSync(this.props.filepath, 'utf8'); @@ -255,6 +266,7 @@ export default class Editor extends React.Component { const graph = this.graph; if (this.state.curNodeId) { + console.log("unselect", this.state.curNodeId); graph.setItemState(this.state.curNodeId, 'selected', false); } diff --git a/render-process/index.tsx b/render-process/index.tsx index 4e34d96..7e59a05 100644 --- a/render-process/index.tsx +++ b/render-process/index.tsx @@ -86,7 +86,7 @@ export default class Main extends Component { 'drag-down': { fillOpacity: 0.6, } - }, + } }, }, draw(cfg, group) { @@ -298,7 +298,7 @@ export default class Main extends Component { // visible: false, }); return shape; - }, + } }, 'single-node', );