Skip to content

Commit

Permalink
Annotation fix (#10853)
Browse files Browse the repository at this point in the history
* UpdateBoundaryFromSelection Fix

* Fix

* Comment spelling correction

Co-authored-by: Astul B <[email protected]>
  • Loading branch information
Astul-Betizagasti and astulb authored Jul 8, 2020
1 parent 8cd74d2 commit 0a3615f
Showing 1 changed file with 13 additions and 51 deletions.
64 changes: 13 additions & 51 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,58 +290,33 @@ internal void UpdateBoundaryFromSelection()
var regionY = groupModels.Min(y => y.Y) - ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);

//calculates the distance between the nodes
var xDistance = groupModels.Max(x => x.X) - regionX;
var yDistance = groupModels.Max(x => x.Y) - regionY;

var widthandheight = CalculateWidthAndHeight();

var maxWidth = widthandheight.Item1;
var maxHeight = widthandheight.Item2;
var xDistance = groupModels.Max(x => (x.X + x.Width)) - regionX;
var yDistance = groupModels.Max(x => (x.Y + x.Height)) - regionY;

// InitialTop is to store the Y value without the Textblock height
this.InitialTop = groupModels.Min(y => y.Y);


var region = new Rect2D
{
X = regionX,
Y = regionY,
Width = xDistance + maxWidth + ExtendSize,
Height = yDistance + maxHeight + ExtendSize
Width = xDistance + ExtendSize,
Height = yDistance + ExtendSize
};


//gets the element that reaches the lowest point inside the annotation
var lowestElement = groupModels.Aggregate((element1, element2) => (element1.Y + element1.Height) > (element2.Y + element2.Height) ? element1 : element2);

//If the last model is Node, then increase the height so that
//node border does not overlap with the group
if (lowestElement is NodeModel) region.Height += ExtendYHeight;

this.X = region.X;
this.Y = region.Y;
this.Width = Math.Max(region.Width, TextMaxWidth + ExtendSize);
this.Height = region.Height;

//Calculate the boundary if there is any overlap
ModelBase overlap = null;
foreach (var nodesList in Nodes)
{
if (!region.Contains(nodesList.Rect))
{
overlap = nodesList;
if (overlap.Rect.Top < this.X ||
overlap.Rect.Bottom > region.Bottom) //Overlap in height - increase the region height
{
if (overlap.Rect.Bottom - region.Bottom > 0)
{
this.Height += overlap.Rect.Bottom - region.Bottom + ExtendSize + ExtendYHeight;
}
region.Height = this.Height;
}
if (overlap.Rect.Left < this.Y ||
overlap.Rect.Right > region.Right) //Overlap in width - increase the region width
{
if (overlap.Rect.Right - region.Right > 0)
{
this.Width += overlap.Rect.Right - region.Right + ExtendSize;
}
region.Width = this.Width;
}
}
}

//Initial Height is to store the Actual height of the group.
//that is the height should be the initial height without the textblock height.
if (this.InitialHeight <= 0.0)
Expand All @@ -358,20 +333,7 @@ internal void UpdateBoundaryFromSelection()
/// Group the Models based on Height and Width
/// </summary>
/// <returns> the width and height of the last model </returns>
private Tuple<Double,Double> CalculateWidthAndHeight()
{
var xgroup = Nodes.OrderBy(x => x.X).ToList();
var ygroup = Nodes.OrderBy(x => x.Y).ToList();
double yheight = ygroup.Last().Height;

//If the last model is Node, then increase the height so that
//node border does not overlap with the group
if (ygroup.Last() is NodeModel)
yheight = yheight + ExtendYHeight;

return Tuple.Create(xgroup.Last().Width, yheight);
}

#region Serialization/Deserialization Methods

protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
Expand Down

0 comments on commit 0a3615f

Please sign in to comment.