cytoscape.js - How to add nodes to Dagre layout with Cytoscape -


i trying add nodes dagre graph through cityscape.js. problem nodes not painted. code have:

cy.add({       group: "nodes",       data: { id:"n0",name:"n0",weight: 75 },   });   $.ajax(url).done(function(jsontree){       var newnodes=[];       for(var i=1;i<6;i++){         //var child = jsontree.result[i];         newnodes.push(           { group: "nodes", data: { id: "n"+i, name:"n"+i}},           { group: "edges", data: { id: "e"+i, source: "n0", target: "n"+i } }         );        }       cy.add(newnodes); 

any ideas? have used loaded function reload graph not work. not know if have use specific function reload graph.

thank in advance.

you need add positions new nodes. cytoscape.js docs:

it important note positions of newly added nodes must defined when calling cy.add(). nodes can not placed in graph without valid position — otherwise not displayed.

you'll want for loop:

  var newnodes=[];   for(var i=1;i<6;i++){      newnodes.push(           { group: "nodes",                data: {                  id: "n"+i,                  name:"n"+i               },            //this bit missed: position               position: {                x:25*i,                y:20*i               }            },           { group: "edges",             data: {               id: "e"+i,               source: "testnode",               target: "n"+i             }            }         );       }   cy.add(newnodes); 

here's jsbin showing graph new nodes added dynamically


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -