Layout problem

Hi Walter.

I faced the following problem.
Sometimes nodes get stuck together and the diagram looks like this:

But after I recreate Diagram.Model (MyDiagram.Model = new MyGraphLinksModel(…)) it relayouts correctly:

I failed to find certain circumstances of reproducing or discover any sensible reason why it may happen.

Here are some details might be useful to identify the problem:

  1. Model properties

public MyGraphLinksModel(…):base()
LinkCategoryPath = “LinkType”;
GroupNodePath = “Model.ParentStepId”;
NodeIsGroupPath = “Model.IsNotLeaf”;
NodeKeyPath = “Model.Id”;
NodeCategoryPath = “Model.LevelName”;
Modifiable = true;

2) Diagram properties
<go:Diagram Name=“diagram”

NodeTemplate="{StaticResource groupTemplate}"
GroupTemplate="{StaticResource groupTemplate}"
LinkTemplateDictionary="{StaticResource linkTemplateDictionary}"
<Tool:ToolManager WheelBehavior=“ControlZooms,ScrollsVertically” MouseEnabled=“False” />
<Graph:RecipeStepsGraphPartManager />
<Graph:GraphRelinkingTool />

  1. Group.Layout used for inner nodes is LayeredDigraphLayout {LayerSpacing=10, ColumnSpacing=10, ConditionFlags=All}

Node Template is quite long (~150 lines) so I omit it. If you consider it relevant I can provide it as well.

Could you please give me some advice on the reasons of such a strange behavior and the way to fix it?

Under what circumstances do you have the problem?

  1. Diagram control is created and empty (Model == null)
  2. A user selects an item in a list
  3. Some data is loaded according to user’s selection
  4. And then a new Model is created using the data loaded and is assigned to Diagram.Model property:

var model = new RecipeStepsGraphLinksModel((RecipeStepsGraphPartManager)diagram.PartManager,
NodesSource = nodessource,
LinksSource = linkssource,
<span =“Apple-tab-span” style=“line-height: 1.4; white-space: pre;”>
foreach (object linksource in model.LinksSource)
((Wire)linksource).StepDiagramModel = model;
<span =“Apple-tab-span” style=“white-space:pre”>
foreach (NodeData nodesource in nodessource)
nodesource.StepsDiagramModel = model;

     <span style="line-height: 1.4;">diagram.Model = model; </span>
Sometimes it results in "sticking" nodes as shown at the 1st figure. But if the user selects another list item (which means creation of a new Model based on another data) and then select the initial one once again (which means creation of a new Model based on the same data as the 1st time) the diagram looks well as shown at the 2nd figure.

Instead of starting by setting Diagram.Model = null, why not leave it with an empty Model? That is the default value, and you can disable or make the diagram read-only if you like.

Just checked - the initial Model is an empty instance of UniversalGraphLinksModel actually.

But what do I do with the sporadic layout problem? Do you have any thoughts?

First, is this WPF or Silverlight?

I still don’t understand the circumstances under which you get the bad layout of a Group. Does it only happen with the first model that you load (that has nodes in it) during the running of the app? Then whether you reload the same model or you load a new model it’s always good?

If so, I’m wondering if maybe it’s due to the layout happening when some Images had not yet been loaded. Try explicitly setting the Width and Height of your Image elements.

It is SL, sorry for not specifying that.
This issue occurs not only with the 1st model having nodes. Sometimes I load one model and everything goes well, but then I load another one and layout gets bad.
However I’ve tried setting images size explicitly and it changed nothing - the layout still gets spoiled.

OK, so it wasn’t the obvious reason.

If you turn off layout animation, does it improve? Use a Diagram.LayoutManager with Animated=“False”.

looks like it helps. when I turn off the animation the problem does not reproduce.
well, I can leave the animation off.
thank you for your help.

So now the question is: what about your templates and code is it that causes layout animation to sometimes do the wrong thing? I don’t have a good answer for that. But whether you want to spend time helping me pursue this issue is up to you. If turning off layout animation works for you, you don’t have to do anything more.