Springy/Ajax/JSON Cytoscape.js

425 views
Skip to first unread message

Theresa Becker

unread,
Jun 10, 2015, 3:00:50 PM6/10/15
to cytoscap...@googlegroups.com
Hello!

First let me begin by saying that I am complete newbie to JavaScript, Jquery, Cytoscape.js etc. and I hope this is the appropriate forum. My task is to build a web application using cytoscape.js to create network visualizations. I have been cramming tutorials in trying to get up to speed, and I am having a few issues. Any advice and/or insight is greatly appreciated. 

I am trying to use Springy and it seems like there are two ways to use Springy. One is to set it in layouts after initiating a new 
var cy = window.cy = cytoscape({
      container: document.getElementById('cy'),
 // etc
}); 
 and the other is 

var graph = new Springy.Graph(); 

Considering my end goal is to load in a user provided JSON file via ajax and rawgit, my guess is that the latter is better? 
My next question is then, I am not sure how to loop through json file and create new nodes etc. I have selected Springy since it is a force directed graph that does not seem to require a preset location for the nodes. Is this the case? Here is how I am planning to load the file:

$(function(){
  
  // get exported json from cytoscape desktop via ajax
  var graphP = $.ajax({
    type: 'GET',
    dataType: 'json'
  });


  function initCy( then ){

    var loading = document.getElementById('loading');
    var expJson = then[0];
    //taking out style load
    var styleJson = then[1];
    var elements = expJson.elements;
    console.log(loading )
    loading.classList.add('loaded');
    
   var graph = new Springy.Graph();
  // the below code is psuedo-esque 
     var node = graphP.nodes;
       
  for ( var i in node) {
graph.newNode( {id: 'name'});
};

Any insight as to what I am doing wrong here would be greatly appreciated. 

Thanks for your time and help. 


Max Franz

unread,
Jun 15, 2015, 10:04:12 AM6/15/15
to cytoscap...@googlegroups.com
Simply call the layout as in the example in the docs:


`new Springy.Graph()` will not do anything with Cytoscape.js.
Reply all
Reply to author
Forward
0 new messages