This method adds nodes to the graph dynamically. BirdEye Code Example
Submitted by Sam Rose on Fri, 01/09/2009 - 21:36
======================= /* * This method adds nodes to the graph dynamically. */ private function addNodesToGraph(newNodes:XML):void { vgraph.newNodesDefaultVisible = true; var nodes:XMLList = newNodes.child("Node"); var edges:XMLList = newNodes.child("Edge"); //Keep track of root node. var root:IVisualNode=vgraph.currentRootVNode; for (var i:Number = 0; i < nodes.length(); i++) { if (graphData.children().contains(nodes[i])) { //trace("Node "+nodes[i].@id+" exists. "); } else { graphData.appendChild(nodes[i]); var newNode:IVisualNode = vgraph.createNode(nodes [i].@id, nodes[i]); } } for (var j:Number = 0; j < edges.length(); j++) { if (graphData.children().contains(edges[j])) { //trace("Edge '"+XML(edges[j]).toXMLString()+"' exists. "); } else { graphData.appendChild(edges[j]); var fromNode:INode = graph.nodeByStringId(edges [j].@fromID); var toNode:INode = graph.nodeByStringId(edges [j].@toID); var newEdge:IVisualEdge = vgraph.linkNodes (fromNode.vnode, toNode.vnode); newEdge.data = edges[j]; } } /* the following kicks it off .... */ vgraph.currentRootVNode = graph.nodeByStringId(XML (newNodes).@rootID).vnode; vgraph.draw(); }
Original location:
- Login to post comments

