DateTimeTickTenYear.cs 1003 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Globalization;
  3. namespace ScottPlot.Ticks.DateTimeTickUnits
  4. {
  5. public class DateTimeTickTenYear : DateTimeTickUnitBase
  6. {
  7. public DateTimeTickTenYear(CultureInfo culture, int maxTickCount, int? manualSpacing) : base(culture, maxTickCount, manualSpacing)
  8. {
  9. kind = DateTimeUnit.TenYear;
  10. if (manualSpacing == null)
  11. deltas = new int[] { 1, 2, 5 };
  12. }
  13. protected override DateTime Floor(DateTime value)
  14. {
  15. return new DateTime(value.Year - (value.Year % 10), 1, 1);
  16. }
  17. protected override DateTime Increment(DateTime value, int delta)
  18. {
  19. return value.AddYears(delta * 10);
  20. }
  21. protected override string GetTickLabel(DateTime value)
  22. {
  23. var dt = new DateTime(value.Year, 1, 1);
  24. string localizedLabel = dt.ToString("yyyy", culture); // year only
  25. return localizedLabel + "\n ";
  26. }
  27. }
  28. }