1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/OxyPlot/OxyPlot/Manipulators/TrackerManipulator.cs Sat Jun 08 16:53:22 2013 +0000
1.3 @@ -0,0 +1,186 @@
1.4 +// --------------------------------------------------------------------------------------------------------------------
1.5 +// <copyright file="TrackerManipulator.cs" company="OxyPlot">
1.6 +// The MIT License (MIT)
1.7 +//
1.8 +// Copyright (c) 2012 Oystein Bjorke
1.9 +//
1.10 +// Permission is hereby granted, free of charge, to any person obtaining a
1.11 +// copy of this software and associated documentation files (the
1.12 +// "Software"), to deal in the Software without restriction, including
1.13 +// without limitation the rights to use, copy, modify, merge, publish,
1.14 +// distribute, sublicense, and/or sell copies of the Software, and to
1.15 +// permit persons to whom the Software is furnished to do so, subject to
1.16 +// the following conditions:
1.17 +//
1.18 +// The above copyright notice and this permission notice shall be included
1.19 +// in all copies or substantial portions of the Software.
1.20 +//
1.21 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1.22 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1.23 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1.24 +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1.25 +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1.26 +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.27 +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.28 +// </copyright>
1.29 +// <summary>
1.30 +// The tracker manipulator.
1.31 +// </summary>
1.32 +// --------------------------------------------------------------------------------------------------------------------
1.33 +namespace OxyPlot
1.34 +{
1.35 + using OxyPlot.Series;
1.36 +
1.37 + /// <summary>
1.38 + /// Provides a plot control manipulator for tracker functionality.
1.39 + /// </summary>
1.40 + public class TrackerManipulator : ManipulatorBase
1.41 + {
1.42 + /// <summary>
1.43 + /// The current series.
1.44 + /// </summary>
1.45 + private ITrackableSeries currentSeries;
1.46 +
1.47 + /// <summary>
1.48 + /// Initializes a new instance of the <see cref="TrackerManipulator"/> class.
1.49 + /// </summary>
1.50 + /// <param name="plotControl">
1.51 + /// The plot control.
1.52 + /// </param>
1.53 + public TrackerManipulator(IPlotControl plotControl)
1.54 + : base(plotControl)
1.55 + {
1.56 + this.Snap = true;
1.57 + this.PointsOnly = false;
1.58 + }
1.59 +
1.60 + /// <summary>
1.61 + /// Gets or sets a value indicating whether to show tracker on points only (not interpolating).
1.62 + /// </summary>
1.63 + public bool PointsOnly { get; set; }
1.64 +
1.65 + /// <summary>
1.66 + /// Gets or sets a value indicating whether to snap to the nearest point.
1.67 + /// </summary>
1.68 + public bool Snap { get; set; }
1.69 +
1.70 + /// <summary>
1.71 + /// Occurs when a manipulation is complete.
1.72 + /// </summary>
1.73 + /// <param name="e">
1.74 + /// The <see cref="OxyPlot.ManipulationEventArgs"/> instance containing the event data.
1.75 + /// </param>
1.76 + public override void Completed(ManipulationEventArgs e)
1.77 + {
1.78 + base.Completed(e);
1.79 +
1.80 + if (this.currentSeries == null)
1.81 + {
1.82 + return;
1.83 + }
1.84 +
1.85 + this.currentSeries = null;
1.86 + this.PlotControl.HideTracker();
1.87 + }
1.88 +
1.89 + /// <summary>
1.90 + /// Occurs when the input device changes position during a manipulation.
1.91 + /// </summary>
1.92 + /// <param name="e">
1.93 + /// The <see cref="OxyPlot.ManipulationEventArgs"/> instance containing the event data.
1.94 + /// </param>
1.95 + public override void Delta(ManipulationEventArgs e)
1.96 + {
1.97 + base.Delta(e);
1.98 + if (this.currentSeries == null)
1.99 + {
1.100 + return;
1.101 + }
1.102 +
1.103 + if (!this.PlotControl.ActualModel.PlotArea.Contains(e.CurrentPosition.X, e.CurrentPosition.Y))
1.104 + {
1.105 + return;
1.106 + }
1.107 +
1.108 + TrackerHitResult result = GetNearestHit(this.currentSeries, e.CurrentPosition, this.Snap, this.PointsOnly);
1.109 + if (result != null)
1.110 + {
1.111 + result.PlotModel = this.PlotControl.ActualModel;
1.112 + this.PlotControl.ShowTracker(result);
1.113 + }
1.114 + }
1.115 +
1.116 + /// <summary>
1.117 + /// Gets the cursor for the manipulation.
1.118 + /// </summary>
1.119 + /// <returns>
1.120 + /// The cursor.
1.121 + /// </returns>
1.122 + public override CursorType GetCursorType()
1.123 + {
1.124 + return CursorType.Default;
1.125 + }
1.126 +
1.127 + /// <summary>
1.128 + /// Occurs when an input device begins a manipulation on the plot.
1.129 + /// </summary>
1.130 + /// <param name="e">
1.131 + /// The <see cref="OxyPlot.ManipulationEventArgs"/> instance containing the event data.
1.132 + /// </param>
1.133 + public override void Started(ManipulationEventArgs e)
1.134 + {
1.135 + base.Started(e);
1.136 + this.currentSeries = this.PlotControl.GetSeriesFromPoint(e.CurrentPosition);
1.137 + this.Delta(e);
1.138 + }
1.139 +
1.140 + /// <summary>
1.141 + /// Gets the nearest tracker hit.
1.142 + /// </summary>
1.143 + /// <param name="s">
1.144 + /// The series.
1.145 + /// </param>
1.146 + /// <param name="point">
1.147 + /// The point.
1.148 + /// </param>
1.149 + /// <param name="snap">
1.150 + /// Snap to points.
1.151 + /// </param>
1.152 + /// <param name="pointsOnly">
1.153 + /// Check points only (no interpolation).
1.154 + /// </param>
1.155 + /// <returns>
1.156 + /// A tracker hit result.
1.157 + /// </returns>
1.158 + private static TrackerHitResult GetNearestHit(ITrackableSeries s, ScreenPoint point, bool snap, bool pointsOnly)
1.159 + {
1.160 + if (s == null)
1.161 + {
1.162 + return null;
1.163 + }
1.164 +
1.165 + // Check data points only
1.166 + if (snap || pointsOnly)
1.167 + {
1.168 + TrackerHitResult result = s.GetNearestPoint(point, false);
1.169 + if (result != null)
1.170 + {
1.171 + if (result.Position.DistanceTo(point) < 20)
1.172 + {
1.173 + return result;
1.174 + }
1.175 + }
1.176 + }
1.177 +
1.178 + // Check between data points (if possible)
1.179 + if (!pointsOnly)
1.180 + {
1.181 + TrackerHitResult result = s.GetNearestPoint(point, true);
1.182 + return result;
1.183 + }
1.184 +
1.185 + return null;
1.186 + }
1.187 +
1.188 + }
1.189 +}
1.190 \ No newline at end of file