PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 92 lines | 64 code | 9 blank | 19 comment | 9 complexity | 470eec4d1c267cbdfbfc36a433df6e9a 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.Windows;
  6. using Microsoft.Research.DynamicDataDisplay;
  7. namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes.Numeric
  8. {
  9. public class CustomBaseNumericLabelProvider : LabelProvider<double>
  10. {
  11. private double customBase = 2;
  12. /// <summary>
  13. /// Gets or sets the custom base.
  14. /// </summary>
  15. /// <value>The custom base.</value>
  16. public double CustomBase
  17. {
  18. get { return customBase; }
  19. set
  20. {
  21. if (Double.IsNaN(value))
  22. throw new ArgumentException(Strings.Exceptions.CustomBaseTicksProviderBaseIsNaN);
  23. if (value <= 0)
  24. throw new ArgumentOutOfRangeException(Strings.Exceptions.CustomBaseTicksProviderBaseIsTooSmall);
  25. customBase = value;
  26. }
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="CustomBaseNumericLabelProvider"/> class.
  30. /// </summary>
  31. public CustomBaseNumericLabelProvider() { }
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="CustomBaseNumericLabelProvider"/> class.
  34. /// </summary>
  35. public CustomBaseNumericLabelProvider(double customBase)
  36. : this()
  37. {
  38. CustomBase = customBase;
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="CustomBaseNumericLabelProvider"/> class.
  42. /// </summary>
  43. /// <param name="customBase">The custom base.</param>
  44. /// <param name="customBaseString">The custom base string.</param>
  45. public CustomBaseNumericLabelProvider(double customBase, string customBaseString)
  46. : this(customBase)
  47. {
  48. CustomBaseString = customBaseString;
  49. }
  50. private string customBaseString = null;
  51. /// <summary>
  52. /// Gets or sets the custom base string.
  53. /// </summary>
  54. /// <value>The custom base string.</value>
  55. public string CustomBaseString
  56. {
  57. get { return customBaseString; }
  58. set
  59. {
  60. if (customBaseString != value)
  61. {
  62. customBaseString = value;
  63. RaiseChanged();
  64. }
  65. }
  66. }
  67. protected override string GetStringCore(LabelTickInfo<double> tickInfo)
  68. {
  69. double value = tickInfo.Tick / customBase;
  70. string customBaseStr = customBaseString ?? customBase.ToString();
  71. string result;
  72. if (value == 1)
  73. result = customBaseStr;
  74. else if (value == -1)
  75. {
  76. result = "-" + customBaseStr;
  77. }
  78. else
  79. result = value.ToString() + customBaseStr;
  80. return result;
  81. }
  82. }
  83. }