1

My Cytoscape is using arbor layout and I've loaded some nodes in initialization process. All worked fine. The nodes was created and moving some time until all stabilizes.

Now, with a button, I've added a new node:

function addNode() {
    var eles = cy.add([
       { group: "nodes", data: { id: 'zz', name: 'MyNewNode', weight: 450, faveColor: '#F5A45D', faveShape: 'rectangle' }, position: { x: 100, y: 100 } },
       { group: "edges", data: { source: 'zz', target: 'a', faveColor: '#F5A45D', strength: 1 } }
    ]);
}

But, as you can see, I need to specify the position of new node. How can I force all nodes to reacomodate, so I can add other nodes without concern about positions?

Magno C
  • 1,922
  • 4
  • 28
  • 53
  • Nevermind. I found this http://stackoverflow.com/questions/18391899/how-to-reload-graph-in-cytoscape-js and try `cy.load( cy.elements('*').jsons() );` with success. – Magno C Jul 06 '14 at 01:08
  • 1
    `cy.load()` just runs the layout after adding the nodes. So you could alternatively add nodes at arbitrary positions and apply a layout. – maxkfranz Jul 07 '14 at 15:24
  • How can I do that and what is the difference? – Magno C Jul 07 '14 at 17:58
  • `cy.add(eles); cy.layout(opts);` has the same end result more or less than `cy.load()`, but `cy.load()` will introduce more overhead because you're loading a whole new graph rather than modifying the existing one a bit. – maxkfranz Jul 08 '14 at 15:26
  • When I do `cy.add(eles)` I must concern each element position and I do not want to do that. My solution is to use laytout type `arbor`, add an element and do a `load()` with same content. So, the arbor will rearrange the elements in best position and keeps the layout nice.. – Magno C Jul 08 '14 at 19:13
  • If you use a layout for positioning, you can safely add elements with an arbitrary position -- like `{ x: 0, y: 0 }` -- and then run the layout. – maxkfranz Jul 09 '14 at 15:37
  • Ok, I understood. My layout don't have positioning. I do not know how many nodes the user will add, because He is in a kind of "node editor". I must use Arbor. Thanks! – Magno C Jul 09 '14 at 18:30

0 Answers0