using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using Microsoft.Research.DynamicDataDisplay; namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes.Numeric { public class CustomBaseNumericLabelProvider : LabelProvider { private double customBase = 2; /// /// Gets or sets the custom base. /// /// The custom base. public double CustomBase { get { return customBase; } set { if (Double.IsNaN(value)) throw new ArgumentException(Strings.Exceptions.CustomBaseTicksProviderBaseIsNaN); if (value <= 0) throw new ArgumentOutOfRangeException(Strings.Exceptions.CustomBaseTicksProviderBaseIsTooSmall); customBase = value; } } /// /// Initializes a new instance of the class. /// public CustomBaseNumericLabelProvider() { } /// /// Initializes a new instance of the class. /// public CustomBaseNumericLabelProvider(double customBase) : this() { CustomBase = customBase; } /// /// Initializes a new instance of the class. /// /// The custom base. /// The custom base string. public CustomBaseNumericLabelProvider(double customBase, string customBaseString) : this(customBase) { CustomBaseString = customBaseString; } private string customBaseString = null; /// /// Gets or sets the custom base string. /// /// The custom base string. public string CustomBaseString { get { return customBaseString; } set { if (customBaseString != value) { customBaseString = value; RaiseChanged(); } } } protected override string GetStringCore(LabelTickInfo tickInfo) { double value = tickInfo.Tick / customBase; string customBaseStr = customBaseString ?? customBase.ToString(); string result; if (value == 1) result = customBaseStr; else if (value == -1) { result = "-" + customBaseStr; } else result = value.ToString() + customBaseStr; return result; } } }