using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Microsoft.Research.DynamicDataDisplay.Charts { /// /// Represents axis with values of type TimeSpan. /// public class TimeSpanAxis : AxisBase { /// /// Initializes a new instance of the class with default values conversion. /// public TimeSpanAxis() : base(new TimeSpanAxisControl(), DoubleToTimeSpan, TimeSpanToDouble) { } private static readonly long minTicks = TimeSpan.MinValue.Ticks; private static readonly long maxTicks = TimeSpan.MaxValue.Ticks; private static TimeSpan DoubleToTimeSpan(double value) { long ticks = (long)(value * 10000000000L); // todo should we throw an exception if number of ticks is too big or small? if (ticks < minTicks) ticks = minTicks; else if (ticks > maxTicks) ticks = maxTicks; return new TimeSpan(ticks); } private static double TimeSpanToDouble(TimeSpan time) { return time.Ticks / 10000000000.0; } /// /// Sets conversions of axis - functions used to convert values of axis type to and from double values of viewport. /// Sets both ConvertToDouble and ConvertFromDouble properties. /// /// The minimal viewport value. /// The value of axis type, corresponding to minimal viewport value. /// The maximal viewport value. /// The value of axis type, corresponding to maximal viewport value. public override void SetConversion(double min, TimeSpan minValue, double max, TimeSpan maxValue) { var conversion = new TimeSpanToDoubleConversion(min, minValue, max, maxValue); ConvertToDouble = conversion.ToDouble; ConvertFromDouble = conversion.FromDouble; } } }