microsoft / microsoft/automatic-graph-layout
[Question] Vertical node order with subgraphs
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 319
- Avg merge
- 38m
- Merged PRs (30d)
- 1
Description
Hi,
I've just started using this library today, so apologies in advance if this is an RTFM-type question, but when using nested subgraphs, I can't seem to get the nodes to appear in a "topological" (I think it's called) order from top to bottom.
For example, this code:
static void Main(string[] args)
{
var graph = Program.MakeNestedGraph();
var image = new Bitmap(1500, 1000);
var renderer = new GraphRenderer(graph);
renderer.CalculateLayout();
renderer.Render(image);
image.Save("c:\\temp\\example.png", ImageFormat.Png);
}
private static Graph MakeNestedGraph()
{
var graph = new Graph();
var rg = new Subgraph("rg");
var vnet = graph.AddNode("vnet");
var nic = new Subgraph("nic");
var subnet = graph.AddNode("subnet");
var ipcfg = graph.AddNode("ipcfg");
var nsg = graph.AddNode("nsg");
var ipaddr = graph.AddNode("ipaddr");
var vm = graph.AddNode("vm");
graph.RootSubgraph.AddSubgraph(rg);
rg.AddNode(vnet);
rg.AddNode(subnet);
rg.AddSubgraph(nic);
nic.AddNode(ipcfg);
rg.AddNode(nsg);
rg.AddNode(vm);
rg.AddNode(ipaddr);
graph.AddEdge(vnet.Id, subnet.Id);
graph.AddEdge(subnet.Id, ipcfg.Id);
graph.AddEdge(nic.Id, nsg.Id);
graph.AddEdge(nic.Id, vm.Id);
graph.AddEdge(ipcfg.Id, ipaddr.Id);
return graph;
}
generates this image:

but, I'd like the "vnet" and "subnet" nodes to be above the "nic" subgraph (not necessarily aligned directly above, just higher up vertically in the chart).
I thought maybe doing something like this would help:
graph.LayerConstraints.AddUpDownConstraint(vnet, subnet);
graph.LayerConstraints.AddUpDownConstraint(subnet, nic);
graph.LayerConstraints.AddUpDownConstraint(subnet, ipcfg);
but that doesn't seem to make any difference.
Am I missing something obvious? Or could you give some pointers on how to force the "top-to-bottom layout so that all "source" nodes are higher than their "target" nodes (assuming there's no cycles in the graph)?
Thanks,
Mike
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 nested graph from MakeNestedGraph, then trace GraphRenderer.CalculateLayout and the LayerConstraints calls. Check how constraints involving nodes and the nic subgraph affect vertical layers; done means establishing whether the requested top-to-bottom ordering is supported and providing a documented resolution or a validated change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100