graph moves when insering a new node

5 views
Skip to first unread message

rexme...@gmail.com

unread,
Jun 16, 2009, 9:24:11 AM6/16/09
to BirdEye
I'm having trouble with dymanically inserting new nodes. If after
inserting a node I do not call vgraph.draw(), the new node does not
display in teh correct position. If I do call vgraph.draw(), the whole
node moves to the left. This only happens once.

Code that inserts a node:

private function addNode(evt:ContextMenuEvent):void {
var data:XML = <crt />;
data.@x= evt.mouseTarget.mouseX;
data.@y= evt.mouseTarget.mouseY;
var newlyInstertedNode:IVisualNode=vgraph.createNode(null,data);
vgraph.linkNodes
(vgraph.currentRootVNode,newlyInstertedNode).data=hiddenLink;
vgraph.draw();
}

rexme...@gmail.com

unread,
Jun 16, 2009, 9:52:04 PM6/16/09
to BirdEye
It appears that adding them to the
"model" (vgraph.graph.xmlData) directly is the best way. I have been
using functions like this (adapted from a posting to the mailing
list):

private function addNode(e : MouseEvent) : void {
addToGraph(
<Nodes>
<Node id='nodeA' label='nodeA' color='0xFF0000' size='40' /
>
</Nodes>
);
}

private function addToGraph(newNodes : XML) : void {
vgraph.newNodesDefaultVisible = true;

var nodes : XMLList = newNodes..Node;
var edges : XMLList = newNodes..Edge;
var root : IVisualNode = vgraph.currentRootVNode;

for (var i : Number = 0; i < nodes.length(); i++) {
if (!vgraph.graph.xmlData.children().contains(nodes[i])) {
vgraph.graph.xmlData.appendChild(nodes[i]);
var newNode : IVisualNode = vgraph.createNode(nodes
[i].@id, nodes[i]);
}
}

for (var j : Number = 0; j < edges.length(); j++) {
if (!vgraph.graph.xmlData.children().contains(edges[j])) {
vgraph.graph.xmlData.appendChild(edges[j]);
var fromNode : INode = vgraph.graph.nodeByStringId(edges
[j].@fromID);
var toNode : INode = vgraph.graph.nodeByStringId(edges
[j].@toID);
var newEdge : IVisualEdge = vgraph.linkNodes
(fromNode.vnode, toNode.vnode);
newEdge.data = edges[j];
}
}
vgraph.draw();
}

On Jun 16, 2:24 pm, "rexmedo...@gmail.com" <rexmedo...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages