refactor: 移除知识图谱统计信息的显示和相关逻辑(因为不准确)
- 在 `KnowledgeGraphSection.vue` 中,删除不准确的节点和边统计信息显示。 - 在 `KnowledgeGraphViewer.vue` 中,更新统计信息逻辑,移除对总节点和总边的依赖。 - 在 `database.js` 和 `graphStore.js` 中,移除图统计信息的初始化和重置逻辑,简化状态管理。
This commit is contained in:
parent
bf286e1f01
commit
6bc1f0e247
@ -2,10 +2,7 @@
|
||||
<div class="graph-section" v-if="isGraphSupported">
|
||||
<div class="graph-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<div class="graph-stats">
|
||||
<a-tag color="blue" size="small">总节点: {{ graphStats.total_nodes || 0 }}</a-tag>
|
||||
<a-tag color="green" size="small">总边: {{ graphStats.total_edges || 0 }}</a-tag>
|
||||
</div>
|
||||
<!-- 移除了不准确的总节点数和总边数显示 -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="graph-container-compact">
|
||||
@ -23,7 +20,6 @@
|
||||
:initial-limit="graphLimit"
|
||||
:initial-depth="graphDepth"
|
||||
ref="graphViewerRef"
|
||||
@update:stats="handleViewerStats"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -109,10 +105,6 @@ const store = useDatabaseStore();
|
||||
const databaseId = computed(() => store.databaseId);
|
||||
const kbType = computed(() => store.database.kb_type);
|
||||
const kbTypeLabel = computed(() => getKbTypeLabel(kbType.value || 'lightrag'));
|
||||
const graphStats = computed({
|
||||
get: () => store.graphStats,
|
||||
set: (stats) => store.graphStats = stats
|
||||
});
|
||||
|
||||
const graphViewerRef = ref(null);
|
||||
const showSettings = ref(false);
|
||||
@ -254,19 +246,6 @@ const scheduleGraphLoad = (delay = 200) => {
|
||||
}, delay);
|
||||
};
|
||||
|
||||
// 处理子组件(Viewer)上报的统计信息,将其写入 database store 的 graphStats
|
||||
const handleViewerStats = (stats) => {
|
||||
if (!stats) return;
|
||||
|
||||
// 合并现有 store.graphStats,优先使用来自 viewer 的值
|
||||
store.graphStats = {
|
||||
total_nodes: stats.total_nodes ?? store.graphStats.total_nodes ?? 0,
|
||||
total_edges: stats.total_edges ?? store.graphStats.total_edges ?? 0,
|
||||
displayed_nodes: stats.displayed_nodes ?? store.graphStats.displayed_nodes ?? 0,
|
||||
displayed_edges: stats.displayed_edges ?? store.graphStats.displayed_edges ?? 0,
|
||||
is_truncated: stats.is_truncated ?? store.graphStats.is_truncated ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.active,
|
||||
@ -279,14 +258,6 @@ watch(
|
||||
);
|
||||
|
||||
watch(databaseId, () => {
|
||||
// 重置统计信息
|
||||
store.graphStats = {
|
||||
total_nodes: 0,
|
||||
total_edges: 0,
|
||||
displayed_nodes: 0,
|
||||
displayed_edges: 0,
|
||||
is_truncated: false
|
||||
};
|
||||
clearGraph();
|
||||
|
||||
// 只有在新数据库支持图谱时才加载
|
||||
@ -297,13 +268,6 @@ watch(databaseId, () => {
|
||||
|
||||
watch(isGraphSupported, (supported) => {
|
||||
if (!supported) {
|
||||
store.graphStats = {
|
||||
total_nodes: 0,
|
||||
total_edges: 0,
|
||||
displayed_nodes: 0,
|
||||
displayed_edges: 0,
|
||||
is_truncated: false
|
||||
};
|
||||
clearGraph();
|
||||
return;
|
||||
}
|
||||
@ -339,12 +303,6 @@ onUnmounted(() => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.graph-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
|
||||
@ -698,13 +698,10 @@ const loadGraphData = async () => {
|
||||
|
||||
// 设置图数据
|
||||
graphStore.setRawGraph(rawGraph)
|
||||
// 更新 displayed 计数(当前视图)以及来自后端的 total 计数(整个库)
|
||||
// 更新当前显示的节点和边数量
|
||||
graphStore.stats = {
|
||||
displayed_nodes: graphResponse.data.nodes.length,
|
||||
displayed_edges: graphResponse.data.edges.length,
|
||||
// 从 statsResponse 填充整个知识库的统计信息(后端返回 total_nodes/total_edges)
|
||||
total_nodes: statsResponse.data.total_nodes ?? graphStore.stats.total_nodes ?? 0,
|
||||
total_edges: statsResponse.data.total_edges ?? graphStore.stats.total_edges ?? 0,
|
||||
is_truncated: graphResponse.data.is_truncated
|
||||
}
|
||||
|
||||
|
||||
@ -17,14 +17,7 @@ export const useDatabaseStore = defineStore('database', () => {
|
||||
|
||||
const queryParams = ref([]);
|
||||
const meta = reactive({});
|
||||
const graphStats = ref({
|
||||
total_nodes: 0,
|
||||
total_edges: 0,
|
||||
displayed_nodes: 0,
|
||||
displayed_edges: 0,
|
||||
is_truncated: false,
|
||||
});
|
||||
const selectedRowKeys = ref([]);
|
||||
const selectedRowKeys = ref([]);
|
||||
|
||||
const state = reactive({
|
||||
databaseLoading: false,
|
||||
@ -377,7 +370,6 @@ export const useDatabaseStore = defineStore('database', () => {
|
||||
selectedFile,
|
||||
queryParams,
|
||||
meta,
|
||||
graphStats,
|
||||
selectedRowKeys,
|
||||
state,
|
||||
getDatabaseInfo,
|
||||
|
||||
@ -27,10 +27,9 @@ export const useGraphStore = defineStore('graph', {
|
||||
|
||||
// 图统计信息
|
||||
stats: {
|
||||
total_nodes: 0,
|
||||
total_edges: 0,
|
||||
displayed_nodes: 0,
|
||||
displayed_edges: 0
|
||||
displayed_edges: 0,
|
||||
is_truncated: false
|
||||
}
|
||||
}),
|
||||
|
||||
@ -44,9 +43,9 @@ export const useGraphStore = defineStore('graph', {
|
||||
// 获取选中边的详细信息
|
||||
selectedEdgeData: (state) => {
|
||||
if (!state.selectedEdge || !state.rawGraph) return null
|
||||
|
||||
|
||||
console.log('查找边数据,选中边ID:', state.selectedEdge)
|
||||
|
||||
|
||||
// 首先尝试通过dynamicId匹配(Sigma使用的ID格式)
|
||||
let foundEdge = state.rawGraph.edges.find(edge => edge.dynamicId === state.selectedEdge)
|
||||
if (foundEdge) {
|
||||
@ -66,7 +65,7 @@ export const useGraphStore = defineStore('graph', {
|
||||
const match = state.selectedEdge.match(dynamicIdPattern)
|
||||
if (match) {
|
||||
const [, source, target, index] = match
|
||||
foundEdge = state.rawGraph.edges.find(edge =>
|
||||
foundEdge = state.rawGraph.edges.find(edge =>
|
||||
edge.source === source && edge.target === target
|
||||
)
|
||||
if (foundEdge) {
|
||||
@ -204,10 +203,9 @@ export const useGraphStore = defineStore('graph', {
|
||||
updateStats() {
|
||||
if (this.rawGraph) {
|
||||
this.stats = {
|
||||
total_nodes: this.rawGraph.nodes.length,
|
||||
total_edges: this.rawGraph.edges.length,
|
||||
displayed_nodes: this.rawGraph.nodes.length,
|
||||
displayed_edges: this.rawGraph.edges.length
|
||||
displayed_edges: this.rawGraph.edges.length,
|
||||
is_truncated: this.rawGraph.is_truncated ?? this.stats?.is_truncated ?? false
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -417,10 +415,9 @@ export const useGraphStore = defineStore('graph', {
|
||||
this.moveToSelectedNode = false
|
||||
this.graphIsEmpty = false
|
||||
this.stats = {
|
||||
total_nodes: 0,
|
||||
total_edges: 0,
|
||||
displayed_nodes: 0,
|
||||
displayed_edges: 0
|
||||
displayed_edges: 0,
|
||||
is_truncated: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user