using System; using System.Collections.Generic; using System.Windows; using Microsoft.Research.DynamicDataDisplay.Common; namespace Microsoft.Research.DynamicDataDisplay { public static class BoundsHelper { /// Computes bounding rectangle for sequence of points /// Points sequence /// Minimal axis-aligned bounding rectangle public static DataRect GetViewportBounds(IEnumerable viewportPoints) { DataRect bounds = DataRect.Empty; double xMin = Double.PositiveInfinity; double xMax = Double.NegativeInfinity; double yMin = Double.PositiveInfinity; double yMax = Double.NegativeInfinity; foreach (Point p in viewportPoints) { xMin = Math.Min(xMin, p.X); xMax = Math.Max(xMax, p.X); yMin = Math.Min(yMin, p.Y); yMax = Math.Max(yMax, p.Y); } // were some points in collection if (!Double.IsInfinity(xMin)) { bounds = DataRect.Create(xMin, yMin, xMax, yMax); } return bounds; } public static DataRect GetViewportBounds(IEnumerable dataPoints, DataTransform transform) { return GetViewportBounds(dataPoints.DataToViewport(transform)); } } }