Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs
/// <summary>
/// Update the position and border of the tracker.
/// </summary>
Update the position and border of the tracker.
Update the position and border of the tracker .
private void UpdatePositionAndBorder()
        {
            if (contentContainer == null)
            {
                return;
            }
            var pos = this.Position;
            var lineExtents = this.LineExtents;
            Canvas.SetLeft(this, pos.X);
            Canvas.SetTop(this, pos.Y);
            Control parent = this;
            while (!(parent is Canvas) && parent != null)
            {
                parent = parent.GetVisualParent() as Control;
            }
            if (parent == null)
            {
                return;
            }
            var canvasWidth = parent.Bounds.Width;
            var canvasHeight = parent.Bounds.Height;
            content.Measure(new Size(canvasWidth, canvasHeight));
            content.Arrange(new Rect(0, 0, content.DesiredSize.Width, content.DesiredSize.Height));
            var contentWidth = content.DesiredSize.Width;
            var contentHeight = content.DesiredSize.Height;
            const double MarginLimit = 10;
            var ha = HorizontalAlignment.Center;
            if (CanCenterHorizontally)
            {
                if (pos.X - (contentWidth / 2) < MarginLimit)
                {
                    ha = HorizontalAlignment.Left;
                }
                if (pos.X + (contentWidth / 2) > canvasWidth - MarginLimit)
                {
                    ha = HorizontalAlignment.Right;
                }
            }
            else
            {
                ha = pos.X < canvasWidth / 2 ? HorizontalAlignment.Left : HorizontalAlignment.Right;
            }
            var va = VerticalAlignment.Center;
            if (CanCenterVertically)
            {
                if (pos.Y - (contentHeight / 2) < MarginLimit)
                {
                    va = VerticalAlignment.Top;
                }
                if (ha == HorizontalAlignment.Center)
                {
                    va = VerticalAlignment.Bottom;
                    if (pos.Y - contentHeight < MarginLimit)
                    {
                        va = VerticalAlignment.Top;
                    }
                }
                if (va == VerticalAlignment.Center && pos.Y + (contentHeight / 2) > canvasHeight - MarginLimit)
                {
                    va = VerticalAlignment.Bottom;
                }
                if (va == VerticalAlignment.Top && pos.Y + contentHeight > canvasHeight - MarginLimit)
                {
                    va = VerticalAlignment.Bottom;
                }
            }
            else
            {
                va = pos.Y < canvasHeight / 2 ? VerticalAlignment.Top : VerticalAlignment.Bottom;
            }
            var dx = ha == HorizontalAlignment.Center ? -0.5 : ha == HorizontalAlignment.Left ? 0 : -1;
            var dy = va == VerticalAlignment.Center ? -0.5 : va == VerticalAlignment.Top ? 0 : -1;
            Thickness margin;
            path.Data = ShowPointer
                                 ? CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out margin)
                                 : CreateBorderGeometry(ha, va, contentWidth, contentHeight, out margin);
            content.Margin = margin;
            contentContainer.Measure(new Size(canvasWidth, canvasHeight));
            var contentSize = contentContainer.DesiredSize;
            contentContainer.RenderTransform = new TranslateTransform
                {
                    X = dx * contentSize.Width,
                    Y = dy * contentSize.Height
                };
            if (horizontalLine != null)
            {
                horizontalLine.StartPoint = new Point(lineExtents.Left - pos.X, 0);
                horizontalLine.EndPoint = new Point(lineExtents.Right - pos.X, 0);
            }
            if (verticalLine != null)
            {
                verticalLine.StartPoint = new Point(0, lineExtents.Top - pos.Y);
                verticalLine.EndPoint = new Point(0, lineExtents.Bottom - pos.Y);
            }
        }
private void UpdatePositionAndBorder ( ) { if ( contentContainer == null ) { return ; } var pos = this . Position ; var lineExtents = this . LineExtents ; Canvas . SetLeft ( this , pos . X ) ; Canvas . SetTop ( this , pos . Y ) ; Control parent = this ; while ( ! ( parent is Canvas ) && parent != null ) { parent = parent . GetVisualParent ( ) as Control ; } if ( parent == null ) { return ; } var canvasWidth = parent . Bounds . Width ; var canvasHeight = parent . Bounds . Height ; content . Measure ( new Size ( canvasWidth , canvasHeight ) ) ; content . Arrange ( new Rect ( 0 , 0 , content . DesiredSize . Width , content . DesiredSize . Height ) ) ; var contentWidth = content . DesiredSize . Width ; var contentHeight = content . DesiredSize . Height ; const double MarginLimit = 10 ; var ha = HorizontalAlignment . Center ; if ( CanCenterHorizontally ) { if ( pos . X - ( contentWidth / 2 ) < MarginLimit ) { ha = HorizontalAlignment . Left ; } if ( pos . X + ( contentWidth / 2 ) > canvasWidth - MarginLimit ) { ha = HorizontalAlignment . Right ; } } else { ha = pos . X < canvasWidth / 2 ? HorizontalAlignment . Left : HorizontalAlignment . Right ; } var va = VerticalAlignment . Center ; if ( CanCenterVertically ) { if ( pos . Y - ( contentHeight / 2 ) < MarginLimit ) { va = VerticalAlignment . Top ; } if ( ha == HorizontalAlignment . Center ) { va = VerticalAlignment . Bottom ; if ( pos . Y - contentHeight < MarginLimit ) { va = VerticalAlignment . Top ; } } if ( va == VerticalAlignment . Center && pos . Y + ( contentHeight / 2 ) > canvasHeight - MarginLimit ) { va = VerticalAlignment . Bottom ; } if ( va == VerticalAlignment . Top && pos . Y + contentHeight > canvasHeight - MarginLimit ) { va = VerticalAlignment . Bottom ; } } else { va = pos . Y < canvasHeight / 2 ? VerticalAlignment . Top : VerticalAlignment . Bottom ; } var dx = ha == HorizontalAlignment . Center ? - 0.5 : ha == HorizontalAlignment . Left ? 0 : - 1 ; var dy = va == VerticalAlignment . Center ? - 0.5 : va == VerticalAlignment . Top ? 0 : - 1 ; Thickness margin ; path . Data = ShowPointer ? CreatePointerBorderGeometry ( ha , va , contentWidth , contentHeight , out margin ) : CreateBorderGeometry ( ha , va , contentWidth , contentHeight , out margin ) ; content . Margin = margin ; contentContainer . Measure ( new Size ( canvasWidth , canvasHeight ) ) ; var contentSize = contentContainer . DesiredSize ; contentContainer . RenderTransform = new TranslateTransform { X = dx * contentSize . Width , Y = dy * contentSize . Height } ; if ( horizontalLine != null ) { horizontalLine . StartPoint = new Point ( lineExtents . Left - pos . X , 0 ) ; horizontalLine . EndPoint = new Point ( lineExtents . Right - pos . X , 0 ) ; } if ( verticalLine != null ) { verticalLine . StartPoint = new Point ( 0 , lineExtents . Top - pos . Y ) ; verticalLine . EndPoint = new Point ( 0 , lineExtents . Bottom - pos . Y ) ; } }
Update the position and border of the tracker.
Update the position and border of the tracker .
// throw new InvalidOperationException("The TrackerControl must have a Canvas parent."); // Minimum allowed margins around the tracker