using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints { /// /// Represents a constraint, which limits the maximal size of 's Visible property. /// public class MaximalSizeConstraint : ViewportConstraint { /// /// Initializes a new instance of the class. /// public MaximalSizeConstraint() { } /// /// Initializes a new instance of the class with the given maximal size of Viewport's Visible. /// /// Maximal size of Viewport's Visible. public MaximalSizeConstraint(double maxSize) { MaxSize = maxSize; } private double maxSize = 1000; /// /// Gets or sets the maximal size of Viewport's Visible. /// The default value is 1000.0. /// /// The size of the max. public double MaxSize { get { return maxSize; } set { if (maxSize != value) { maxSize = value; RaiseChanged(); } } } /// /// Applies the specified old data rect. /// /// The old data rect. /// The new data rect. /// The viewport. /// public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) { bool decreasing = newDataRect.Width < oldDataRect.Width || newDataRect.Height < oldDataRect.Height; if (!decreasing && (newDataRect.Width > maxSize || newDataRect.Height > maxSize)) return oldDataRect; return newDataRect; } } }