예제 #1
0
        /// <summary>
        /// Computes minimal plot rectangle, which contains all plot rectangles of child elements
        /// </summary>
        /// <returns>Minimal plot rectangle, which contains all plot rectangles of child elements</returns>
        protected override DataRect ComputeBounds()
        {
            if (!IsVisible)
            {
                return(new DataRect(new Range(), new Range()));
            }
            var localPlotRect = DataRect.Empty;

            foreach (UIElement child in Children)
            {
                DependencyObject item = child;
                if (item is ContentPresenter && VisualTreeHelper.GetChildrenCount(item) == 1)
                {
                    item = VisualTreeHelper.GetChild(item, 0);
                }
                double v;
                v = GetX1(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.XSurround(XDataTransform.DataToPlot(v));
                }
                v = GetX2(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.XSurround(XDataTransform.DataToPlot(v));
                }
                v = GetY1(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.YSurround(YDataTransform.DataToPlot(v));
                }
                v = GetY2(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.YSurround(YDataTransform.DataToPlot(v));
                }
                var points = GetPoints(item);
                if (points != null)
                {
                    foreach (var point in points)
                    {
                        localPlotRect.XSurround(XDataTransform.DataToPlot(point.X));
                        localPlotRect.YSurround(YDataTransform.DataToPlot(point.Y));
                    }
                }
            }
            return(localPlotRect);
        }
예제 #2
0
        /// <summary>
        /// Computes minimal plot rectangle, which contains all plot rectangles of child elements
        /// </summary>
        /// <returns>Minimal plot rectangle, which contains all plot rectangles of child elements</returns>
        protected override DataRect ComputeBounds()
        {
            var localPlotRect = DataRect.Empty;

            foreach (UIElement child in Children)
            {
                DependencyObject item = child;
                if (item is ContentPresenter && VisualTreeHelper.GetChildrenCount(item) == 1)
                {
                    item = VisualTreeHelper.GetChild(item, 0);
                }
                double v;
                v = GetX1(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.XSurround(XDataTransform.DataToPlot(v));
                }
                v = GetX2(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.XSurround(XDataTransform.DataToPlot(v));
                }
                v = GetY1(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.YSurround(YDataTransform.DataToPlot(v));
                }
                v = GetY2(item);
                if (!double.IsNaN(v) && !double.IsInfinity(v))
                {
                    localPlotRect.YSurround(YDataTransform.DataToPlot(v));
                }
                IEnumerable <Point> points
                    = this.AutoFitAffectOrigins
                    ? GetPoints(item)
                    : GetPoints(item)?.SkipWhile(p => p.X < this.PlotOriginX);
                if (points != null)
                {
                    foreach (var point in points)
                    {
                        localPlotRect.XSurround(XDataTransform.DataToPlot(point.X));
                        localPlotRect.YSurround(YDataTransform.DataToPlot(point.Y));
                    }
                }
            }
            return(localPlotRect);
        }
