Skip to content

Commit

Permalink
style(constant)
Browse files Browse the repository at this point in the history
feat(graphUtil): Update label using nickname like "task 1.1"
  • Loading branch information
ChrisGray0626 committed Jul 19, 2024
1 parent 417e1f4 commit fbf85eb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
12 changes: 4 additions & 8 deletions src/api/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -27,7 +23,7 @@ export const fetchTool = (_toolId: string) =>
setTimeout(
() =>
resolve({
data: JSON.parse(MOCK_TOOL),
data: MOCK_TOOL,
}),
500,
);
Expand Down
45 changes: 43 additions & 2 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]
}
};
16 changes: 9 additions & 7 deletions src/utils/graphUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fbf85eb

Please sign in to comment.