using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.ComponentModel; namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints { /// /// Represents a viewport constraint which modifies x coordinates of result visible rect to be adjacent to the right border of initial rect and have a fixed given width. /// Probably is better to add to FitToViewConstraints collection of . /// public class FollowWidthConstraint : ViewportConstraint { /// /// Initializes a new instance of the class. /// public FollowWidthConstraint() { } /// /// Initializes a new instance of the class with the given width. /// /// The width. public FollowWidthConstraint(double width) { Width = width; } private double width = 1; /// /// Gets or sets the width of result visible rectangle. /// Default value is 1.0. /// /// The width. [DefaultValue(1.0)] public double Width { get { return width; } set { if (width != value) { width = value; RaiseChanged(); } } } /// /// Applies the constraint. /// /// Previous data rectangle. /// Proposed data rectangle. /// The viewport, to which current constraint is being applied. /// New changed visible rectangle. public override DataRect Apply(DataRect previousDataRect, DataRect proposedDataRect, Viewport2D viewport) { if (proposedDataRect.IsEmpty) return proposedDataRect; double followWidth = proposedDataRect.Width; if (!viewport.UnitedContentBounds.IsEmpty) { followWidth = Math.Min(width, viewport.UnitedContentBounds.Width); } if (followWidth.IsInfinite()) followWidth = width; Rect visible = new Rect(proposedDataRect.XMin + proposedDataRect.Width - followWidth, proposedDataRect.YMin, followWidth, proposedDataRect.Height); return visible; } } }