Example #1
0
        private Rect CoerceVisible(Rect newVisible)
        {
            PerformanceCounter.startStopwatch("Coercing visible");
            if (Plotter == null)
            {
                return(newVisible);
            }

            bool isDefaultValue = (newVisible == defaultRect);

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

            //if (isDefaultValue && IsFittedToView)
            if (isDefaultValue)
            {
                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 = CoordinateUtilities.RectZoom(bounds, bounds.GetCenter(), clipToBoundsFactor);
                }
                else
                {
                    bounds = defaultRect;
                }
                newVisible.Union(bounds);
            }

            if (newVisible.IsEmpty)
            {
                newVisible = defaultRect;
            }
            else if (newVisible.Width == 0 || newVisible.Height == 0)
            {
                Rect  defRect = defaultRect;
                Size  size    = new Size(newVisible.Width, newVisible.Height);
                Point loc     = new Point(newVisible.X, newVisible.Y);

                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 = RectExt.Intersect(newDataRect, transform.DataTransform.DataDomain);
                newVisible  = newDataRect.DataToViewport(transform);
            }

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

            //RaisePropertyChangedEvent();
            PerformanceCounter.stopStopwatch("Coercing visible");
            return(newVisible);
        }
Example #2
0
 public override void GetBounds(ref Rect outBounds, Matrix3X3 parentMatrix)
 {
     base.GetBounds(ref outBounds, parentMatrix);
     RectExt.Set(ref outBounds, 0, 0, 0, 0);
 }
Example #3
0
 public void GetClipBounds(out Rect bounds)
 {
     RectExt.Set(ref bounds, _currentClip.X, _currentClip.Y, _currentClip.Width, _currentClip.Height);
 }