[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows;
|
---|
| 6 | using System.ComponentModel;
|
---|
| 7 |
|
---|
| 8 | namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
|
---|
| 9 | {
|
---|
| 10 | /// <summary>
|
---|
| 11 | /// 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.
|
---|
| 12 | /// Probably is better to add to FitToViewConstraints collection of <see cref="Viewport"/>.
|
---|
| 13 | /// </summary>
|
---|
| 14 | public class FollowWidthConstraint : ViewportConstraint
|
---|
| 15 | {
|
---|
| 16 | /// <summary>
|
---|
| 17 | /// Initializes a new instance of the <see cref="FollowWidthConstraint"/> class.
|
---|
| 18 | /// </summary>
|
---|
| 19 | public FollowWidthConstraint() { }
|
---|
| 20 |
|
---|
| 21 | /// <summary>
|
---|
| 22 | /// Initializes a new instance of the <see cref="FollowWidthConstraint"/> class with the given width.
|
---|
| 23 | /// </summary>
|
---|
| 24 | /// <param name="width">The width.</param>
|
---|
| 25 | public FollowWidthConstraint(double width)
|
---|
| 26 | {
|
---|
| 27 | Width = width;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | private double width = 1;
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// Gets or sets the width of result visible rectangle.
|
---|
| 33 | /// Default value is 1.0.
|
---|
| 34 | /// </summary>
|
---|
| 35 | /// <value>The width.</value>
|
---|
| 36 | [DefaultValue(1.0)]
|
---|
| 37 | public double Width
|
---|
| 38 | {
|
---|
| 39 | get { return width; }
|
---|
| 40 | set
|
---|
| 41 | {
|
---|
| 42 | if (width != value)
|
---|
| 43 | {
|
---|
| 44 | width = value;
|
---|
| 45 | RaiseChanged();
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// Applies the constraint.
|
---|
| 52 | /// </summary>
|
---|
| 53 | /// <param name="previousDataRect">Previous data rectangle.</param>
|
---|
| 54 | /// <param name="proposedDataRect">Proposed data rectangle.</param>
|
---|
| 55 | /// <param name="viewport">The viewport, to which current constraint is being applied.</param>
|
---|
| 56 | /// <returns>New changed visible rectangle.</returns>
|
---|
| 57 | public override DataRect Apply(DataRect previousDataRect, DataRect proposedDataRect, Viewport2D viewport)
|
---|
| 58 | {
|
---|
| 59 | if (proposedDataRect.IsEmpty)
|
---|
| 60 | return proposedDataRect;
|
---|
| 61 |
|
---|
| 62 | double followWidth = proposedDataRect.Width;
|
---|
| 63 | if (!viewport.UnitedContentBounds.IsEmpty)
|
---|
| 64 | {
|
---|
| 65 | followWidth = Math.Min(width, viewport.UnitedContentBounds.Width);
|
---|
| 66 | }
|
---|
| 67 | if (followWidth.IsInfinite())
|
---|
| 68 | followWidth = width;
|
---|
| 69 |
|
---|
| 70 | Rect visible = new Rect(proposedDataRect.XMin + proposedDataRect.Width - followWidth, proposedDataRect.YMin, followWidth, proposedDataRect.Height);
|
---|
| 71 |
|
---|
| 72 | return visible;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|