Skip to content
maxkfranz edited this page May 8, 2012 · 5 revisions

cy.load()

Load a graph into Cytoscape Web.

cy.load( eleObjs [, load] [, done] )

eleObjs : The set of elements as plain objects to load into Cytoscape Web
load = function( eventObj ) : A callback function that is called when the graph is loaded
done = function( eventObj ) : A callback function that is called when the initial layout is done running after loading the graph

Details

Note that eleObjs can be specified as an array with each element specifying its group, or alternatively, eleObjs can be specified as a group-indexed map.

Examples

As an array:

cy.load([
  { data: { id: "n1" }, group: "nodes" },
  { data: { id: "n2" }, group: "nodes" },
  { data: { id: "e1", source: "n1", target: "n2" }, group: "edges" }
]);

As a group-indexed map:

cy.load({
  nodes: [
    { data: { id: "n1" } },
    { data: { id: "n2" } }
  ],

  edges: [
    { data: { id: "e1", source: "n1", target: "n2" } }
  ]
});

With specified callbacks:

cy.load([ { data: { id: "n1" }, group: "nodes" } ], function(e){
  console.log("cy loaded elements");
}, function(e){
  console.log("cy laid out elements");
});

This is equivalent to:

cy.one("load", function(e){
  console.log("cy loaded elements");
}).one("layoutdone", function(e){
  console.log("cy laid out elements");
});

cy.load([ { data: { id: "n1" }, group: "nodes" } ]);

Clone this wiki locally