Layout question

We’re trying to support multiple policies for layouts. One policy involves adding all nodes that exist (even in SubGraphs) to a global layout, except for nodes that are in collapsed SubGraphs. If a SubGraph is collapsed, it participates in the layout as a node. So, if I have 10 nodes not in a SG, 5 nodes in SG-A and 2 in SG-B, and SG-B is collapsed, then SG-B will join all other 15 nodes in a global layout.
This seemed really easy for me to do, but we also need to filter out certain types of links from the layout altogether. I built a recursive algorithm that enters collections if they’re expanded, and adds nodes and links to the global layout.
public static IGoLayoutNetwork LayoutFilter(GoDocument doc, IGoLayoutNetwork net)
But this isn’t working as expected; it seems when the subgraphs are collapsed the links are still being drawn to where they would be if the subgraph is expanded.
This approach works perfectly if I force expand all subgraphs. Unfortunately, we need to support this other layout policy. I’m worried that I don’t completely understand how layouts work. Any ideas?

Thanks, Tyler

Are you sure you aren’t adding nodes and links that are in collapsed subgraphs? After all, unless your subgraphs have their own ports, as opposed to the ports that their child nodes have, your network will naturally consist of links connecting non-subgraph nodes, even though some of those nodes might actually be not visible because they are inside collapsed subgraphs.
You’ll need to make sure that there is just a single network node corresponding to the collapsed subgraph, and that all links connect to that parent subgraph rather than to the (atomic) nodes inside the subgraph.

Thanks Walter. I was apparently adding the links (because links can go in and out of subgraphs) but not the nodes, resulting in interesting behavior.