Link moves after changing node key

I am using a tree layout. When I insert a new node I’m using a temporary key that gets updated later based on the ID of a record that’s created in a database after the node is created.

When I change the key on the node the link to the node from the parent is drawn incorrectly. When it’s in this state if I scroll the diagram using the overview window or select the node with the mouse and then wiggle it a little bit the link is then fine.

One possibility I have is to change things around so that the we don’t have to change the key. However, is there any other way to get around this problem so that I don’t have to do that? Some way of telling the link to refresh itself?

Thanks.

What kind of model are you using?
How are you modifying the key?
Is there anything else that you are doing when you change the key?

I’m wondering if the relationships are temporarily broken as the key is changing, causing the Diagram (actually, the PartManager) not to be able to figure out which intended relationships for that node are meant to be kept. But after everything has settled down, apparently all of the relationships are correct again.

I’m using a GraphLinksModel. My node data class derives from GraphLinksModelNodeData and my link data class derives from GraphLinksModelLinkData<string, string>.

I’m modifying the Key by setting in the new string to the node data.

I’ve commented out everything else that was happening when the key changes so at this point I’d say that I’m not doing anything else.

But don’t you need to do something else? Don’t you need to modify the “To” key property on your link data? (Or equivalently, call GraphLinksModel.SetLinkToPort.)

Otherwise the link won’t be connecting to the node whose key was modified.

The link is already attached to the node. I tried setting the “To” property on the existing link to the new value and it doesn’t seem to have an effect.

I haven’t tried SetLinkToPort().

You’re modifying the node key and the link(s) “to” and “from” key properties all within a transaction, yes?

Yes, it’s nestled in between calls to StartTransaction() and EndTransaction().

I also just tried calling SetLinkToPort() and it didn’t change the outcome.

I’ll see if I can reproduce the problem in one of the samples.

One other thing that might be relevant. This problem doesn’t happen for the first few child nodes that I insert. It only happens once I have a few present and the diagram is starting to have a horizontal shape.

Is this for Silverlight and is the node off-screen when its data’s key is changed?

It is for Silverlight v2.0.2.5.

The node is on screen and selected when the key is changed.

Also if it matters we are using ports in our node templates.

I set up a Silverlight app that uses TreeLayout. I implemented an action that did:

if (myDiagram.SelectedNode != null) { myDiagram.StartTransaction("change key"); var nodedata = myDiagram.SelectedNode.Data as NodeInfo; String newkey = nodedata.Key + "s"; nodedata.Key = newkey; var linkdata = myDiagram.SelectedNode.LinksInto.First().Data as UniversalLinkData; linkdata.To = newkey; myDiagram.CommitTransaction("change key"); }
This worked reliably.

I also tried an action that added a child to the root node, and had it then modify the key: myDiagram.StartTransaction("insert node"); String k = _nodes.Count.ToString(); _lastNodeData = new NodeInfo() { Key=k }; _nodes.Add(_lastNodeData); _lastLinkData = new UniversalLinkData() { From="A", To=k }; _links.Add(_lastLinkData); myDiagram.CommitTransaction("insert node"); myDiagram.StartTransaction("change key"); String newkey = _lastNodeData.Key + "i"; _lastNodeData.Key = newkey; _lastLinkData.To = newkey; myDiagram.CommitTransaction("change key");
This too worked correctly, even when adding the 30th child. (I also tried combining adding the node and modifying the key in a single transaction, but that also worked as expected.)

So I’m not sure what I should do to reproduce the problem. If you could help by giving me a minimal app that demonstrates the problem, I might be able to make progress on it.

In my focus on trying to find bugs, I forgot to answer one of your questions: “Some way of telling the link to refresh itself?”

The answer is to call Part.InvalidateRelationships() on the Node.

Ok, we’ll try refreshing the link with that call.

If that doesn’t work I think that will be easier to change our code around so that we don’t need to change the key.

Thanks.