microsoft / microsoft/automatic-graph-layout
KeyNotFoundException with MDS layout
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 319
- Avg merge
- 38m
- Merged PRs (30d)
- 1
Description
Hi Lev,
I tried to modify WpfAplicationSample to show MDS layout, and it throws KeyNotFoundException.
Here are my modifications:
diff --git a/GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs b/GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs
index 5a6e6dd..f16ec58 100644
--- a/GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs
+++ b/GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs
@@ -291,6 +291,7 @@ namespace WpfApplicationSample
// //graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.SplineBundling;
// //layout the graph and draw it
Graph graph = new Graph();
+ graph.LayoutAlgorithmSettings=new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings();
graph.AddEdge("47", "58");
graph.AddEdge("70", "71");
@@ -315,11 +316,11 @@ namespace WpfApplicationSample
graph.Attr.LayerDirection = LayerDirection.LR;
//graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear;
- var global = (SugiyamaLayoutSettings) graph.LayoutAlgorithmSettings;
- var local = (SugiyamaLayoutSettings) global.Clone();
- local.Transformation = PlaneTransformation.Rotation(-Math.PI / 2);
+ var global = (Microsoft.Msagl.Layout.MDS.MdsLayoutSettings) graph.LayoutAlgorithmSettings;
+ var local = (Microsoft.Msagl.Layout.MDS.MdsLayoutSettings) global.Clone();
+ //local.Transformation = PlaneTransformation.Rotation(-Math.PI / 2);
subgraph2.LayoutSettings = local; // for Collapsing\Expanding
- global.ClusterSettings.Add(subgraph2, local);
+ //global.ClusterSettings.Add(subgraph2, local);
graphViewer.Graph = graph;
}
The line, which throws exception is:
intEdges.Add(new SimpleIntEdge {Source = nodeIndex[e.Source], Target = nodeIndex[e.Target]});
Checking with debugger, I can see that subgraph2 is missing from nodeIndex dictionary.

I have no idea why it happens specifically with MDS, but doesn't happen with Sugiyama.
Am I doing something wrong, or is there a bug in MDS layout algorithm?
Here's the screenshot of the exception being thrown:

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the exception in GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs using MdsLayoutSettings and the shown subgraph configuration. Start at the SimpleIntEdge construction where nodeIndex[e.Source] and nodeIndex[e.Target] are accessed, then trace how the MDS layout builds nodeIndex and handles subgraph2. Done means the sample no longer throws KeyNotFoundException for this layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100