internal void DoGraphAutoLayout()
{
if (Nodes.Count() < 2) return;
var selection = DynamoSelection.Instance.Selection;
// Check if all the selected models are groups
bool isGroupLayout = selection.Count > 0 &&
selection.All(x => x is AnnotationModel ||
selection.OfType<AnnotationModel>().Any(g => g.SelectedModels.Contains(x)));
GenerateCombinedGraph(isGroupLayout);
RecordUndoGraphLayout(isGroupLayout);
// Generate subgraphs separately for each cluster
SubgraphClusters.ForEach(
x => GenerateSeparateSubgraphs(new HashSet<GraphLayout.Node>(x)));
// Deselect all nodes
SubgraphClusters.ForEach(c => c.ForEach(x => x.IsSelected = false));
// Run layout algorithm for each subgraph
LayoutSubgraphs.Skip(1).ToList().ForEach(g => RunLayoutSubgraph(g, isGroupLayout));
AvoidSubgraphOverlap();
SaveLayoutGraph();
// Restore the workspace model selection information
selection.ToList().ForEach(x => x.Select());
}