SilverlightMappingToolBasic.UI.SuperGraph.View.SuperGraphControl.CentraliseNode C# (CSharp) Method

CentraliseNode() private method

private CentraliseNode ( NodeControl nodeControl ) : void
nodeControl SilverlightMappingToolBasic.UI.SuperGraph.View.NodeControlSupportClasses.NodeControl
return void
        private void CentraliseNode(NodeControl nodeControl)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (App.UserStyle == UserStyle.Reader && AllowAutoRealign)
                {
                    AutoRealign();
                }


                var oldLocation = nodeControl.Centre;

                var visibleNodes = GetVisibleNodeControls();

                var locationList = visibleNodes.Select(q => q.Centre).ToList();

                var leftMost = locationList.Min(q => q.X);
                var rightMost = locationList.Max(q => q.X);
                var topMost = locationList.Min(q => q.Y);
                var bottomMost = locationList.Max(q => q.Y);

                var newLocation = oldLocation;

                var widthOffset = GlymaParameters.NodeTextWidth/2 + GlymaParameters.Margin;
                var heightOffset = (nodeControl.TextArea.ActualHeight + 40)/2 + GlymaParameters.Margin;


                if (oldLocation.X <= ActualWidth/Zoom/2 + leftMost - widthOffset)
                {
                    newLocation.X = ActualWidth/Zoom/2 + leftMost - widthOffset;
                }
                else if (oldLocation.X >= rightMost - ActualWidth/Zoom/2 + widthOffset)
                {
                    newLocation.X = rightMost - ActualWidth/Zoom/2 + widthOffset;
                }

                //This make sure if the map is smaller than the display area, it will realign the map to the center
                if (bottomMost - topMost + 80 >= ActualHeight/Zoom)
                {
                    if (oldLocation.Y < ActualHeight/Zoom/2 + topMost - heightOffset &&
                        !oldLocation.Y.Equals(bottomMost))
                    {
                        newLocation.Y = ActualHeight/Zoom/2 + topMost - heightOffset;
                    }
                    else if (oldLocation.Y > bottomMost - ActualHeight/Zoom/2 + heightOffset &&
                             !oldLocation.Y.Equals(topMost))
                    {
                        newLocation.Y = bottomMost - ActualHeight/Zoom/2 + heightOffset;
                    }
                }


                //var leftMostMove = leftMost

                var moveX = ActualWidth/Zoom/2 - MoveGraphTransform.X - newLocation.X;
                var moveY = ActualHeight/Zoom/2 - MoveGraphTransform.Y - newLocation.Y;


                MoveMap(moveX, moveY);
            });
        }
SuperGraphControl