Line | |
---|
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 | internal sealed class DateTimeToDoubleConversion
|
---|
9 | {
|
---|
10 | public DateTimeToDoubleConversion(double min, DateTime minDate, double max, DateTime maxDate)
|
---|
11 | {
|
---|
12 | this.min = min;
|
---|
13 | this.length = max - min;
|
---|
14 | this.ticksMin = minDate.Ticks;
|
---|
15 | this.ticksLength = maxDate.Ticks - ticksMin;
|
---|
16 | }
|
---|
17 |
|
---|
18 | private double min;
|
---|
19 | private double length;
|
---|
20 | private long ticksMin;
|
---|
21 | private long ticksLength;
|
---|
22 |
|
---|
23 | internal DateTime FromDouble(double d)
|
---|
24 | {
|
---|
25 | double ratio = (d - min) / length;
|
---|
26 | long tick = (long)(ticksMin + ticksLength * ratio);
|
---|
27 |
|
---|
28 | tick = MathHelper.Clamp(tick, DateTime.MinValue.Ticks, DateTime.MaxValue.Ticks);
|
---|
29 |
|
---|
30 | return new DateTime(tick);
|
---|
31 | }
|
---|
32 |
|
---|
33 | internal double ToDouble(DateTime dt)
|
---|
34 | {
|
---|
35 | double ratio = (dt.Ticks - ticksMin) / (double)ticksLength;
|
---|
36 | return min + ratio * length;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.