Skip to content

Commit 6c94345

Browse files
authored
Fix node overlap issue by skipping the original node from AutoLayout repositioning (#11414)
* prevent overlap
1 parent 3817035 commit 6c94345

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class LayoutExtensions
2020
/// </summary>
2121
/// <param name="workspace">Workspace on which graph layout will be performed.</param>
2222
/// <param name="reuseUndoRedoGroup">If true, skip initializing new undo action group.</param>
23-
internal static List<GraphLayout.Graph> DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false)
23+
internal static List<GraphLayout.Graph> DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false, bool isNodeAutoComplete = false, Guid? originalNodeGUID = null)
2424
{
2525
if (workspace.Nodes.Count() < 2) return null;
2626

@@ -50,7 +50,14 @@ public static class LayoutExtensions
5050
// Run layout algorithm for each subgraph
5151
layoutSubgraphs.Skip(1).ToList().ForEach(g => RunLayoutSubgraph(g, isGroupLayout));
5252
AvoidSubgraphOverlap(layoutSubgraphs);
53-
SaveLayoutGraph(workspace, layoutSubgraphs);
53+
54+
if (isNodeAutoComplete)
55+
{
56+
SaveLayoutGraphForNodeAutoComplete(workspace, layoutSubgraphs, originalNodeGUID);
57+
}
58+
else {
59+
SaveLayoutGraph(workspace, layoutSubgraphs);
60+
}
5461

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

436+
double noteOffset = -n.NotesHeight;
437+
foreach (NoteModel note in n.LinkedNotes)
438+
{
439+
if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0)
440+
{
441+
note.X = node.X;
442+
note.Y = node.Y + noteOffset;
443+
noteOffset += note.Height + GraphLayout.Graph.VerticalNoteDistance;
444+
note.ReportPosition();
445+
}
446+
}
447+
}
448+
}
449+
}
450+
/// <summary>
451+
/// This method pushes changes from the GraphLayout.Graph objects
452+
/// back to the workspace models, but only for nodes placed by NodeAutocomplete.
453+
/// </summary>
454+
private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel workspace, List<GraphLayout.Graph> layoutSubgraphs, Guid? originalNodeGUID)
455+
{
456+
// Assign coordinates to nodes outside groups
457+
foreach (var node in workspace.Nodes)
458+
{
459+
GraphLayout.Graph graph = layoutSubgraphs
460+
.FirstOrDefault(g => g.FindNode(node.GUID) != null);
461+
462+
if (graph != null)
463+
{
464+
GraphLayout.Node n = graph.FindNode(node.GUID);
465+
double offsetY = graph.OffsetY;
466+
//skipping the original node to avoid jumping of node
467+
if (node.GUID != originalNodeGUID )
468+
{
469+
node.X = n.X;
470+
node.Y = n.Y + n.NotesHeight + offsetY;
471+
472+
}
473+
node.ReportPosition();
474+
workspace.HasUnsavedChanges = true;
475+
429476
double noteOffset = -n.NotesHeight;
430477
foreach (NoteModel note in n.LinkedNotes)
431478
{

src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ protected virtual void CreateAndConnectToPort(object parameter)
286286
dynamoViewModel.ExecuteCommand(new DynamoModel.CreateAndConnectNodeCommand(id, initialNode.GUID,
287287
Model.CreationName, 0, portModel.Index, adjustedX, 0, createAsDownStreamNode, false, true));
288288

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

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

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

309-
dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true);
311+
dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true, true, originalNodeId);
310312

311313
DynamoSelection.Instance.ClearSelection();
312314

0 commit comments

Comments
 (0)