You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Gephi导出Sigma.js模板后,如何实现仅悬停节点时显示边?

Hover Node to Show Connected Edges in Sigma.js (Gephi Export)

Hey there! Let's get this hover-to-show-edges feature working for your Sigma.js visualization exported from Gephi. Since you mentioned you don't know JavaScript, I'll break this down with exact copy-paste code and simple steps—no prior JS experience required.

Why Your config.json Changes Didn't Work

Sigma.js doesn't have a built-in config setting for this specific behavior, which is why your tweaks to network/config.json didn't take effect. We need to add custom event listeners in network/js/main.js to manually control edge visibility.

Step-by-Step Fix

  1. Open network/js/main.js in a basic text editor (like Notepad, VS Code, or even TextEdit).
  2. Look for the section where Sigma initializes your graph. In Gephi's exported template, this usually looks like:
    sigma.parsers.json(
      'data/graph.json',
      { container: 'sigma-container' },
      function(s) {
        // We'll add our code right here!
      }
    );
    
  3. Copy and paste the following code inside the callback function (where the comment is):
    // Hide all edges by default when the graph loads
    s.graph.edges().forEach(edge => {
      edge.hidden = true;
    });
    s.refresh();
    
    // Show edges connected to the hovered node
    s.bind('overNode', (event) => {
      const hoveredNodeId = event.data.node.id;
      // Loop through all edges and show those linked to the hovered node
      s.graph.edges().forEach(edge => {
        if (edge.source === hoveredNodeId || edge.target === hoveredNodeId) {
          edge.hidden = false;
        }
      });
      s.refresh(); // Update the visualization to show changes
    });
    
    // Hide all edges when mouse leaves the node
    s.bind('outNode', () => {
      s.graph.edges().forEach(edge => {
        edge.hidden = true;
      });
      s.refresh();
    });
    

What This Code Does

  • Default State: All edges stay hidden when your graph first loads
  • On Hover: When you mouse over a node, it finds every edge connected to that node (either as a starting or ending point) and makes those edges visible
  • On Mouse Out: As soon as you move your mouse away from the node, all edges hide again

Save and Test

Save your changes to main.js, then open your visualization's index.html file in a browser. You should now only see edges when hovering over their connected nodes!

内容的提问来源于stack exchange,提问作者yausername

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:08:40