drag right
This commit is contained in:
1 parent
4fd1992f1f
commit
b4e08f7108
4 files changed
+159
-57
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { TreeGraphData } from "@antv/g6/lib/types"
|
||||
import { Tree } from "antd";
|
||||
import { BehaviorNodeModel } from "./BehaviorTreeModel";
|
||||
|
||||
export const cloneNodeData = (nodeData: TreeGraphData) => {
|
||||
const newData: TreeGraphData = {
|
||||
id: nodeData.id + "new",
|
||||
label: nodeData.label,
|
||||
}
|
||||
return newData;
|
||||
}
|
||||
|
||||
export const refreshNodeId = (nodeData: TreeGraphData, id?: number) => {
|
||||
if (!id) {
|
||||
id = 1;
|
||||
}
|
||||
nodeData.id = (id++).toString();
|
||||
if (nodeData.children) {
|
||||
nodeData.children.forEach(child => {
|
||||
id = refreshNodeId(child, id);
|
||||
})
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
export const createTreeData = (bNode: BehaviorNodeModel) => {
|
||||
const treeData: any = {
|
||||
id: bNode.id.toString(),
|
||||
name: bNode.name,
|
||||
}
|
||||
if (bNode.children) {
|
||||
treeData.children = [];
|
||||
bNode.children.forEach(child => {
|
||||
treeData.children.push(createTreeData(child));
|
||||
})
|
||||
}
|
||||
return treeData;
|
||||
}
|
||||
|
||||
export const findParent = (node: TreeGraphData, id: string): TreeGraphData | null => {
|
||||
if (node.children) {
|
||||
for (let child of node.children) {
|
||||
if (child.id == id) {
|
||||
return node;
|
||||
} else {
|
||||
let parent = findParent(child, id);
|
||||
if (parent) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const findFromAllChildren = (node: TreeGraphData, id: string): TreeGraphData | null => {
|
||||
if (node.id == id) {
|
||||
return node;
|
||||
}
|
||||
if (node.children) {
|
||||
for (let child of node.children) {
|
||||
let found = findFromAllChildren(child, id);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user