diff --git a/src/api/mock.ts b/src/api/mock.ts index 2f7ff71..c649092 100644 --- a/src/api/mock.ts +++ b/src/api/mock.ts @@ -4,19 +4,15 @@ * @Date: 2024/6/19 */ -import { MOCK_JOB, MOCK_TOOL } from "@/constant"; +import {MOCK_JOB, MOCK_TOOL} from "@/constant"; export const fetchJob = (task: string) => new Promise<{ data: any }>((resolve, _reject) => { + MOCK_JOB.data.task = task; setTimeout( () => resolve({ - data: JSON.parse( - MOCK_JOB.replace( - /"task":"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file/, - '"task":"' + task, - ), - ), + data: MOCK_JOB }), 1000, ); @@ -27,7 +23,7 @@ export const fetchTool = (_toolId: string) => setTimeout( () => resolve({ - data: JSON.parse(MOCK_TOOL), + data: MOCK_TOOL, }), 500, ); diff --git a/src/constant/index.ts b/src/constant/index.ts index 27d8060..5f80ead 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -53,5 +53,46 @@ export const TOOL_EXAMPLE = { }, ], }; -export const MOCK_JOB = `{"code":70200,"message":"Success!","data":{"task":"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file","subtasks":[{"task":"Merge multiple TIF files into a single raster dataset","toolId":"gdal:merge","subtasks":[],"toolName":"gdal:merge"},{"task":"Clip the merged raster dataset using the shape of the island from the vector file to extract the relevant elevation data","toolId":"gdal:cliprasterbymasklayer","subtasks":[],"toolName":"gdal:cliprasterbymasklayer"}],"toolId":"","toolName":""}}`; -export const MOCK_TOOL = `{"code":70200,"message":"success","data":{"id":"gdal:cliprasterbymasklayer","name":"Clip raster by mask layer","description":"Clip raster by mask layer","args":[{"name":"INPUT","description":"Input raster file","type":"raster","required":true},{"name":"MASK","description":"Mask layer","type":"vector","required":true},{"name":"OUTPUT","description":"Output raster file","type":"raster","required":true}]}}`; +export const MOCK_JOB = { + "code": 70200, + "message": "Success!", + "data": { + "task": "Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file", + "subtasks": [ + { + "task": "Merge multiple TIF files into a single raster dataset", + "toolId": "gdal:merge", + "subtasks": [], + "toolName": "gdal:merge" + }, + { + "task": "Clip the merged raster dataset using the shape of the island from the vector file to extract the relevant elevation data", + "toolId": "gdal:cliprasterbymasklayer", + "subtasks": [], + "toolName": "gdal:cliprasterbymasklayer" + } + ], + "toolId": "", + "toolName": "" + } +}; +export const MOCK_TOOL = { + "code": 70200, + "message": "success", + "data": { + "id": "gdal:cliprasterbymasklayer", + "name": "Clip raster by mask layer", + "description": "Clip raster by mask layer", + "args": [{ + "name": "INPUT", + "description": "Input raster file", + "type": "raster", + "required": true + }, {"name": "MASK", "description": "Mask layer", "type": "vector", "required": true}, { + "name": "OUTPUT", + "description": "Output raster file", + "type": "raster", + "required": true + }] + } +}; diff --git a/src/utils/graphUtil.ts b/src/utils/graphUtil.ts index 198ff3e..8c727c8 100644 --- a/src/utils/graphUtil.ts +++ b/src/utils/graphUtil.ts @@ -3,28 +3,30 @@ * @Author: Chris * @Date: 2024/6/7 */ -import G6, { TreeGraphData } from "@antv/g6"; -import { EdgeConfig, GraphData, NodeConfig } from "@antv/g6-core/lib/types"; -import { Task } from "@/type.ts"; +import G6, {TreeGraphData} from "@antv/g6"; +import {EdgeConfig, GraphData, NodeConfig} from "@antv/g6-core/lib/types"; +import {Task} from "@/type.ts"; export function job2G6TreeGraph(job: Task) { - function buildTreeNode(task: Task) { + function buildTreeNode(task: Task, label: string) { const { children } = task; const treeNode: TreeGraphData = { id: generateId(), - label: task.name, + label: label, task: task, children: [] as TreeGraphData[], }; if (children && children.length > 0) { for (let i = 0; i < children.length; i++) { - treeNode.children!.push(buildTreeNode(children[i])); + const subLabel = `${label}.${i + 1}`; + treeNode.children!.push(buildTreeNode(children[i], subLabel)); } } return treeNode; } - return buildTreeNode(job); + const label = "task 1"; + return buildTreeNode(job, label); } export function jobLeafNode2G6Graph(job: Task) {