Initial commit
This commit is contained in:
@@ -6,20 +6,20 @@
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
import type { EdgeNodeElement, NodeGraph, TaskNodeElement } from './element';
|
||||
import type { GraphEdgeElement, GraphTaskElement, NodeGraph } from './element';
|
||||
import { Edge, Graph, Node } from '@antv/x6';
|
||||
|
||||
export const defaultHeight: Record<string, number> = {
|
||||
component: 110,
|
||||
};
|
||||
|
||||
export const createModelNode = (element: TaskNodeElement, width: number = 250, height: number = 120): any => {
|
||||
export const createGraphTaskElement = (element: GraphTaskElement, width: number = 250, height: number = 120): any => {
|
||||
let realHeight = defaultHeight[element.category as string];
|
||||
if (!realHeight) {
|
||||
realHeight = 120;
|
||||
}
|
||||
return {
|
||||
shape: 'node',
|
||||
shape: 'task',
|
||||
id: element.key,
|
||||
position: {
|
||||
x: element.position?.x || 0,
|
||||
@@ -38,13 +38,13 @@ export const createModelNode = (element: TaskNodeElement, width: number = 250, h
|
||||
};
|
||||
};
|
||||
|
||||
export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
||||
const taskElements: TaskNodeElement[] = [];
|
||||
export const resolveGraphTaskElements = (graph: Graph): GraphTaskElement[] => {
|
||||
const taskElements: GraphTaskElement[] = [];
|
||||
if (graph) {
|
||||
const nodes = graph?.getNodes() as Node[];
|
||||
if (nodes) {
|
||||
nodes.forEach(node => {
|
||||
const nodeData = node.getData() as TaskNodeElement;
|
||||
const nodeData = node.getData() as GraphTaskElement;
|
||||
const newElement = {
|
||||
...nodeData,
|
||||
key: node.id,
|
||||
@@ -59,13 +59,13 @@ export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
||||
return taskElements;
|
||||
};
|
||||
|
||||
export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
||||
const edgeElements: EdgeNodeElement[] = [];
|
||||
export const resolveGraphEdgeElements = (graph: Graph): GraphEdgeElement[] => {
|
||||
const edgeElements: GraphEdgeElement[] = [];
|
||||
if (graph) {
|
||||
const graphEdges = graph?.getEdges() ?? [] as Edge[];
|
||||
if (graphEdges) {
|
||||
graphEdges.forEach(edge => {
|
||||
const nodeData = edge.getData() as TaskNodeElement;
|
||||
const nodeData = edge.getData() as GraphTaskElement;
|
||||
edgeElements.push({
|
||||
id: nodeData?.id ?? 0,
|
||||
key: edge.id,
|
||||
@@ -84,8 +84,8 @@ export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
||||
};
|
||||
|
||||
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||
const nodes: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const edges: EdgeNodeElement[] = resolveNodeEdgeElements(graph);
|
||||
const nodes: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
const edges: GraphEdgeElement[] = resolveGraphEdgeElements(graph);
|
||||
return {
|
||||
nodes,
|
||||
edges,
|
||||
@@ -94,7 +94,7 @@ export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||
|
||||
export const hasElements = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
return taskElements.length > 0;
|
||||
}
|
||||
return false;
|
||||
@@ -102,7 +102,7 @@ export const hasElements = (graph: Graph): boolean => {
|
||||
|
||||
export const hasRootElementNode = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
return taskElements.filter(e => e.type === 'root').length === 1;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user