Ejemplo n.º 1
0
 public static Rect Zoom(this Rect rect, Point to, double ratio)
 {
     return(CoordinateUtilities.RectZoom(rect, to, ratio));
 }
Ejemplo n.º 2
0
        private Rect CoerceVisible(Rect newVisible)
        {
            if (Plotter == null)
            {
                return(newVisible);
            }

            bool isDefaultValue = newVisible == (Rect)VisibleProperty.DefaultMetadata.DefaultValue;

            if (isDefaultValue)
            {
                newVisible = Rect.Empty;
            }

            if (isDefaultValue && IsFittedToView)
            {
                Rect bounds = Rect.Empty;
                foreach (var g in Plotter.Children)
                {
                    var graph = g as DependencyObject;
                    if (graph != null)
                    {
                        var uiElement = g as UIElement;
                        if (uiElement == null || (uiElement != null && uiElement.Visibility == Visibility.Visible))
                        {
                            bounds.Union((Rect)graph.GetValue(ViewportElement2D.ContentBoundsProperty));
                        }
                    }
                }
                Rect viewportBounds = bounds;
                if (!bounds.IsEmpty)
                {
                    bounds = bounds.DataToViewport(transform);
                }

                //Rect defaultRect = (Rect)VisibleProperty.DefaultMetadata.DefaultValue;
                //if (bounds.Width.IsInfinite())
                //    bounds.Width = defaultRect.Width;
                //if (bounds.Height.IsInfinite())
                //    bounds.Height = defaultRect.Height;
                //if (bounds.X.IsInfinite())
                //    bounds.X = defaultRect.X;
                //if (bounds.Y.IsInfinite())
                //    bounds.Y = defaultRect.Y;

                if (!bounds.IsEmpty)
                {
                    bounds = CoordinateUtilities.RectZoom(bounds, bounds.GetCenter(), clipToBoundsFactor);
                }
                else
                {
                    bounds = (Rect)VisibleProperty.DefaultMetadata.DefaultValue;
                }
                newVisible.Union(bounds);
            }

            if (newVisible.IsEmpty)
            {
                newVisible = (Rect)VisibleProperty.DefaultMetadata.DefaultValue;
            }
            else if (newVisible.Width == 0 || newVisible.Height == 0)
            {
                Rect  defRect = (Rect)VisibleProperty.DefaultMetadata.DefaultValue;
                Size  size    = newVisible.Size;
                Point loc     = newVisible.Location;

                if (newVisible.Width == 0)
                {
                    size.Width = defRect.Width;
                    loc.X     -= size.Width / 2;
                }
                if (newVisible.Height == 0)
                {
                    size.Height = defRect.Height;
                    loc.Y      -= size.Height / 2;
                }

                newVisible = new Rect(loc, size);
            }

            newVisible = ApplyRestrictions(Visible, newVisible);

            // applying transform's data domain restriction
            if (!transform.DataTransform.DataDomain.IsEmpty)
            {
                var newDataRect = newVisible.ViewportToData(transform);
                newDataRect = Rect.Intersect(newDataRect, transform.DataTransform.DataDomain);
                newVisible  = newDataRect.DataToViewport(transform);
            }

            if (newVisible.IsEmpty)
            {
                return(new Rect(0, 0, 1, 1));
            }

            return(newVisible);
        }