Adding links and refreshing

Hi I am having a couple of issues that I’m sure are my fault somewhere.

I am using a Layered Digraph Layout. I have a GroupTemplate and Nodes inside. The nodes connect to other nodes in another group template. After I add a link between the nodes, the diagram is completely re-drawn and comes up with something like this:

The problem is that the links (arcs) are forming these strange geometries between the nodes, when I want it to be direct from one to the next. After collapsing the group and then expanding it again, the diagram looks much different. This is what I would prefer it to look like at all times:

(Forgetting the issue that I have connected the same nodes multiple times, which I haven’t yet gotten around to blocking.) I have Routing set to “Normal” for the Link Route, so I don’t understand why I am getting the behavior from the first picture (image #1).

For the image above (#2), when I link Material 2 to Material 3, it reverts to a picture that looks like image #1. However when my diagram looks like image #1 and I add links, it continues to look like Image #1 until I collapse/expand the group. When it looks like image #1 and I add links, it completely redraws the diagram to make room for all of these strange geometries. In this case, when I say “like image 1”, I mean that it is similar because the individual links are spread out into the in-direct links.

Question #1: How can I make it so it always looks like image #2, and avoid seeing the weirdness of #1?

While I can understand it is necessary to refresh when I link from Group 1 (Stockpile) to Group 2 (New Destination 1) for the very first time, why is it necessary to completely redraw everything when I add more links between the same groups? It is somewhat distracting for my experience as a user when everything is moving around.

Question #2: Is there anything I can do to stop it from completely re-drawing and modifying the layout, which seems to be caused by the issue from Question #1?

It looks like you are using LayeredDigraphLayout, which separates the links. You could override LayeredDigraphLayout.LayoutLinks() to be a no-op. I suppose the override could be smarter to recognize the cases where you really don’t want that routing and other cases where you do, to avoid links crossing over nodes.

Adding (or removing) a Node (or a Link) invalidates the layout and causes it to be performed again sometime, probably by the end of the transaction. You can set the DiagramLayout.Conditions property to control under what conditions the layout may be invalidated as various changes occur.

Hi Walter
Sorry for the delay, I am still struggling with this issue. What exactly does overriding LayoutLinks() do in this case? When I run it after overriding it (not calling base.LayoutLinks()), it still seems to have the same behavior. I still just find it strange that a simple action like collapsing or expanding the group can result in vastly different link paths.

As for changing DiagramLayout.Conditions - are there any examples of this that I can take a look at?

Thanks for your help!

EDIT: I forgot to link up my diagram.Layout to my modified version with the override LayoutLinks. It’s starting to get where I would like it! The style now always appears as the direct links, rather than the ones that move around other objects and spread them out.

Now, I’m sure your hint at changing the Conditions will probably solve the issue - when I create a node or a link, I would still like to update the layout to respect the topological ordering of the links. Any ideas?

I’m glad the layout is working more the way you’d like it to.

If the behaviors when you make changes to the diagram are the way that you want it, you don’t need to set the layout.Conditions property. I thought you had said that you wanted to have the layout not performed again when the user drew new links. If that’s the case, you want to say something like:

    <local:CustomLayout . . . Conditions="NodeAdded NodeRemoved" />

That prevents the layout from being invalidated when a link is added or removed.

Yes, I guess I seem to be flip-flopping between ideas. Sorry about that.

I am curious if it is possible to get a little more granular control over the updates than just through the conditions in WPF. The main reason is that if there is a link from a node in one group (A) to a node in another group (B), and I add a link between a different node in A to a node in B, then I don’t want to force an update, which will help the diagram from jumping around too much. An update should be forced if there aren’t any existing connections between the groups.

I would override DiagramLayout.InvalidateLayout(LayoutChange reason, Part part) in order to decide not to call the base method because it’s a situation where you do not want to invalidate the layout. In other words, if

part is Link && (reason&LayoutChange.LinkAdded) != 0

then you can look at the Link and decide whether to go ahead and try to invalidate or not. I suppose you probably want to do a similar thing when the reason includes LayoutChange.LinkRemoved.

I hope that all makes sense and that it all works as you would expect.

This is great! Thanks so much for your help, Walter.