generateVisibleLabels method

  1. @override
void generateVisibleLabels()
override

Generates the visible axis labels.

Implementation

@override
void generateVisibleLabels() {
  final ChartAxisRendererDetails axisDetails =
      AxisHelper.getAxisRendererDetails(this);
  final VisibleRange? visibleRange = axisDetails.visibleRange;
  final NumericAxis numericAxis = axisDetails.axis as NumericAxis;
  num tempInterval = visibleRange!.minimum;
  String text;
  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;
  axisDetails.visibleLabels = <AxisLabel>[];
  for (; tempInterval <= maximumVisibleRange; tempInterval += interval) {
    num minimumVisibleRange = tempInterval;
    if (minimumVisibleRange <= maximumVisibleRange &&
        minimumVisibleRange >= visibleRange.minimum) {
      final int fractionDigits =
          (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<String>? list = str.split('.');
        minimumVisibleRange = double.parse(
            minimumVisibleRange.toStringAsFixed(numericAxis.decimalPlaces));
        if (list != null &&
            list.length > 1 &&
            (list[1] == '0' ||
                list[1] == '00' ||
                list[1] == '000' ||
                list[1] == '0000' ||
                list[1] == '00000' ||
                minimumVisibleRange % 1 == 0)) {
          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 = axisDetails.stateProperties.chartAxis.primaryYAxisDetails
                      .isStack100 ==
                  true &&
              axisDetails.name ==
                  axisDetails
                      .stateProperties.chartAxis.primaryYAxisDetails.name
          ? '$text%'
          : text;
      axisDetails.triggerLabelRenderEvent(text, tempInterval);
    }
  }

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