1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace Microsoft.Research.DynamicDataDisplay.Charts
|
---|
7 | {
|
---|
8 | /// <summary>
|
---|
9 | /// Represents axis with values of type TimeSpan.
|
---|
10 | /// </summary>
|
---|
11 | public class TimeSpanAxis : AxisBase<TimeSpan>
|
---|
12 | {
|
---|
13 | /// <summary>
|
---|
14 | /// Initializes a new instance of the <see cref="TimeSpanAxis"/> class with default values conversion.
|
---|
15 | /// </summary>
|
---|
16 | public TimeSpanAxis()
|
---|
17 | : base(new TimeSpanAxisControl(),
|
---|
18 | DoubleToTimeSpan, TimeSpanToDouble)
|
---|
19 | { }
|
---|
20 |
|
---|
21 | private static readonly long minTicks = TimeSpan.MinValue.Ticks;
|
---|
22 | private static readonly long maxTicks = TimeSpan.MaxValue.Ticks;
|
---|
23 | private static TimeSpan DoubleToTimeSpan(double value)
|
---|
24 | {
|
---|
25 | long ticks = (long)(value * 10000000000L);
|
---|
26 |
|
---|
27 | // todo should we throw an exception if number of ticks is too big or small?
|
---|
28 | if (ticks < minTicks)
|
---|
29 | ticks = minTicks;
|
---|
30 | else if (ticks > maxTicks)
|
---|
31 | ticks = maxTicks;
|
---|
32 |
|
---|
33 | return new TimeSpan(ticks);
|
---|
34 | }
|
---|
35 |
|
---|
36 | private static double TimeSpanToDouble(TimeSpan time)
|
---|
37 | {
|
---|
38 | return time.Ticks / 10000000000.0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /// <summary>
|
---|
42 | /// Sets conversions of axis - functions used to convert values of axis type to and from double values of viewport.
|
---|
43 | /// Sets both ConvertToDouble and ConvertFromDouble properties.
|
---|
44 | /// </summary>
|
---|
45 | /// <param name="min">The minimal viewport value.</param>
|
---|
46 | /// <param name="minValue">The value of axis type, corresponding to minimal viewport value.</param>
|
---|
47 | /// <param name="max">The maximal viewport value.</param>
|
---|
48 | /// <param name="maxValue">The value of axis type, corresponding to maximal viewport value.</param>
|
---|
49 | public override void SetConversion(double min, TimeSpan minValue, double max, TimeSpan maxValue)
|
---|
50 | {
|
---|
51 | var conversion = new TimeSpanToDoubleConversion(min, minValue, max, maxValue);
|
---|
52 |
|
---|
53 | ConvertToDouble = conversion.ToDouble;
|
---|
54 | ConvertFromDouble = conversion.FromDouble;
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|