1

I am pretty much a javascript noob, and very new to cytoscape (but i code in other languages)...

I am trying to use Cytoscape to graph out the servers available in my network. Creating a node per server and their relationship was straightforward actually.

I would like to add the possibility than when I click a node (let's say server12345) that it would open kind of a table with data associated with that server (servertype etc...).

Do you have any idea / examples / guidance on how I could:

  1. add functionality on that click event of a specific node ?
  2. how to create a 'details' table using cytoscope?

Thank you guys so much in advance! (Ps: My first post on StackOverflow...)

Stephanevg
  • 21
  • 2

1 Answers1

3

Nice question.

Firstly, you can capture the click event of cytoscape.js like below

cy.nodes().on('click', function(e){
  var clickedNode = e.target;
  console.log(clickedNode.id());
});

or you can also use the tap event of cytoscape.js

cy.on('tap', 'node', function(evt){
  var node = evt.target;
  console.log( 'tapped ' + node.id() );
});

You can read events section of the documentation for more details

After you capture this event, I see to ways.

1-) Just modify an existing HTML element on the UI. For example in here you can see on the left side there are some other elements.

So you can write your code like

cy.on('tap', 'node', function(evt){
  var node = evt.target;
  document.getElementById('someOtherElementOnUI').innerHTML = JSON.stringfy(node.data());
});

This will simply modify some other UI element (HTML element) and changes its content to the data of the selected node.

2-) You can use some extensions like Cytoscape.js-popper and show data dynamically like a tooltip. You can check my answer https://stackoverflow.com/a/66813720/3209523

canbax
  • 3,432
  • 1
  • 27
  • 44