private static object OnCoerceVisible(DependencyObject d, object newValue) { Viewport2D viewport = (Viewport2D)d; DataRect newRect = viewport.CoerceVisible((DataRect)newValue); if (newRect.Width == 0 || newRect.Height == 0 || newRect.IsNaN()) { // doesn't apply rects with zero square return(DependencyProperty.UnsetValue); } else { return(newRect); } }
//bool SizeEqual(Size s1, Size s2, double eps) //{ // double width = Math.Min(s1.Width, s2.Width); // double height = Math.Min(s1.Height, s2.Height); // return Math.Abs(s1.Width - s2.Width) < width * eps && // Math.Abs(s1.Height - s2.Height) < height * eps; //} protected virtual void OnVisibleChanged(DataRect newRect, DataRect oldRect) { if (newRect.Size == oldRect.Size) { var transform = viewport.Transform; offset += oldRect.Location.DataToScreen(transform) - newRect.Location.DataToScreen(transform); if (ManualTranslate) { Update(); } } else { offset = new Vector(); Update(); } }
private static object CoerceContentBounds(DependencyObject d, object value) { DataRect prevBounds = GetContentBounds(d); DataRect currBounds = (DataRect)value; bool approximateComparanceAllowed = GetUsesApproximateContentBoundsComparison(d); bool areClose = approximateComparanceAllowed && currBounds.IsCloseTo(prevBounds, 0.005); if (areClose) { return(DependencyProperty.UnsetValue); } else { return(value); } }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (Marker == null) { return; } if (DataSource == null) // No data is specified { if (canvas != null) { foreach (UIElement child in canvas.Children) { unused.Add(child); } canvas.Children.Clear(); } } else // There is some data { int index = 0; var transform = GetTransform(); using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); DataRect bounds = DataRect.Empty; while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(Marker); if (index >= canvas.Children.Count) { UIElement newMarker; if (unused.Count > 0) { newMarker = unused[unused.Count - 1]; unused.RemoveAt(unused.Count - 1); } else { newMarker = Marker.CreateMarker(); } canvas.Children.Add(newMarker); } Marker.SetMarkerProperties(canvas.Children[index]); bounds.Union(point); Point screenPoint = point.DataToScreen(transform); Marker.SetPosition(canvas.Children[index], screenPoint); index++; } Viewport2D.SetContentBounds(this, bounds); while (index < canvas.Children.Count) { unused.Add(canvas.Children[index]); canvas.Children.RemoveAt(index); } } } }
public static CoordinateTransform FromRects(DataRect visibleRect, Rect screenRect) { CoordinateTransform result = new CoordinateTransform(visibleRect, screenRect); return(result); }
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 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); }
private static bool ValidateVisibleCallback(object value) { DataRect rect = (DataRect)value; return(!rect.IsNaN()); }
public RenderRequest(int requestId, DataRect visible, Rect output) { _requestId = requestId; _visible = visible; _output = output; }
public static Point GetCenter(this DataRect rect) { return(new Point(rect.XMin + rect.Width * 0.5, rect.YMin + rect.Height * 0.5)); }
protected override void OnVisibleChanged(DataRect newRect, DataRect oldRect) { base.OnVisibleChanged(newRect, oldRect); InvalidateVisual(); }
public static DataRect RectZoom(DataRect rect, Point zoomCenter, double ratio) { return(RectZoom(rect, zoomCenter, ratio, ratio)); }
public static DataRect RectZoom(DataRect rect, double horizontalRatio, double verticalRatio) { return(RectZoom(rect, rect.GetCenter(), horizontalRatio, verticalRatio)); }
public static DataRect RectZoom(DataRect rect, double ratio) { return(RectZoom(rect, rect.GetCenter(), ratio)); }
protected abstract DataRect CreateVisibleRect(DataRect rect, double value);
protected override void OnVisibleChanged(DataRect newRect, DataRect oldRect) { base.OnVisibleChanged(newRect, oldRect); CreateRenderTask(newRect, Viewport.Output); InvalidateVisual(); }
public static DataRect ZoomInToCenter(this DataRect rect, double ratio) { return(CoordinateUtilities.RectZoom(rect, rect.GetCenter(), 1 / ratio)); }
protected abstract BitmapSource RenderFrame(DataRect visible, Rect output, RenderRequest renderRequest);
public static DataRect ZoomY(this DataRect rect, Point to, double ratio) { return(CoordinateUtilities.RectZoomY(rect, to, ratio)); }
protected virtual UIElement GetTooltipForPoint(Point point, DataRect visible, Rect output) { return(null); }
public static void SetContentBounds(DependencyObject obj, DataRect value) { obj.SetValue(ContentBoundsProperty, value); }