double click fold & unfold

This commit is contained in:
zhandouxiaojiji committed 2020-10-19 20:42:56 +08:00
1 parent d2b0584c24
commit 0093bf961e
2 files changed
+22 -9

No files matched your search

+22 -7
View File
@@ -1,7 +1,10 @@
import * as React from 'react'; import * as React from 'react';
import GGEditor, { Mind, RegisterNode, setAnchorPointsState } from 'gg-editor'; import GGEditor, { Mind, RegisterNode, constants, CommandManager } from 'gg-editor';
import { INode } from '@antv/g6/lib/interface/item'; import { INode } from '@antv/g6/lib/interface/item';
import { MindData, Graph, GraphEvent } from 'gg-editor/lib/common/interfaces'; import { MindData, Graph, GraphEvent } from 'gg-editor/lib/common/interfaces';
const { EditorCommand } = constants
const data: MindData = { const data: MindData = {
id: "1", id: "1",
label: 'Central Topic111', label: 'Central Topic111',
@@ -27,21 +30,32 @@ interface BehaviorTreeProps {
class BehaviorTree extends React.Component<BehaviorTreeProps> { class BehaviorTree extends React.Component<BehaviorTreeProps> {
graph: Graph; graph: Graph;
mind: Mind;
componentDidMount() { componentDidMount() {
} }
initGraph(graph: Graph) { initGraph(graph: Graph) {
const { onSelectNode } = this.props; const { onSelectNode } = this.props;
graph.on('click', (ev: GraphEvent) => { graph.on('click', (ev: GraphEvent) => {
if (!ev.item) { const item = ev.item;
if (!item) {
onSelectNode(null); onSelectNode(null);
} else if (ev.item.getType() == "node") { } else if (item.getType() == "node") {
onSelectNode(ev.item as INode); onSelectNode(item as INode);
} }
}); });
graph.on('dbclick', (ev: GraphEvent) => { graph.on('dblclick', (ev: GraphEvent) => {
console.log("dbclick", ev); console.log("dblclick", ev);
const item = ev.item;
if (item && item.getType() == 'node') {
const commandManager: CommandManager = graph.get('commandManager');
if (commandManager.canExecute(graph, EditorCommand.Fold)) {
commandManager.execute(graph, EditorCommand.Fold);
} else {
commandManager.execute(graph, EditorCommand.Unfold);
}
}
}); });
graph.on('dragenter', (ev: GraphEvent) => { graph.on('dragenter', (ev: GraphEvent) => {
@@ -61,8 +75,9 @@ class BehaviorTree extends React.Component<BehaviorTreeProps> {
}} }}
data={data} data={data}
ref={component => { ref={component => {
if (component) { if (component && !this.graph) {
this.initGraph(component.graph); this.initGraph(component.graph);
this.mind = component;
} }
}} }}
/> />
-2
View File
@@ -17,7 +17,6 @@ class Panel extends React.Component<NodePanelProps> {
} }
renderNode() { renderNode() {
console.log("NodePanel render", this.props);
const { curNode } = this.props; const { curNode } = this.props;
return ( return (
<div> <div>
@@ -27,7 +26,6 @@ class Panel extends React.Component<NodePanelProps> {
} }
render() { render() {
console.log("NodePanel render", this.props);
const { curNode } = this.props; const { curNode } = this.props;
return ( return (
<Card title="节点信息" style={{ height: "100%" }}> <Card title="节点信息" style={{ height: "100%" }}>