PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/Numeric/MinorNumericTicksProvider.cs

#
C# | 89 lines | 73 code | 16 blank | 0 comment | 5 complexity | 7d5a7dcd2bc071cd2308b255509a188d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics.CodeAnalysis;
  6. namespace Microsoft.Research.DynamicDataDisplay.Charts
  7. {
  8. public sealed class MinorNumericTicksProvider : ITicksProvider<double>
  9. {
  10. private readonly ITicksProvider<double> parent;
  11. private Range<double>[] ranges;
  12. internal void SetRanges(IEnumerable<Range<double>> ranges)
  13. {
  14. this.ranges = ranges.ToArray();
  15. }
  16. private double[] coeffs;
  17. public double[] Coeffs
  18. {
  19. get { return coeffs; }
  20. set
  21. {
  22. if (value == null)
  23. throw new ArgumentNullException("value");
  24. coeffs = value;
  25. Changed.Raise(this);
  26. }
  27. }
  28. internal MinorNumericTicksProvider(ITicksProvider<double> parent)
  29. {
  30. this.parent = parent;
  31. Coeffs = new double[] { 0.3, 0.3, 0.3, 0.3, 0.6, 0.3, 0.3, 0.3, 0.3 };
  32. }
  33. #region ITicksProvider<double> Members
  34. public event EventHandler Changed;
  35. public ITicksInfo<double> GetTicks(Range<double> range, int ticksCount)
  36. {
  37. if (Coeffs.Length == 0)
  38. return new TicksInfo<double>();
  39. var minorTicks = ranges.Select(r => CreateTicks(r)).SelectMany(m => m);
  40. var res = new TicksInfo<double>();
  41. res.TickSizes = minorTicks.Select(m => m.Value).ToArray();
  42. res.Ticks = minorTicks.Select(m => m.Tick).ToArray();
  43. return res;
  44. }
  45. public MinorTickInfo<double>[] CreateTicks(Range<double> range)
  46. {
  47. double step = (range.Max - range.Min) / (Coeffs.Length + 1);
  48. MinorTickInfo<double>[] res = new MinorTickInfo<double>[Coeffs.Length];
  49. for (int i = 0; i < Coeffs.Length; i++)
  50. {
  51. res[i] = new MinorTickInfo<double>(Coeffs[i], range.Min + step * (i + 1));
  52. }
  53. return res;
  54. }
  55. public int DecreaseTickCount(int ticksCount)
  56. {
  57. return ticksCount;
  58. }
  59. public int IncreaseTickCount(int ticksCount)
  60. {
  61. return ticksCount;
  62. }
  63. public ITicksProvider<double> MinorProvider
  64. {
  65. get { return null; }
  66. }
  67. public ITicksProvider<double> MajorProvider
  68. {
  69. get { return parent; }
  70. }
  71. #endregion
  72. }
  73. }