perfect: 设定样式资源池将硬编码label转化为可配置
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState, useCallback, useEffect } from 'react';
|
||||
import type { GraphData, Node, SearchNode } from '../types/graph';
|
||||
import { graphApi } from '../services/graphApi';
|
||||
import { SAMPLE_GRAPH_DATA } from '../config/sampleData';
|
||||
import { resetColorAssignment } from '../config/colors';
|
||||
|
||||
/**
|
||||
* 知识图谱数据管理 Hook
|
||||
@@ -20,6 +21,9 @@ export const useGraphData = () => {
|
||||
setLoading(true);
|
||||
const data = await graphApi.getData();
|
||||
|
||||
// 重置颜色分配缓存,确保每次加载数据时颜色分配一致
|
||||
resetColorAssignment();
|
||||
|
||||
// 如果后端返回空数据,使用示例数据
|
||||
if (data.nodes.length === 0) {
|
||||
setGraphData(SAMPLE_GRAPH_DATA);
|
||||
@@ -28,6 +32,8 @@ export const useGraphData = () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load graph data:', error);
|
||||
// 重置颜色分配缓存
|
||||
resetColorAssignment();
|
||||
// API 失败时使用示例数据作为降级方案
|
||||
setGraphData(SAMPLE_GRAPH_DATA);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user