Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node overlap issue by skipping the original node from AutoLayout repositioning #11414

Merged
merged 3 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class LayoutExtensions
/// </summary>
/// <param name="workspace">Workspace on which graph layout will be performed.</param>
/// <param name="reuseUndoRedoGroup">If true, skip initializing new undo action group.</param>
internal static List<GraphLayout.Graph> DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false)
internal static List<GraphLayout.Graph> DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false, bool isNodeAutoComplete = false, Guid? originalNodeGUID = null)
{
if (workspace.Nodes.Count() < 2) return null;

Expand Down Expand Up @@ -50,7 +50,14 @@ public static class LayoutExtensions
// Run layout algorithm for each subgraph
layoutSubgraphs.Skip(1).ToList().ForEach(g => RunLayoutSubgraph(g, isGroupLayout));
AvoidSubgraphOverlap(layoutSubgraphs);
SaveLayoutGraph(workspace, layoutSubgraphs);

if (isNodeAutoComplete)
{
SaveLayoutGraphForNodeAutoComplete(workspace, layoutSubgraphs, originalNodeGUID);
}
else {
SaveLayoutGraph(workspace, layoutSubgraphs);
}

// Restore the workspace model selection information
selection.ToList().ForEach(x => x.Select());
Expand Down Expand Up @@ -426,6 +433,46 @@ private static void SaveLayoutGraph(this WorkspaceModel workspace, List<GraphLay
node.ReportPosition();
workspace.HasUnsavedChanges = true;

double noteOffset = -n.NotesHeight;
foreach (NoteModel note in n.LinkedNotes)
{
if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0)
{
note.X = node.X;
note.Y = node.Y + noteOffset;
noteOffset += note.Height + GraphLayout.Graph.VerticalNoteDistance;
note.ReportPosition();
}
}
}
}
}
/// <summary>
/// This method pushes changes from the GraphLayout.Graph objects
/// back to the workspace models, but only for nodes placed by NodeAutocomplete.
/// </summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both versions of the function are missing comments for input params, do you mind adding them back?

private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel workspace, List<GraphLayout.Graph> layoutSubgraphs, Guid? originalNodeGUID)
{
// Assign coordinates to nodes outside groups
foreach (var node in workspace.Nodes)
{
GraphLayout.Graph graph = layoutSubgraphs
.FirstOrDefault(g => g.FindNode(node.GUID) != null);

if (graph != null)
{
GraphLayout.Node n = graph.FindNode(node.GUID);
double offsetY = graph.OffsetY;
//skipping the original node to avoid jumping of node
if (node.GUID != originalNodeGUID )
{
node.X = n.X;
node.Y = n.Y + n.NotesHeight + offsetY;

}
node.ReportPosition();
workspace.HasUnsavedChanges = true;

double noteOffset = -n.NotesHeight;
foreach (NoteModel note in n.LinkedNotes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ protected virtual void CreateAndConnectToPort(object parameter)
dynamoViewModel.ExecuteCommand(new DynamoModel.CreateAndConnectNodeCommand(id, initialNode.GUID,
Model.CreationName, 0, portModel.Index, adjustedX, 0, createAsDownStreamNode, false, true));

// Clear current selections and select all input nodes as we need to perform Auto layout on only the input nodes.
DynamoSelection.Instance.ClearSelection();
var inputNodes = initialNode.InputNodes.Values.Where(x => x != null).Select(y => y.Item2);

// Clear current selections and select all input nodes as we need to perform Auto layout on only the input nodes.
DynamoSelection.Instance.ClearSelection();
DynamoSelection.Instance.Selection.AddRange(inputNodes);
DynamoSelection.Instance.Selection.Add(initialNode);
}

protected virtual bool CanCreateAndConnectToPort(object parameter)
Expand All @@ -305,8 +306,9 @@ private void AutoLayoutNodes(object sender, EventArgs e)
{
var nodeView = (NodeView) sender;
var dynamoViewModel = nodeView.ViewModel.DynamoViewModel;
var originalNodeId = nodeView.ViewModel.NodeModel.OutputNodes.Values.SelectMany(s => s.Select(t => t.Item2)).Distinct().FirstOrDefault().GUID;

dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true);
dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true, true, originalNodeId);

DynamoSelection.Instance.ClearSelection();

Expand Down