예제 #3
0
        /// <summary>
        /// Finds the point nearest to a specified point on a screen.
        /// </summary>
        /// <param name="screenPoint">The point to search nearest for.</param>
        /// <param name="nearest">The out parameter to handle the founded point.</param>
        /// <param name="vd">The out parameter to handle data of founded point.</param>
        /// <returns>Boolen value indicating whether the nearest point was found or not.</returns>
        public bool GetNearestPointAndValue(Point screenPoint, out Point nearest, out double vd)
        {
            nearest = new Point(Double.NaN, Double.NaN);
            vd      = Double.NaN;
            if (data == null || xArr == null || yArr == null)
            {
                return(false);
            }
            Point dataPoint = new Point(XDataTransform.PlotToData(XFromLeft(screenPoint.X)), YDataTransform.PlotToData(YFromTop(screenPoint.Y)));//PlotContext.ScreenToData(screenPoint);
            int   i         = ArrayExtensions.GetNearestIndex(xArr, dataPoint.X);

            if (i < 0)
            {
                return(false);
            }
            int j = ArrayExtensions.GetNearestIndex(yArr, dataPoint.Y);

            if (j < 0)
            {
                return(false);
            }
            if (IsBitmap)
            {
                if (i > 0 && xArr[i - 1] > dataPoint.X)
                {
                    i--;
                }
                if (j > 0 && yArr[j - 1] > dataPoint.Y)
                {
                    j--;
                }
            }
            if (i < data.GetLength(0) && j < data.GetLength(1))
            {
                vd      = data[i, j];
                nearest = new Point(xArr[i], yArr[j]);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// Finds the point nearest to a specified point on a screen.
        /// </summary>
        /// <param name="screenPoint">The point to search nearest for.</param>
        /// <param name="nearest">The out parameter to handle the founded point.</param>
        /// <param name="vd">The out parameter to handle data of founded point.</param>
        /// <returns>Boolen value indicating whether the nearest point was found or not.</returns>
        public bool GetNearestPointAndValue(Point screenPoint, out Point nearest, out double vd)
        {
            nearest = new Point(Double.NaN, Double.NaN);
            vd      = Double.NaN;
            if (DataContainer == null || XArray == null || YArray == null)
            {
                return(false);
            }
            Point dataPoint = new Point(XDataTransform.PlotToData(XFromLeft(screenPoint.X)), YDataTransform.PlotToData(YFromTop(screenPoint.Y)));
            int   i         = ArrayExtensions.GetNearestIndex(XArray, dataPoint.X);

            if (i < 0)
            {
                return(false);
            }
            int j = ArrayExtensions.GetNearestIndex(YArray, dataPoint.Y);

            if (j < 0)
            {
                return(false);
            }
            if (IsBitmap)
            {
                if (i > 0 && XArray[i - 1] > dataPoint.X)
                {
                    i--;
                }
                if (j > 0 && YArray[j - 1] > dataPoint.Y)
                {
                    j--;
                }
            }
            if (i < DataContainer.GetLength(0) && j < DataContainer.GetLength(1))
            {
                vd      = DataContainer[i, j];
                nearest = new Point(XArray[i], YArray[j]);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
        internal void ArrangeChildren(Size finalSize)
        {
            foreach (UIElement child in Children)
            {
                DependencyObject item = child;
                if (item is ContentPresenter && VisualTreeHelper.GetChildrenCount(item) == 1)
                {
                    item = VisualTreeHelper.GetChild(item, 0);
                }

                if (item is Line || item is Polyline)
                {
                    child.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
                }
                else
                {
                    double x1 = GetX1(item);
                    double x2 = GetX2(item);
                    double y1 = GetY1(item);
                    double y2 = GetY2(item);

                    Size desiredSize = Size.Empty;
                    if (double.IsNaN(x1) || double.IsNaN(x2) || double.IsNaN(y1) || double.IsNaN(y2))
                    {
                        desiredSize = child.DesiredSize;
                    }

                    double L = 0.0;
                    if (!double.IsNaN(x1))
                    {
                        if (double.IsNegativeInfinity(x1))
                        {
                            L = 0;
                        }
                        else if (double.IsPositiveInfinity(x1))
                        {
                            L = finalSize.Width;
                        }
                        else
                        {
                            L = LeftFromX(XDataTransform.DataToPlot(x1)); // x1 is not Nan and Inf here
                        }
                    }
                    else
                    {
                        L = (double)item.GetValue(Canvas.LeftProperty);
                    }

                    double W    = 0.0;
                    var    elem = item as FrameworkElement;
                    if (!double.IsNaN(x1) && !double.IsNaN(x2))
                    {
                        double L2 = 0.0;
                        if (double.IsNegativeInfinity(x2))
                        {
                            L2 = 0;
                        }
                        else if (double.IsPositiveInfinity(x2))
                        {
                            L2 = desiredSize.Width;
                        }
                        else
                        {
                            L2 = LeftFromX(XDataTransform.DataToPlot(x2)); // x2 is not Nan and Inf here
                        }
                        if (L2 >= L)
                        {
                            W = L2 - L;
                        }
                        else
                        {
                            W = L - L2;
                            L = L2;
                        }
                    }
                    else if (elem != null || double.IsNaN(W = elem.Width) || double.IsInfinity(W))
                    {
                        W = desiredSize.Width;
                    }

                    double T = 0.0;
                    if (!double.IsNaN(y1))
                    {
                        if (double.IsNegativeInfinity(y1))
                        {
                            T = desiredSize.Height;
                        }
                        else if (double.IsPositiveInfinity(y1))
                        {
                            T = 0;
                        }
                        else
                        {
                            T = TopFromY(YDataTransform.DataToPlot(y1)); // y1 is not Nan and Inf here
                        }
                    }
                    else
                    {
                        T = (double)item.GetValue(Canvas.TopProperty);
                    }

                    double H = 0.0;
                    if (!double.IsNaN(y1) && !double.IsNaN(y2))
                    {
                        double T2 = 0.0;
                        if (double.IsNegativeInfinity(y2))
                        {
                            T2 = desiredSize.Height;
                        }
                        else if (double.IsPositiveInfinity(y2))
                        {
                            T2 = desiredSize.Width;
                        }
                        else
                        {
                            T2 = TopFromY(YDataTransform.DataToPlot(y2)); // y2 is not Nan and Inf here
                        }
                        if (T2 >= T)
                        {
                            H = T2 - T;
                        }
                        else
                        {
                            H = T - T2;
                            T = T2;
                        }
                    }
                    else if (elem != null || double.IsNaN(H = elem.Height) || double.IsInfinity(H))
                    {
                        H = desiredSize.Height;
                    }

                    if (Double.IsNaN(L) || Double.IsInfinity(L) || Double.IsNaN(W) || Double.IsInfinity(W)) // Horizontal data to screen transform fails
                    {
                        L = 0;
                        W = desiredSize.Width;
                    }
                    if (Double.IsNaN(T) || Double.IsInfinity(T) || Double.IsNaN(H) || Double.IsInfinity(H)) // Vertical data to screen transform fails
                    {
                        T = 0;
                        H = desiredSize.Height;
                    }
                    child.Arrange(new Rect(L, T, W, H));
                }
            }
        }
예제 #6
0
        internal void MeasureChildren(Size availableSize)
        {
            foreach (UIElement child in Children)
            {
                DependencyObject item = child;
                if (item is ContentPresenter && VisualTreeHelper.GetChildrenCount(item) == 1)
                {
                    item = VisualTreeHelper.GetChild(item, 0);
                }

                var xy = GetPoints(item);
                if (xy != null)
                {
                    if (item is Polyline)
                    {
                        var line   = (Polyline)item;
                        var points = new PointCollection();
                        foreach (var point in xy)
                        {
                            points.Add(new Point(LeftFromX(XDataTransform.DataToPlot(point.X)), TopFromY(YDataTransform.DataToPlot(point.Y))));
                        }
                        line.Points = points;
                    }
                    else if (item is Polygon)
                    {
                        var p      = (Polygon)item;
                        var points = new PointCollection();
                        foreach (var point in xy)
                        {
                            points.Add(new Point(LeftFromX(XDataTransform.DataToPlot(point.X)), TopFromY(YDataTransform.DataToPlot(point.Y))));
                        }
                        p.Points = points;
                    }
                }
                if (item is Line)
                {
                    var    line = (Line)item;
                    double v;
                    v = GetX1(line);
                    if (!double.IsNaN(v))
                    {
                        if (Double.IsNegativeInfinity(v))
                        {
                            line.X1 = 0;
                        }
                        else if (Double.IsPositiveInfinity(v))
                        {
                            line.X1 = availableSize.Width;
                        }
                        else
                        {
                            line.X1 = LeftFromX(XDataTransform.DataToPlot(v));
                        }
                    }
                    v = GetX2(line);
                    if (!double.IsNaN(v))
                    {
                        if (Double.IsNegativeInfinity(v))
                        {
                            line.X2 = 0;
                        }
                        else if (Double.IsPositiveInfinity(v))
                        {
                            line.X2 = availableSize.Width;
                        }
                        else
                        {
                            line.X2 = LeftFromX(XDataTransform.DataToPlot(v));
                        }
                    }
                    v = GetY1(line);
                    if (!double.IsNaN(v))
                    {
                        if (Double.IsNegativeInfinity(v))
                        {
                            line.Y1 = availableSize.Height;
                        }
                        else if (Double.IsPositiveInfinity(v))
                        {
                            line.Y1 = 0;
                        }
                        else
                        {
                            line.Y1 = TopFromY(YDataTransform.DataToPlot(v));
                        }
                    }
                    v = GetY2(line);
                    if (!double.IsNaN(v))
                    {
                        if (Double.IsNegativeInfinity(v))
                        {
                            line.Y2 = availableSize.Height;
                        }
                        else if (Double.IsPositiveInfinity(v))
                        {
                            line.Y2 = 0;
                        }
                        else
                        {
                            line.Y2 = TopFromY(YDataTransform.DataToPlot(v));
                        }
                    }
                }
                child.Measure(availableSize);
            }
        }
 private double GetHorizontalCoordinateFromTick(double tick, double screenSize, Range range)
 {
     return(ValueToScreen(XDataTransform.DataToPlot(tick), screenSize, range, IsXAxisReversed));
 }