generateVisibleLabels method

  1. @override
void generateVisibleLabels()
override

Generates the visible axis labels.

Implementation

@override
void generateVisibleLabels() {
  num tempInterval = _visibleRange!.minimum;
  String text;
  final String minimum = tempInterval.toString();
  final num maximumVisibleRange = _visibleRange!.maximum;
  num interval = _visibleRange!.interval;
  interval = interval.toString().split('.').length >= 2
      ? interval.toString().split('.')[1].length == 1 &&
              interval.toString().split('.')[1] == '0'
          ? interval.floor()
          : interval
      : interval;
  _visibleLabels = <AxisLabel>[];
  for (; tempInterval <= maximumVisibleRange; tempInterval += interval) {
    num minimumVisibleRange = tempInterval;
    if (minimumVisibleRange <= maximumVisibleRange &&
        minimumVisibleRange >= _visibleRange!.minimum) {
      final int fractionDigits = (minimum.split('.').length >= 2)
          ? minimum.split('.')[1].toString().length
          : (minimumVisibleRange.toString().split('.').length >= 2)
              ? minimumVisibleRange.toString().split('.')[1].toString().length
              : 0;
      final int fractionDigitValue =
          fractionDigits > 20 ? 20 : fractionDigits;
      minimumVisibleRange = minimumVisibleRange.toString().contains('e')
          ? minimumVisibleRange
          : num.tryParse(
              minimumVisibleRange.toStringAsFixed(fractionDigitValue))!;
      if (minimumVisibleRange.toString().split('.').length > 1) {
        final String str = minimumVisibleRange.toString();
        final List<dynamic> list = str.split('.');
        minimumVisibleRange = double.parse(
            minimumVisibleRange.toStringAsFixed(_numericAxis.decimalPlaces));
        //ignore: unnecessary_null_comparison
        if (list != null &&
            list.length > 1 &&
            (list[1] == '0' ||
                list[1] == '00' ||
                list[1] == '000' ||
                list[1] == '0000' ||
                list[1] == '00000')) {
          minimumVisibleRange = minimumVisibleRange.round();
        }
      }
      text = minimumVisibleRange.toString();
      if (_numericAxis.numberFormat != null) {
        text = _numericAxis.numberFormat!.format(minimumVisibleRange);
      }
      if (_numericAxis.labelFormat != null &&
          _numericAxis.labelFormat != '') {
        text = _numericAxis.labelFormat!.replaceAll(RegExp('{value}'), text);
      }
      text =
          _chartState._chartAxis._primaryYAxisRenderer._isStack100 == true &&
                  _name == _chartState._chartAxis._primaryYAxisRenderer._name
              ? (text + '%')
              : text;
      _triggerLabelRenderEvent(text, tempInterval);
    }
  }

  /// Get the maximum label of width and height in axis.
  _calculateMaximumLabelSize(this, _chartState);
}