Skip to content

Commit 6bc1f0e

Browse files
committed
refactor: 移除知识图谱统计信息的显示和相关逻辑(因为不准确)
- 在 `KnowledgeGraphSection.vue` 中,删除不准确的节点和边统计信息显示。 - 在 `KnowledgeGraphViewer.vue` 中,更新统计信息逻辑,移除对总节点和总边的依赖。 - 在 `database.js` 和 `graphStore.js` 中,移除图统计信息的初始化和重置逻辑,简化状态管理。
1 parent bf286e1 commit 6bc1f0e

File tree

4 files changed

+12
-68
lines changed

4 files changed

+12
-68
lines changed

web/src/components/KnowledgeGraphSection.vue

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
<div class="graph-section" v-if="isGraphSupported">
33
<div class="graph-toolbar">
44
<div class="toolbar-left">
5-
<div class="graph-stats">
6-
<a-tag color="blue" size="small">总节点: {{ graphStats.total_nodes || 0 }}</a-tag>
7-
<a-tag color="green" size="small">总边: {{ graphStats.total_edges || 0 }}</a-tag>
8-
</div>
5+
<!-- 移除了不准确的总节点数和总边数显示 -->
96
</div>
107
</div>
118
<div class="graph-container-compact">
@@ -23,7 +20,6 @@
2320
:initial-limit="graphLimit"
2421
:initial-depth="graphDepth"
2522
ref="graphViewerRef"
26-
@update:stats="handleViewerStats"
2723
/>
2824
</div>
2925

