PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/DateTime/DateTimeLabelProviderBase.cs

#
C# | 59 lines | 54 code | 5 blank | 0 comment | 1 complexity | b8886bfc861579fae2eec2918afa2f03 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows;
 6using Microsoft.Research.DynamicDataDisplay.Charts.Axes;
 7using System.Globalization;
 8
 9namespace Microsoft.Research.DynamicDataDisplay.Charts
10{
11	public abstract class DateTimeLabelProviderBase : LabelProviderBase<DateTime>
12	{
13		private string dateFormat;
14		protected string DateFormat
15		{
16			get { return dateFormat; }
17			set { dateFormat = value; }
18		}
19
20		protected override string GetStringCore(LabelTickInfo<DateTime> tickInfo)
21		{
22			return tickInfo.Tick.ToString(dateFormat);
23		}
24
25		protected virtual string GetDateFormat(DifferenceIn diff)
26		{
27			string format = null;
28
29			switch (diff)
30			{
31				case DifferenceIn.Year:
32					format = "yyyy";
33					break;
34				case DifferenceIn.Month:
35					format = "MMM";
36					break;
37				case DifferenceIn.Day:
38					format = "%d";
39					break;
40				case DifferenceIn.Hour:
41					format = "HH:mm";
42					break;
43				case DifferenceIn.Minute:
44					format = "%m";
45					break;
46				case DifferenceIn.Second:
47					format = "ss";
48					break;
49				case DifferenceIn.Millisecond:
50					format = "fff";
51					break;
52				default:
53					break;
54			}
55
56			return format;
57		}
58	}
59}