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