Question

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.

Was it helpful?

Solution

Is this Cytoscape Web or Cytoscape.js?

In Cytoscape.js,

OTHER TIPS

Change the layout name to "preset", then the positions value will be considered. Ref - http://js.cytoscape.org/#layouts/preset

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top