getFormattedValue1 method

  1. @override
String getFormattedValue1(
  1. double? value
)
override

Implementation

@override
String getFormattedValue1(double? value) {
  int days = value!.toInt();

  int year = determineYear(days);

  int month = determineMonth(days);
  String monthName = _months[month % _months.length];
  String yearName = year.toString();

  if (_controller.painter!.getVisibleXRange() > 30 * 6) {
    return "$monthName $yearName";
  } else {
    int dayOfMonth = determineDayOfMonth(days, month + 12 * (year - 2016));

    String appendix = "th";

    switch (dayOfMonth) {
      case 1:
        appendix = "st";
        break;
      case 2:
        appendix = "nd";
        break;
      case 3:
        appendix = "rd";
        break;
      case 21:
        appendix = "st";
        break;
      case 22:
        appendix = "nd";
        break;
      case 23:
        appendix = "rd";
        break;
      case 31:
        appendix = "st";
        break;
    }

    return dayOfMonth == 0 ? "" : "$dayOfMonth$appendix $monthName";
  }
}