I want to add more than 10 nodes in arbor.js layout.This code adds nodes and edges in arbor layout for cytoscape
elements: {
nodes: [
{ data : { id: b[0], faveBorderColor: "#AAAAAA", name: b[0], faveColor: "#EEB211", faveFontColor: "#ffffff" ,'link':'http://www.yahoo.com'} },
{ data : { id: a[0], name: a[0], faveColor: "#21526a", faveFontColor: "#fff"} },
{ data : { id: a[1], name: a[1], faveColor: "#21526a", faveFontColor: "#fff"} },
{ data : { id: a[2], name: a[2], faveColor: "#21526a", faveFontColor: "#fff"} },
{ data : { id: a[3], name: a[3], faveColor: "#21526a", faveFontColor: "#fff"} },
{ data : { id: a[4], name: a[4], faveColor: "#21526a", faveFontColor: "#fff"} }
], //end "nodes"
edges: [
{ data : { target: a[0], source : b[0] } },
{ data : { target: a[1], source : b[0]} },
{ data : { target: a[2], source : b[0]} },
{ data : { target: a[3], source : b[0]} },
{ data : { target: a[4], source : b[0]} }
]//end "edges"
},//end "elements"
Now i have 100s of nodes to be added. a[] and b[] are arrays which gets data dynamically through mysql. Is there any chance to loop through nodes, so that all the data can be added dynamically.
You can add elements to the graph in a loop with cy.add():
This will add all nodes from array
aand add an edge to the first element ofb. Nodes are identified by their id and nodes with existing ids are not added again. How you figure out which nodes fromaandbare connected depends on your data structure of course.You can rerun the layout with: