首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CytoscapeJS -显示节点邻域?

CytoscapeJS -显示节点邻域?
EN

Stack Overflow用户
提问于 2015-03-10 17:48:10
回答 1查看 1.7K关注 0票数 3

我有一个JSON格式的数据集,其中包含关于节点和边缘的信息,用于在cytoscapeJS中生成网络图。JSON数据包含节点的id、值、形状、颜色和节点的 ('element‘或'none')属性,以及边缘的id、源、目标和标签。我的样式表使用这个“visibleDisplay”属性在cy容器首次初始化时根据需要显示/隐藏节点。

我希望允许用户取消隐藏节点的选项“显示邻里”。我已经修改了我的旧代码以使用集合,但它仍然无法工作:

代码语言:javascript
运行
复制
function showNeighbourhood() {
   var eleID;
   var neighbourArray= new Array();

   var neighbours= cy.collection(); // collection

   cy.nodes().forEach(function( ele ) {
       if(ele.selected()) { // get the currently selected node.
          eleID= ele.id();
         }
      });

   // Find its connected neighbours.
   cy.edges().forEach(function( edg ) {
       if(edg.data('source') === eleID) {
          neighbourArray[neighbourArray.length]= edg.data('target');
         }
       else if(edg.data('target') === eleID) {
          neighbourArray[neighbourArray.length]= edg.data('source');
         }
      });

   // Add the array to the collection.
   neighbours.add(neighbourArray);

  // Show neighbourhood, using the collection.
   neighbours.show();
  }

对如何使这项工作有什么建议吗?我不能使用集合上的show()方法使所需的节点可见吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-17 16:12:39

您只需要使用node.neighborhood(),例如cy.$(':selected').neighborhood().removeClass('hidden')

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28970633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档