Initial commit
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import { Edge, Graph, Node } from '@antv/x6';
|
||||
import type { EdgeNodeElement, NodeGraph, NodeTemplate, SettingTaskNodeElement, TaskNodeElement, TaskNodeRect } from '../types';
|
||||
import { generateKey } from '@/utils/strings.ts';
|
||||
import type { NodeTemplate } from '../types';
|
||||
import type { SettingTaskNodeElement, TaskNodeRect } from '../builder/element';
|
||||
import { generateKey } from '@/utils/strings';
|
||||
|
||||
export const createTaskNodeElementFromTemplate = (
|
||||
template: NodeTemplate,
|
||||
@@ -31,7 +31,7 @@ export const createTaskNodeElementFromTemplate = (
|
||||
},
|
||||
width: realRect.width,
|
||||
height: realRect.height,
|
||||
settings: JSON.parse(JSON.stringify(template.parameter_defs ?? [])),
|
||||
// settings: JSON.parse(JSON.stringify(template.parameter_defs ?? [])),
|
||||
inputs: null,
|
||||
outputs: null,
|
||||
parameters: {},
|
||||
@@ -53,94 +53,3 @@ export const createTaskNodeElementFromTemplate = (
|
||||
],
|
||||
} as SettingTaskNodeElement;
|
||||
};
|
||||
|
||||
export const createTaskNodeElement = (element: TaskNodeElement, width: number = 200, height: number = 100): any => {
|
||||
return {
|
||||
shape: 'task',
|
||||
id: element.key,
|
||||
position: {
|
||||
x: element.position?.x || 0,
|
||||
y: element.position?.y || 0,
|
||||
},
|
||||
size: {
|
||||
width: element.width ?? width,
|
||||
height: element.height ?? height,
|
||||
},
|
||||
attrs: {
|
||||
label: {
|
||||
text: element.name,
|
||||
},
|
||||
},
|
||||
data: element,
|
||||
};
|
||||
};
|
||||
|
||||
export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
||||
const taskElements: TaskNodeElement[] = [];
|
||||
if (graph) {
|
||||
const nodes = graph?.getNodes() as Node[];
|
||||
if (nodes) {
|
||||
nodes.forEach(node => {
|
||||
const nodeData = node.getData() as TaskNodeElement;
|
||||
const newElement = {
|
||||
...nodeData,
|
||||
key: node.id,
|
||||
position: node.getPosition(),
|
||||
width: node.getSize().width,
|
||||
height: node.getSize().height,
|
||||
};
|
||||
taskElements.push(newElement);
|
||||
});
|
||||
}
|
||||
}
|
||||
return taskElements;
|
||||
};
|
||||
|
||||
export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
||||
const edgeElements: EdgeNodeElement[] = [];
|
||||
if (graph) {
|
||||
const graphEdges = graph?.getEdges() ?? [] as Edge[];
|
||||
if (graphEdges) {
|
||||
graphEdges.forEach(edge => {
|
||||
const nodeData = edge.getData() as TaskNodeElement;
|
||||
edgeElements.push({
|
||||
id: nodeData?.id ?? 0,
|
||||
key: edge.id,
|
||||
type: 'edge',
|
||||
status: nodeData?.status,
|
||||
source: edge.getSource() ? edge.getSource() as unknown as string : null,
|
||||
target: edge.getSource() ? edge.getTarget() as unknown as string : null,
|
||||
attrs: edge.getAttrs() ?? {},
|
||||
router: edge.getRouter() ?? {},
|
||||
connector: edge.getConnector() ?? null,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return edgeElements;
|
||||
};
|
||||
|
||||
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||
const nodes: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const edges: EdgeNodeElement[] = resolveNodeEdgeElements(graph);
|
||||
return {
|
||||
nodes,
|
||||
edges,
|
||||
};
|
||||
};
|
||||
|
||||
export const hasElements = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
return taskElements.length > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export const hasRootElementNode = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
return taskElements.filter(e => e.type === 'root').length === 1;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user