How can I set the start position of nodes in cytoscape.js with cy.load?

user1768233 picture user1768233 · Oct 13, 2013 · Viewed 11.2k times · Source

I am trying to set the start position of my nodes manually but loading them from a JSON structure. If I put the position within the 'nodes' structure it works, however I am trying to add a seperate structure called 'positions:'which I thought should work? See below for an example of the structure.

var graphdata = { nodes: [ { data: { id: 'j', name: 'Jerry', width: 20, height: 20 ,     shape: 'rectangle' }},
                       { data: { id: 't', name: 'Tom', width: 20 , height: 20, shape: 'circle' } },
                       { data: { id: 'm', name: 'Mary', width: 20 , height: 20, shape: 'circle' } } ,
                       { data: { id: 'b', name: 'Bob', width: 20 , height: 20, shape: 'circle' } } ],

              edges: [
                      { data: { source: 'j', target: 't', faveColor: '#6FB1FC', strength: 90 } },
                      { data: { source: 't', target: 'm', faveColor: '#6FB1FC', strength: 90 } },
                      { data: { source: 'm', target: 'b', faveColor: '#6FB1FC', strength: 90 } } ],

             positions: [ { j: { x:100,y:100 } }, 
                          { t: { x:100,y:200 } } ]

Later on I call cy.load(graphdata).

The nodes and edges display fine but the position doesn't seem to be affected at all.

I have also loaded the preset layout.

Thanks.

Answer

maxkfranz picture maxkfranz · Oct 15, 2013

Is this Cytoscape Web or Cytoscape.js?

In Cytoscape.js,