666ghj commited on
Commit
108b72f
·
1 Parent(s): be60b1a

Add gravitational forces to node simulation in GraphPanel.vue

Browse files

- 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 CHANGED
@@ -440,6 +440,9 @@ const renderGraph = () => {
440
  .force('charge', d3.forceManyBody().strength(-400))
441
  .force('center', d3.forceCenter(width / 2, height / 2))
442
  .force('collide', d3.forceCollide(50))
 
 
 
443
 
444
  currentSimulation = simulation
445
 
 
440
  .force('charge', d3.forceManyBody().strength(-400))
441
  .force('center', d3.forceCenter(width / 2, height / 2))
442
  .force('collide', d3.forceCollide(50))
443
+ // 添加向中心的引力,让独立的节点群聚集到中心区域
444
+ .force('x', d3.forceX(width / 2).strength(0.04))
445
+ .force('y', d3.forceY(height / 2).strength(0.04))
446
 
447
  currentSimulation = simulation
448