generateVisibleLabels method

  1. @override
void generateVisibleLabels()
override

Generates the visible axis labels.

Implementation

@override
void generateVisibleLabels() {
  _axisDetails.visibleLabels = <AxisLabel>[];
  num tempInterval = _axisDetails.visibleRange!.minimum.ceil();
  num interval = _axisDetails.visibleRange!.interval;
  interval = interval.toString().split('.').length >= 2
      ? interval.toString().split('.')[1].length == 1 &&
              interval.toString().split('.')[1] == '0'
          ? interval.floor()
          : interval.ceil()
      : interval;
  int position;
  num prevInterval;
  String labelText;
  final List<AxisLabel> label = _axisDetails.visibleLabels;
  prevInterval = (label.isNotEmpty)
      ? _axisDetails
          .visibleLabels[_axisDetails.visibleLabels.length - 1].value
      : tempInterval;
  _axisDetails.dateTimeFormat =
      _axisDetails.dateTimeCategoryAxis.dateFormat ??
          getDateTimeLabelFormat(
              this, tempInterval.toInt(), prevInterval.toInt());
  for (;
      tempInterval <= _axisDetails.visibleRange!.maximum;
      tempInterval += interval) {
    if (withInRange(tempInterval, _axisDetails)) {
      position = tempInterval.round();
      if (position <= -1 ||
          (_axisDetails.labels.isNotEmpty &&
              position >= _axisDetails.labels.length)) {
        continue;
      } else if (_axisDetails.labels.isNotEmpty &&
          // ignore: unnecessary_null_comparison
          _axisDetails.labels[position] != null) {
        labelText = _axisDetails.getFormattedLabel(
            _axisDetails.labels[position], _axisDetails.dateFormat);
        _axisDetails.labels[position] = labelText;
      } else {
        continue;
      }
      _axisDetails.triggerLabelRenderEvent(
          labelText,
          tempInterval,
          _axisDetails.actualIntervalType,
          _axisDetails.dateTimeFormat!.pattern);

      /// Here the loop is terminated to avoid the format exception
      /// while there is only one data point in data source.
      if (interval == 0) {
        break;
      }
    }
  }

  /// Get the maximum label of width and height in axis.
  _axisDetails.calculateMaximumLabelSize(this, _axisDetails.stateProperties);
  if (_axisDetails.dateTimeCategoryAxis.multiLevelLabels != null &&
      _axisDetails.dateTimeCategoryAxis.multiLevelLabels!.isNotEmpty) {
    generateMultiLevelLabels(_axisDetails);
    calculateMultiLevelLabelBounds(_axisDetails);
  }
}