CytoscapeJS-显示节点邻居? [英] CytoscapeJS - show node neighborhood?

查看:256
本文介绍了CytoscapeJS-显示节点邻居?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON格式的数据集,其中包含有关节点和边缘的信息,我正在使用这些信息在cytoscapeJS中生成网络图. JSON数据包含节点的id,值,形状,颜色和visibleDisplay属性("element"或"none"),以及 edges 的id,源,目标和标签.我的样式表使用此"visibleDisplay"属性根据需要在第一次初始化 cy 容器时显示/隐藏节点.<​​/p>

我想允许用户取消隐藏节点,并选择显示邻居" .我已经修改了旧代码以使用集合,但仍然无法正常工作:

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()方法使所需的节点可见吗?

解决方案

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

I have a dataset in JSON format containing information about nodes and edges which I am using to generate a network graph in cytoscapeJS. The JSON data contains id, value, shape, colour and visibleDisplay ('element' or 'none') attributes for nodes and id, source, target and label for edges. My stylesheet uses this 'visibleDisplay' property to show/ hide nodes, as needed, when the cy container is first initialised.

I want to allow users to unhide nodes with an option to "Show neighbourhood". I have modified my old code to make use of collections but it still does not work:

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();
  }

Any suggestions on how to make this work ? Can't I use the show() method on the collection to make the required nodes visible ?

解决方案

You need only use node.neighborhood(), e.g. cy.$(':selected').neighborhood().removeClass('hidden').

这篇关于CytoscapeJS-显示节点邻居?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