KeyNotFoundException with MDS layout
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- computer-graphics
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.
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:

- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 317
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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.
More from microsoft/automatic-graph-layout
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
microsoft/automatic-graph-layout#395 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Issue with framework reference in the GraphViewerGDI.nuspecMay be free again @levnach claimed this 259 days ago, and no pull request is open. Open
microsoft/automatic-graph-layout#390 · 6 comments · 2 reactions · 2 assignees ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
microsoft/automatic-graph-layout#389 · 1 comment · 1 reaction ·
All issues in microsoft/automatic-graph-layout
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PCL-Community/PCL-CE#3652 ·
Maintainers usually reply within 1 day
-
area:frontend bug FE P3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
klasolsson81/jobbliggaren#2010 ·
Maintainers usually reply within 1 day
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
area: homeblaze type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
RicoSuter/Namotion.Interceptor#630 ·
Maintainers usually reply within 1 day
-
Akka.Hosting enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100