drag and focusItem

This commit is contained in:
zhandouxiaojiji committed 2020-10-21 20:04:24 +08:00
1 parent 99d1a4570e
commit 683eea771a
1 file changed
+26 -12
+26 -12
View File
@@ -39,8 +39,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
width: window.screen.width * 0.66, width: window.screen.width * 0.66,
height: window.screen.height, height: window.screen.height,
animate: false, animate: false,
fitView: true, // fitCenter: true,
fitViewPadding: [20, 20, 20, 20],
modes: { modes: {
default: [ default: [
'drag-canvas', 'drag-canvas',
@@ -86,14 +85,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
}); });
graph.on('nodeselectchange', (e: G6GraphEvent) => { graph.on('nodeselectchange', (e: G6GraphEvent) => {
if (this.state.curNode) { this.onSelectNode(e.target as INode)
graph.setItemState(this.state.curNode, 'selected', false);
}
const curNode = e.target as INode;
this.setState({ curNode });
if (this.state.curNode) {
graph.setItemState(this.state.curNode, 'selected', true);
}
}); });
const clearDragDstState = () => { const clearDragDstState = () => {
@@ -194,9 +186,10 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
return; return;
} }
Utils.refreshNodeId(graph.findDataById('1')); const zoom = graph.getZoom();
graph.changeData(rootData); graph.changeData(rootData);
// graph.layout() graph.focusItem(srcData.id);
this.onSelectNode(srcData.id);
clearDragDstState(); clearDragDstState();
}); });
@@ -205,9 +198,30 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
const data = Utils.createTreeData(tree.root); const data = Utils.createTreeData(tree.root);
graph.data(data); graph.data(data);
graph.render(); graph.render();
graph.fitCenter();
this.graph = graph; this.graph = graph;
} }
onSelectNode(node: string | INode) {
const graph = this.graph;
var curNode: INode;
if(typeof node == "string") {
curNode = graph.findById(node) as INode;
} else {
curNode = node;
}
if (this.state.curNode) {
graph.setItemState(this.state.curNode, 'selected', false);
}
this.setState({ curNode });
if (this.state.curNode) {
graph.setItemState(this.state.curNode, 'selected', true);
}
}
render() { render() {
const { curNode } = this.state; const { curNode } = this.state;
return ( return (