diff --git a/frontend/src/components/Legend/index.tsx b/frontend/src/components/Legend/index.tsx
new file mode 100644
index 0000000..5d1891d
--- /dev/null
+++ b/frontend/src/components/Legend/index.tsx
@@ -0,0 +1,69 @@
+import { useState } from 'react';
+import { NODE_COLOR_MAP, NODE_TYPE_LABELS } from '../../config/colors';
+
+/**
+ * 图例组件
+ * 显示知识图谱中不同节点类型及其对应的颜色
+ * 支持折叠/展开展示
+ */
+export const Legend = () => {
+ const [isExpanded, setIsExpanded] = useState(true);
+
+ const nodeTypes = Object.entries(NODE_COLOR_MAP);
+
+ return (
+
+
+
图例
+
+
+
+ {isExpanded && (
+
+ {nodeTypes.map(([type, colors], index) => {
+ const labels = NODE_TYPE_LABELS[type] || { zh: type, en: type };
+ return (
+
+
+
+
+
+ {labels.zh}
+
+
+ {labels.en}
+
+
+
+ );
+ })}
+
+ )}
+
+ );
+};
+
+export default Legend;
diff --git a/frontend/src/config/colors.ts b/frontend/src/config/colors.ts
index 99df291..ab0975d 100644
--- a/frontend/src/config/colors.ts
+++ b/frontend/src/config/colors.ts
@@ -11,8 +11,20 @@ export const NODE_COLOR_MAP: Record =
// 默认节点颜色(当类型未匹配时)
export const DEFAULT_NODE_COLORS = { fill: '#C6E5FF', stroke: '#5B8FF9' };
+// 节点类型双语标签映射
+export const NODE_TYPE_LABELS: Record = {
+ '概念': { zh: '概念', en: 'Concept' },
+ '工具': { zh: '工具', en: 'Tool' },
+ '应用': { zh: '应用', en: 'Application' },
+};
+
// 获取节点颜色配置
export const getNodeColors = (node: Node): { fill: string; stroke: string } => {
if (!node.type) return DEFAULT_NODE_COLORS;
return NODE_COLOR_MAP[node.type] || DEFAULT_NODE_COLORS;
};
+
+// 获取节点双语标签
+export const getNodeLabels = (type: string): { zh: string; en: string } => {
+ return NODE_TYPE_LABELS[type] || { zh: type, en: type };
+};
diff --git a/frontend/src/pages/KnowledgeGraph.tsx b/frontend/src/pages/KnowledgeGraph.tsx
index a23f343..ff374dc 100644
--- a/frontend/src/pages/KnowledgeGraph.tsx
+++ b/frontend/src/pages/KnowledgeGraph.tsx
@@ -1,6 +1,7 @@
import GraphView from '../components/GraphView/index';
import SearchBar from '../components/SearchBar/index';
import NodePanel from '../components/NodePanel/index';
+import Legend from '../components/Legend/index';
import { useGraphData } from '../hooks/useGraphData';
import { useGraphLayout } from '../hooks/useGraphLayout';
@@ -53,6 +54,7 @@ export const KnowledgeGraph = () => {
+
{
/>
{hoveredNode && (
-
+
{hoveredNode.label}
{hoveredNode.type && (
{hoveredNode.type}