Exemplo n.º 1
0
        private void UpdatePlotRect()
        {
            parentMap = GetParentMap();
            var transform = entireWorld.TransformToVisual(parentMap);
            var lt        = transform.Transform(new Point(0, 0));
            var rb        = transform.Transform(new Point(entireWorld.RenderSize.Width, entireWorld.RenderSize.Height));

            var sw = parentMap.ViewportPointToLocation(new Point(Math.Max(0, lt.X), Math.Min(parentMap.RenderSize.Height, rb.Y)));
            var ne = parentMap.ViewportPointToLocation(new Point(Math.Min(parentMap.RenderSize.Width, rb.X), Math.Max(0, lt.Y)));

            if (lt.X > 0)
            {
                sw.Longitude = -180;
            }
            if (rb.X < parentMap.RenderSize.Width)
            {
                ne.Longitude = 180;
            }
            var newPlotRect = new DataRect(sw.Longitude, YDataTransform.DataToPlot(sw.Latitude),
                                           ne.Longitude, YDataTransform.DataToPlot(ne.Latitude));

            if (Math.Abs(newPlotRect.XMin - PlotOriginX) > 1e-10 ||
                Math.Abs(newPlotRect.YMin - PlotOriginY) > 1e-10 ||
                Math.Abs(newPlotRect.XMax - PlotOriginX - PlotWidth) > 1e-10 ||
                Math.Abs(newPlotRect.YMax - PlotOriginY - PlotHeight) > 1e-10)
            {
                MapLayer.SetPositionRectangle(this, new LocationRect(sw, ne));
                SetPlotRect(newPlotRect);
            }
        }
Exemplo n.º 2
0
 void MapPlotter2D_Loaded(object sender, RoutedEventArgs e)
 {
     parentMap = GetParentMap();
     if (parentMap != null)
     {
         parentMap.Children.Add(entireWorld);
         MapLayer.SetPositionRectangle(entireWorld,
                                       new LocationRect(new Location(-85, -180), new Location(85, 180)));
         parentMap.ViewChangeEnd += new EventHandler <MapEventArgs>(parentMap_ViewChangeEnd);
         MapLayer.SetPositionRectangle(this,
                                       new LocationRect(new Location(-85, -180), new Location(85, 180)));
         SetPlotRect(new DataRect(-180, YDataTransform.DataToPlot(-85), 180, YDataTransform.DataToPlot(85)));
         entireWorld.LayoutUpdated += WorldLayoutUpdated;
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 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 GetVerticalCoordinateFromTick(double tick, double screenSize, Range range)
 {
     return(screenSize - ValueToScreen(YDataTransform.DataToPlot(tick), screenSize, range, IsYAxisReversed));
 }