@@ -109,10 +105,6 @@ const store = useDatabaseStore();
109105
const databaseId = computed(() => store.databaseId);
110106
const kbType = computed(() => store.database.kb_type);
111107
const kbTypeLabel = computed(() => getKbTypeLabel(kbType.value || 'lightrag'));
112-
const graphStats = computed({
113-
get: () => store.graphStats,
114-
set: (stats) => store.graphStats = stats
115-
});
116108
117109
const graphViewerRef = ref(null);
118110
const showSettings = ref(false);
@@ -254,19 +246,6 @@ const scheduleGraphLoad = (delay = 200) => {
254246
}, delay);
255247
};
256248
257-
// 处理子组件(Viewer)上报的统计信息,将其写入 database store 的 graphStats
258-
const handleViewerStats = (stats) => {
259-
if (!stats) return;
260-
261-
// 合并现有 store.graphStats,优先使用来自 viewer 的值
262-
store.graphStats = {
263-
total_nodes: stats.total_nodes ?? store.graphStats.total_nodes ?? 0,
264-
total_edges: stats.total_edges ?? store.graphStats.total_edges ?? 0,
265-
displayed_nodes: stats.displayed_nodes ?? store.graphStats.displayed_nodes ?? 0,
266-
displayed_edges: stats.displayed_edges ?? store.graphStats.displayed_edges ?? 0,
267-
is_truncated: stats.is_truncated ?? store.graphStats.is_truncated ?? false,
268-
}
269-
}
270249
271250
watch(
272251
() => props.active,
@@ -279,14 +258,6 @@ watch(
279258
);
280259
281260
watch(databaseId, () => {
282-
// 重置统计信息
283-
store.graphStats = {
284-
total_nodes: 0,
285-
total_edges: 0,
286-
displayed_nodes: 0,
287-
displayed_edges: 0,
288-
is_truncated: false
289-
};
290261
clearGraph();
291262
292263
// 只有在新数据库支持图谱时才加载
@@ -297,13 +268,6 @@ watch(databaseId, () => {
297268
298269
watch(isGraphSupported, (supported) => {
299270
if (!supported) {
300-
store.graphStats = {
301-
total_nodes: 0,
302-
total_edges: 0,
303-
displayed_nodes: 0,
304-
displayed_edges: 0,
305-
is_truncated: false
306-
};
307271
clearGraph();
308272
return;
309273
}
@@ -339,12 +303,6 @@ onUnmounted(() => {
339303
display: flex;
340304
align-items: center;
341305
gap: 12px;
342-
343-
.graph-stats {
344-
display: flex;
345-
align-items: center;
346-
gap: 8px;
347-
}
348306
}
349307
350308
.toolbar-right {

web/src/components/KnowledgeGraphViewer.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,10 @@ const loadGraphData = async () => {
698698
699699
// 设置图数据
700700
graphStore.setRawGraph(rawGraph)
701-
// 更新 displayed 计数(当前视图)以及来自后端的 total 计数(整个库)
701+
// 更新当前显示的节点和边数量
702702
graphStore.stats = {
703703
displayed_nodes: graphResponse.data.nodes.length,
704704
displayed_edges: graphResponse.data.edges.length,
705-
// 从 statsResponse 填充整个知识库的统计信息(后端返回 total_nodes/total_edges)
706-
total_nodes: statsResponse.data.total_nodes ?? graphStore.stats.total_nodes ?? 0,
707-
total_edges: statsResponse.data.total_edges ?? graphStore.stats.total_edges ?? 0,
708705
is_truncated: graphResponse.data.is_truncated
709706
}
710707

web/src/stores/database.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ export const useDatabaseStore = defineStore('database', () => {
1717

1818
const queryParams = ref([]);
1919
const meta = reactive({});
20-
const graphStats = ref({
21-
total_nodes: 0,
22-
total_edges: 0,
23-
displayed_nodes: 0,
24-
displayed_edges: 0,
25-
is_truncated: false,
26-
});
27-
const selectedRowKeys = ref([]);
20+
const selectedRowKeys = ref([]);
2821

2922
const state = reactive({
3023
databaseLoading: false,
@@ -377,7 +370,6 @@ export const useDatabaseStore = defineStore('database', () => {
377370
selectedFile,
378371
queryParams,
379372
meta,
380-
graphStats,
381373
selectedRowKeys,
382374
state,
383375
getDatabaseInfo,

web/src/stores/graphStore.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ export const useGraphStore = defineStore('graph', {
2727

2828
// 图统计信息
2929
stats: {
30-
total_nodes: 0,
31-
total_edges: 0,
3230
displayed_nodes: 0,
33-
displayed_edges: 0
31+
displayed_edges: 0,
32+
is_truncated: false
3433
}
3534
}),
3635

@@ -44,9 +43,9 @@ export const useGraphStore = defineStore('graph', {
4443
// 获取选中边的详细信息
4544
selectedEdgeData: (state) => {
4645
if (!state.selectedEdge || !state.rawGraph) return null
47-
46+
4847
console.log('查找边数据,选中边ID:', state.selectedEdge)
49-
48+
5049
// 首先尝试通过dynamicId匹配(Sigma使用的ID格式)
5150
let foundEdge = state.rawGraph.edges.find(edge => edge.dynamicId === state.selectedEdge)
5251
if (foundEdge) {
@@ -66,7 +65,7 @@ export const useGraphStore = defineStore('graph', {
6665
const match = state.selectedEdge.match(dynamicIdPattern)
6766
if (match) {
6867
const [, source, target, index] = match
69-
foundEdge = state.rawGraph.edges.find(edge =>
68+
foundEdge = state.rawGraph.edges.find(edge =>
7069
edge.source === source && edge.target === target
7170
)
7271
if (foundEdge) {
@@ -204,10 +203,9 @@ export const useGraphStore = defineStore('graph', {
204203
updateStats() {
205204
if (this.rawGraph) {
206205
this.stats = {
207-
total_nodes: this.rawGraph.nodes.length,
208-
total_edges: this.rawGraph.edges.length,
209206
displayed_nodes: this.rawGraph.nodes.length,
210-
displayed_edges: this.rawGraph.edges.length
207+
displayed_edges: this.rawGraph.edges.length,
208+
is_truncated: this.rawGraph.is_truncated ?? this.stats?.is_truncated ?? false
211209
}
212210
}
213211
},
@@ -417,10 +415,9 @@ export const useGraphStore = defineStore('graph', {
417415
this.moveToSelectedNode = false
418416
this.graphIsEmpty = false
419417
this.stats = {
420-
total_nodes: 0,
421-
total_edges: 0,
422418
displayed_nodes: 0,
423-
displayed_edges: 0
419+
displayed_edges: 0,
420+
is_truncated: false
424421
}
425422
}
426423
}

0 commit comments

Comments
 (0)