/// <summary> /// Applies the restriction. /// </summary> /// <param name="previousDataRect">Previous data rectangle.</param> /// <param name="proposedDataRect">Proposed data rectangle.</param> /// <param name="viewport">The viewport, to which current restriction is being applied.</param> /// <returns>New changed visible rectangle.</returns> public override DataRect Apply(DataRect previousDataRect, DataRect proposedDataRect, Viewport2D viewport) { Rect output = viewport.Output; if (output.Width == 0 || output.Height == 0) { return(proposedDataRect); } double screenRatio = output.Width / output.Height; double viewportRatio = proposedDataRect.Width / proposedDataRect.Height; double ratio = screenRatio / viewportRatio; double width = proportionRatio * proposedDataRect.Width * ratio; double height = proposedDataRect.Height; if (width < proposedDataRect.Width) { height = proposedDataRect.Height / proportionRatio / ratio; width = proposedDataRect.Width; } Point center = proposedDataRect.GetCenter(); Rect res = RectExtensions.FromCenterSize(center, width, height); return(res); }
public void GetCenter_2() { DataRect rect = new DataRect(0.1, 0.1, 0.4, 0.6); Point center = rect.GetCenter(); Assert.AreEqual(new Point(0.30000000000000004, 0.4), center); }
public void GetCenter() { DataRect rect = new DataRect(new Point(-1.1, -2.1), new Point(1.1, 2.1)); Point center = rect.GetCenter(); Assert.AreEqual(new Point(0, 0), center); }
public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) { double ratio = newDataRect.Width / newDataRect.Height; double coeff = Math.Sqrt(ratio); double newWidth = newDataRect.Width / coeff; double newHeight = newDataRect.Height * coeff; Point center = newDataRect.GetCenter(); DataRect res = DataRect.FromCenterSize(center, newWidth, newHeight); return res; }
public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) { double ratio = newDataRect.Width / newDataRect.Height; double coeff = Math.Sqrt(ratio); double newWidth = newDataRect.Width / coeff; double newHeight = newDataRect.Height * coeff; Point center = newDataRect.GetCenter(); DataRect res = DataRect.FromCenterSize(center, newWidth, newHeight); return(res); }
public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) { DataRect overallBounds = DataRect.Empty; foreach (var chart in viewport.ContentBoundsHosts) { var plotterElement = chart as IPlotterElement; var visual = viewport.Plotter.VisualBindings[plotterElement]; var points = (ReadOnlyCollection<Point>)PointsGraphBase.GetVisiblePoints(visual); if (points != null) { // searching for indices of chart's visible points which are near left and right borders of newDataRect double startX = newDataRect.XMin; double endX = newDataRect.XMax; if (points[0].X > endX || points[points.Count - 1].X < startX) { continue; } int startIndex = -1; // we assume that points are sorted by x values ascending if (startX <= points[0].X) { startIndex = 0; } else { for (int i = 1; i < points.Count - 1; i++) { if (points[i].X <= startX && startX < points[i + 1].X) { startIndex = i; break; } } } int endIndex = points.Count; if (points[points.Count - 1].X < endX) { endIndex = points.Count; } else { for (int i = points.Count - 1; i >= 1; i--) { if (points[i - 1].X <= endX && endX < points[i].X) { endIndex = i; break; } } } Rect bounds = Rect.Empty; for (int i = startIndex; i < endIndex; i++) { bounds.Union(points[i]); } if (startIndex > 0) { Point pt = GetInterpolatedPoint(startX, points[startIndex], points[startIndex - 1]); bounds.Union(pt); } if (endIndex < points.Count - 1) { Point pt = GetInterpolatedPoint(endX, points[endIndex], points[endIndex + 1]); bounds.Union(pt); } overallBounds.Union(bounds); } } if (!overallBounds.IsEmpty) { double y = overallBounds.YMin; double height = overallBounds.Height; if (height == 0) { height = newDataRect.Height; y -= height / 2; } newDataRect = new DataRect(newDataRect.XMin, y, newDataRect.Width, height); newDataRect = DataRectExtensions.ZoomY(newDataRect, newDataRect.GetCenter(), yEnlargeCoeff); } return newDataRect; }
public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) { DataRect overallBounds = DataRect.Empty; foreach (var chart in viewport.ContentBoundsHosts) { var plotterElement = chart as IPlotterElement; var visual = viewport.Plotter.VisualBindings[plotterElement]; var points = (ReadOnlyCollection <Point>)PointsGraphBase.GetVisiblePoints(visual); if (points != null) { // searching for indices of chart's visible points which are near left and right borders of newDataRect double startX = newDataRect.XMin; double endX = newDataRect.XMax; if (points[0].X > endX || points[points.Count - 1].X < startX) { continue; } int startIndex = -1; // we assume that points are sorted by x values ascending if (startX <= points[0].X) { startIndex = 0; } else { for (int i = 1; i < points.Count - 1; i++) { if (points[i].X <= startX && startX < points[i + 1].X) { startIndex = i; break; } } } int endIndex = points.Count; if (points[points.Count - 1].X < endX) { endIndex = points.Count; } else { for (int i = points.Count - 1; i >= 1; i--) { if (points[i - 1].X <= endX && endX < points[i].X) { endIndex = i; break; } } } Rect bounds = Rect.Empty; for (int i = startIndex; i < endIndex; i++) { bounds.Union(points[i]); } if (startIndex > 0) { Point pt = GetInterpolatedPoint(startX, points[startIndex], points[startIndex - 1]); bounds.Union(pt); } if (endIndex < points.Count - 1) { Point pt = GetInterpolatedPoint(endX, points[endIndex], points[endIndex + 1]); bounds.Union(pt); } overallBounds.Union(bounds); } } if (!overallBounds.IsEmpty) { double y = overallBounds.YMin; double height = overallBounds.Height; if (height == 0) { height = newDataRect.Height; y -= height / 2; } newDataRect = new DataRect(newDataRect.XMin, y, newDataRect.Width, height); newDataRect = DataRectExtensions.ZoomY(newDataRect, newDataRect.GetCenter(), yEnlargeCoeff); } return(newDataRect); }
/// <summary> /// Applies the restriction. /// </summary> /// <param name="previousDataRect">Previous data rectangle.</param> /// <param name="proposedDataRect">Proposed data rectangle.</param> /// <param name="viewport">The viewport, to which current restriction is being applied.</param> /// <returns>New changed visible rectangle.</returns> public override DataRect Apply(DataRect previousDataRect, DataRect proposedDataRect, Viewport2D viewport) { Rect output = viewport.Output; if (output.Width == 0 || output.Height == 0) return proposedDataRect; double screenRatio = output.Width / output.Height; double viewportRatio = proposedDataRect.Width / proposedDataRect.Height; double ratio = screenRatio / viewportRatio; double width = proportionRatio * proposedDataRect.Width * ratio; double height = proposedDataRect.Height; if (width < proposedDataRect.Width) { height = proposedDataRect.Height / proportionRatio / ratio; width = proposedDataRect.Width; } Point center = proposedDataRect.GetCenter(); Rect res = RectExtensions.FromCenterSize(center, width, height); return res; }