PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/ITicksProvider.cs

#
C# | 153 lines | 73 code | 13 blank | 67 comment | 2 complexity | 06201c7a92c7323746555e4b6e9f59dc MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Diagnostics;
  4using System.Linq;
  5using System.Linq.Expressions;
  6using System.Text;
  7using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
  8
  9namespace Microsoft.Research.DynamicDataDisplay.Charts
 10{
 11	/// <summary>
 12	/// Contains information about one minor tick - its value (relative size) and its tick.
 13	/// </summary>
 14	/// <typeparam name="T"></typeparam>
 15	[DebuggerDisplay("{Value} @ {Tick}")]
 16	public struct MinorTickInfo<T>
 17	{
 18		internal MinorTickInfo(double value, T tick)
 19		{
 20			this.value = value;
 21			this.tick = tick;
 22		}
 23
 24		private readonly double value;
 25		private readonly T tick;
 26
 27		public double Value { get { return value; } }
 28		public T Tick { get { return tick; } }
 29
 30		public override string ToString()
 31		{
 32			return String.Format("{0} @ {1}", value, tick);
 33		}
 34	}
 35
 36	/// <summary>
 37	/// Contains data for all generated ticks.
 38	/// Used by TicksLabelProvider.
 39	/// </summary>
 40	/// <typeparam name="T">Type of axis tick.</typeparam>
 41	public interface ITicksInfo<T>
 42	{
 43		/// <summary>
 44		/// Gets the array of axis ticks.
 45		/// </summary>
 46		/// <value>The ticks.</value>
 47		T[] Ticks { get; }
 48		/// <summary>
 49		/// Gets the tick sizes.
 50		/// </summary>
 51		/// <value>The tick sizes.</value>
 52		double[] TickSizes { get; }
 53		/// <summary>
 54		/// Gets the additional information, added to ticks info and specifying range's features.
 55		/// </summary>
 56		/// <value>The info.</value>
 57		object Info { get; }
 58	}
 59
 60	internal class TicksInfo<T> : ITicksInfo<T>
 61	{
 62		private T[] ticks = { };
 63		/// <summary>
 64		/// Gets the array of axis ticks.
 65		/// </summary>
 66		/// <value>The ticks.</value>
 67		public T[] Ticks
 68		{
 69			get { return ticks; }
 70			internal set { ticks = value; }
 71		}
 72
 73		private double[] tickSizes = { };
 74		/// <summary>
 75		/// Gets the tick sizes.
 76		/// </summary>
 77		/// <value>The tick sizes.</value>
 78		public double[] TickSizes
 79		{
 80			get
 81			{
 82				if (tickSizes.Length != ticks.Length)
 83					tickSizes = ArrayExtensions.CreateArray(ticks.Length, 1.0);
 84
 85				return tickSizes;
 86			}
 87			internal set { tickSizes = value; }
 88		}
 89
 90		private object info = null;
 91		/// <summary>
 92		/// Gets the additional information, added to ticks info and specifying range's features.
 93		/// </summary>
 94		/// <value>The info.</value>
 95		public object Info
 96		{
 97			get { return info; }
 98			internal set { info = value; }
 99		}
100
101		private static readonly TicksInfo<T> empty = new TicksInfo<T> { info = null, ticks = new T[0], tickSizes = new double[0] };
102		internal static TicksInfo<T> Empty
103		{
104			get { return empty; }
105		}
106	}
107
108	/// <summary>
109	///	Base interface for ticks generator.
110	/// </summary>
111	/// <typeparam name="T"></typeparam>
112	public interface ITicksProvider<T>
113	{
114		/// <summary>
115		/// Generates ticks for given range and preferred ticks count.
116		/// </summary>
117		/// <param name="range">The range.</param>
118		/// <param name="ticksCount">The ticks count.</param>
119		/// <returns></returns>
120		ITicksInfo<T> GetTicks(Range<T> range, int ticksCount);
121		/// <summary>
122		/// Decreases the tick count.
123		/// Returned value should be later passed as ticksCount parameter to GetTicks method.
124		/// </summary>
125		/// <param name="ticksCount">The ticks count.</param>
126		/// <returns>Decreased ticks count.</returns>
127		int DecreaseTickCount(int ticksCount);
128		/// <summary>
129		/// Increases the tick count.
130		/// Returned value should be later passed as ticksCount parameter to GetTicks method.
131		/// </summary>
132		/// <param name="ticksCount">The ticks count.</param>
133		/// <returns>Increased ticks count.</returns>
134		int IncreaseTickCount(int ticksCount);
135
136		/// <summary>
137		/// Gets the minor ticks provider, used to generate ticks between each two adjacent ticks.
138		/// </summary>
139		/// <value>The minor provider. If there is no minor provider available, returns null.</value>
140		ITicksProvider<T> MinorProvider { get; }
141		/// <summary>
142		/// Gets the major provider, used to generate major ticks - for example, years for common ticks as months.
143		/// </summary>
144		/// <value>The major provider. If there is no major provider available, returns null.</value>
145		ITicksProvider<T> MajorProvider { get; }
146
147		/// <summary>
148		/// Occurs when properties of ticks provider changeds.
149		/// Notifies axis to rebuild its view.
150		/// </summary>
151		event EventHandler Changed;
152	}
153}