public static Rect Zoom(this Rect rect, Point to, double ratio) { return(CoordinateUtilities.RectZoom(rect, to, ratio)); }
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); }
private DataRect CoerceVisible(DataRect newVisible) { if (Plotter == null) { return newVisible; } bool isDefaultValue = newVisible == (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; if (isDefaultValue) { newVisible = DataRect.Empty; } if (isDefaultValue && IsFittedToView) { // determining content bounds DataRect bounds = DataRect.Empty; foreach (var item in contentBoundsHosts) { var visual = plotter.VisualBindings[item]; if (visual.Visibility == Visibility.Visible) { DataRect contentBounds = (DataRect)visual.GetValue(Viewport2D.ContentBoundsProperty); bounds.UnionFinite(contentBounds); } } DataRect viewportBounds = bounds; ContentBounds = bounds; // applying fit-to-view restrictions bounds = fitToViewRestrictions.Apply(Visible, bounds, this); // enlarging if (!bounds.IsEmpty) { bounds = CoordinateUtilities.RectZoom(bounds, bounds.GetCenter(), clipToBoundsEnlargeFactor); } else { bounds = (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; } newVisible.Union(bounds); } if (newVisible.IsEmpty) { newVisible = (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; } else if (newVisible.Width == 0 || newVisible.Height == 0) { DataRect defRect = (DataRect)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 DataRect(loc, size); } // apply domain restriction newVisible = domainRestriction.Apply(Visible, newVisible, this); // apply other restrictions newVisible = restrictions.Apply(Visible, newVisible, this); // applying transform's data domain restriction if (!transform.DataTransform.DataDomain.IsEmpty) { var newDataRect = newVisible.ViewportToData(transform); newDataRect = DataRect.Intersect(newDataRect, transform.DataTransform.DataDomain); newVisible = newDataRect.DataToViewport(transform); } if (newVisible.IsEmpty) newVisible = new Rect(0, 0, 1, 1); return newVisible; }
protected virtual DataRect CoerceVisible(DataRect newVisible) { if (Plotter == null) { return(newVisible); } bool isDefaultValue = newVisible == (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; if (isDefaultValue) { newVisible = DataRect.Empty; } if (isDefaultValue && IsFittedToView) { // determining content bounds DataRect bounds = DataRect.Empty; foreach (var item in contentBoundsHosts) { IPlotterElement plotterElement = item as IPlotterElement; if (plotterElement == null) { continue; } if (plotterElement.Plotter == null) { continue; } var plotter = (Plotter2D)plotterElement.Plotter; var visual = plotter.VisualBindings[plotterElement]; if (visual.Visibility == Visibility.Visible) { DataRect contentBounds = Viewport2D.GetContentBounds(item); if (contentBounds.Width.IsNaN() || contentBounds.Height.IsNaN()) { continue; } bounds.UnionFinite(contentBounds); } } if (useApproximateContentBoundsComparison) { var intersection = prevContentBounds; intersection.Intersect(bounds); double currSquare = bounds.GetSquare(); double prevSquare = prevContentBounds.GetSquare(); double intersectionSquare = intersection.GetSquare(); double squareTopLimit = 1 + maxContentBoundsComparisonMistake; double squareBottomLimit = 1 - maxContentBoundsComparisonMistake; if (intersectionSquare != 0) { double currRatio = currSquare / intersectionSquare; double prevRatio = prevSquare / intersectionSquare; if (squareBottomLimit < currRatio && currRatio < squareTopLimit && squareBottomLimit < prevRatio && prevRatio < squareTopLimit) { bounds = prevContentBounds; } } } prevContentBounds = bounds; UnitedContentBounds = bounds; // applying fit-to-view constraints bounds = fitToViewConstraints.Apply(Visible, bounds, this); // enlarging if (!bounds.IsEmpty) { bounds = CoordinateUtilities.RectZoom(bounds, bounds.GetCenter(), clipToBoundsEnlargeFactor); } else { bounds = (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; } newVisible.Union(bounds); } if (newVisible.IsEmpty) { newVisible = (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; } else if (newVisible.Width == 0 || newVisible.Height == 0) { DataRect defRect = (DataRect)VisibleProperty.DefaultMetadata.DefaultValue; Size size = newVisible.Size; Point location = newVisible.Location; if (newVisible.Width == 0) { size.Width = defRect.Width; location.X -= size.Width / 2; } if (newVisible.Height == 0) { size.Height = defRect.Height; location.Y -= size.Height / 2; } newVisible = new DataRect(location, size); } // apply domain constraint newVisible = domainConstraint.Apply(Visible, newVisible, this); // apply other restrictions if (enforceConstraints) { newVisible = constraints.Apply(Visible, newVisible, this); } // applying transform's data domain constraint if (!transform.DataTransform.DataDomain.IsEmpty) { var newDataRect = newVisible.ViewportToData(transform); newDataRect = DataRect.Intersect(newDataRect, transform.DataTransform.DataDomain); newVisible = newDataRect.DataToViewport(transform); } if (newVisible.IsEmpty) { newVisible = new Rect(0, 0, 1, 1); } return(newVisible); }
protected virtual 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); }
public static DataRect ZoomInToCenter(this DataRect rect, double ratio) { return(CoordinateUtilities.RectZoom(rect, rect.GetCenter(), 1 / ratio)); }
public static Rect ZoomOutFromCenter(this Rect rect, double ratio) { return(CoordinateUtilities.RectZoom(rect, rect.GetCenter(), ratio)); }