Make Cytoscape.js Node a Link
Asked Answered
F

3

5

I am using cytoscape.js to make a simple graph network. I'd like each node to contain an href to link to more information, or on hover to display information as well. Is it possible to add this functionality to cytoscape nodes?

Flail answered 12/12, 2016 at 20:28 Comment(1)
Have you reviewed the demos, the linkout demo for example?Rollmop
P
7

First, add href to data tag. like this:

{ data: { id: 'c' , href: 'example.com'} }

Then insert this in script:

cy.on('tap', 'node', function(){
  try { // your browser may block popups
    window.open( this.data('href') );
  } catch(e){ // fall back on url change
    window.location.href = this.data('href');
  }
});     
Prince answered 23/7, 2018 at 16:16 Comment(0)
U
0

You can add information when generating the node like:

data: {id: 'nodeName', label: 'nodeLabel', link: 'your_href'}

Then you could use qtip to display said link or merely make it part of the label.

You can call the link for each node using data(link) for the labels or this.data("link") in qtip:

{selector: 'edge', style: {'label': 'data(link)',}}
Unfrequented answered 12/12, 2016 at 20:50 Comment(0)
C
0

basically like this:

{"selector": "node", "style": {'href link': "https://images.google.com/puppies","width": 50, "height": 5}}
Cuddy answered 21/7, 2022 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.