-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different layout every time we run the app #342
Comments
What layout do you use? |
Also make sure that the order of the nodes in the graph is the same. |
I am using a simple I will generate some logs later today to show the behaviour and share the findings here. |
Sorry that it took some time for me to come with an update, but I did a complete refactory on how I was generating the graph. Different from the examples, I was adding the nodes and then adding the edges between them. All the examples create the edges first and work on the node later, if necessary. So, with the current change, I can confirm that the behaviour is not the same: every run there is a different result. To confirm what I was doing, I generated a small log that shows the connections being added to the diagram. Here are the results for two runs. There was no change on the code or the source of the diagrams. I just closed the application and run again. As you can see by the logs, all edges were inserted exactly on the same order. However, this is the diagram generated for the fist run: This is the diagram for the second run: As you can see, even with both diagrams being generated from the same source and on the same order, it seems that there is something happening that results on a different diagram. I tried to play with the And another point that I believe is important to mention is that this is happening in the WPF graph. Please, let me know if there is any other information that you need to help me. Thanks in advance |
The logs are identical. @Cussa, can you do experiment for me? When you have your graph ready, use method graph.Write("fileName") to save the graph to a file. See, that you get an identical file content every time. |
20230328201709.graph.log Here are the files. The I can see that on the file that asked me to generate, the nodes are created in different order. |
Tyring to add more info to help. This is how I am generating my graph: public class Item
{
public Guid Id {get;set;}
public List<Guid> Children {get;set;}
}
...
private List<Item> _list;
private void AddEdges(Graph graph, Guid id)
{
var current = _list.First(x => x.Id == id);
foreach (var child in current.Children)
{
if (graph.Edges.Any(x => x.Source == id.ToString() && x.Target == child.ToString()))
continue;
_sb.AppendLine($"{id} - {child}");
graph.AddEdge(id.ToString(), child.ToString());
AddEdges(graph, child);
}
} |
I hope MSAGL layout is deterministic: when I run TestWpfViewer and reload the same graph I get the same drawing each time. I am not sure what is going on. Can you double check that your data is ordered the same way? |
I checked and yes, it is the same order. The logs that I shared show I was adding the edges in the same order in both cases. Tomorrow I will try to create a small project to reproduce completely the error, so I can share it with you. |
I took the example WPF project and created a small validator for the issue. This is one run: This is another run: Please, let me know if I can share any more info to help with this issue. |
I did more tests here to check if the problem was how I was adding the child items (in theory, I went through a whole "brach" before going to the next one. |
Sorry, I could not get to it yet. As I understand the issue is still open. I suspect the problem is that I use Hashtable. |
Fixed by ede35ec. The reason was the usage of Hashtable in Drawing.Graph. |
I am creating an app that loads some data and draw the graph. However, every time I run the app with the same data, it generates a different graph.
Is there any way to set the layout parameters and make it generate the same layout everytime?
The text was updated successfully, but these errors were encountered: