From 1f6f79c8aa1bb2c6cc2072892e57921c43e6f1dc Mon Sep 17 00:00:00 2001 From: 666ghj <670939375@qq.com> Date: Thu, 11 Dec 2025 13:40:01 +0800 Subject: [PATCH] Add gravitational forces to node simulation in GraphPanel.vue - Introduced x and y forces to attract independent nodes towards the center, enhancing the overall layout and clustering of nodes in the graph visualization. - Improved the simulation dynamics for a more cohesive visual representation of the graph. --- frontend/src/components/GraphPanel.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/components/GraphPanel.vue b/frontend/src/components/GraphPanel.vue index 539ebff..767f8d1 100644 --- a/frontend/src/components/GraphPanel.vue +++ b/frontend/src/components/GraphPanel.vue @@ -440,6 +440,9 @@ const renderGraph = () => { .force('charge', d3.forceManyBody().strength(-400)) .force('center', d3.forceCenter(width / 2, height / 2)) .force('collide', d3.forceCollide(50)) + // 添加向中心的引力,让独立的节点群聚集到中心区域 + .force('x', d3.forceX(width / 2).strength(0.04)) + .force('y', d3.forceY(height / 2).strength(0.04)) currentSimulation = simulation