calculateEmptyPointValue method

  1. @override
void calculateEmptyPointValue(
  1. int pointIndex,
  2. CartesianChartPoint currentPoint, [
  3. CartesianSeriesRenderer? seriesRenderer
])
override

To calculate empty point value for the specific mode.

Implementation

@override
void calculateEmptyPointValue(
    int pointIndex, CartesianChartPoint<dynamic> currentPoint,
    [CartesianSeriesRenderer? seriesRenderer]) {
  final SeriesRendererDetails seriesRendererDetails =
      SeriesHelper.getSeriesRendererDetails(seriesRenderer!);
  final int pointLength = seriesRendererDetails.dataPoints.length - 1;
  final String seriesType = seriesRendererDetails.seriesType;
  final CartesianChartPoint<dynamic> prevPoint =
      seriesRendererDetails.dataPoints[
          seriesRendererDetails.dataPoints.length >= 2 == true
              ? pointLength - 1
              : pointLength];
  if (seriesType.contains('range') ||
          seriesType.contains('hilo') ||
          seriesType == 'candle'
      ? seriesType == 'hiloopenclose' || seriesType == 'candle'
          ? (currentPoint.low == null ||
              currentPoint.high == null ||
              currentPoint.open == null ||
              currentPoint.close == null)
          : (currentPoint.low == null || currentPoint.high == null)
      : currentPoint.y == null) {
    switch (seriesRendererDetails.series.emptyPointSettings.mode) {
      case EmptyPointMode.zero:
        currentPoint.isEmpty = true;
        if (seriesType.contains('range') ||
            seriesType.contains('hilo') ||
            seriesType.contains('candle')) {
          currentPoint.high = 0;
          currentPoint.low = 0;
          if (seriesType == 'hiloopenclose' || seriesType == 'candle') {
            currentPoint.open = 0;
            currentPoint.close = 0;
          }
        } else {
          currentPoint.y = 0;
        }
        break;

      case EmptyPointMode.average:
        if (seriesRenderer is XyDataSeriesRenderer) {
          seriesRendererDetails.calculateAverageModeValue(
              pointIndex, pointLength, currentPoint, prevPoint);
        }
        currentPoint.isEmpty = true;
        break;

      case EmptyPointMode.gap:
        if (seriesType == 'scatter' ||
            seriesType == 'column' ||
            seriesType == 'bar' ||
            seriesType == 'bubble' ||
            seriesType == 'splinearea' ||
            seriesType == 'rangecolumn' ||
            seriesType.contains('hilo') ||
            seriesType.contains('candle') ||
            seriesType == 'rangearea' ||
            seriesType.contains('stacked')) {
          currentPoint.y = pointIndex != 0 &&
                  (!seriesType.contains('stackedcolumn') &&
                      !seriesType.contains('stackedbar'))
              ? prevPoint.y ?? 0
              : 0;
          currentPoint.open = currentPoint.open ?? 0;
          currentPoint.close = currentPoint.close ?? 0;
          currentPoint.isVisible = false;
        } else if (seriesType.contains('line') ||
            seriesType == 'area' ||
            seriesType == 'steparea') {
          if (seriesType == 'splinerangearea') {
            // ignore: prefer_if_null_operators
            currentPoint.low = currentPoint.low == null
                ? pointIndex != 0
                    ? prevPoint.low ?? 0
                    : 0
                : currentPoint.low;
            // ignore: prefer_if_null_operators
            currentPoint.high = currentPoint.high == null
                ? pointIndex != 0
                    ? prevPoint.high ?? 0
                    : 0
                : currentPoint.high;
          } else {
            currentPoint.y = pointIndex != 0 ? prevPoint.y ?? 0 : 0;
          }
        }
        currentPoint.isVisible = false;
        currentPoint.isGap = true;
        break;
      case EmptyPointMode.drop:
        if (seriesType == 'splinerangearea') {
          // ignore: prefer_if_null_operators
          currentPoint.low = currentPoint.low == null
              ? pointIndex != 0
                  ? prevPoint.low ?? 0
                  : 0
              : currentPoint.low;
          // ignore: prefer_if_null_operators
          currentPoint.high = currentPoint.high == null
              ? pointIndex != 0
                  ? prevPoint.high ?? 0
                  : 0
              : currentPoint.high;
        }
        currentPoint.y = pointIndex != 0 &&
                (seriesType != 'area' &&
                    seriesType != 'splinearea' &&
                    seriesType != 'splinerangearea' &&
                    seriesType != 'steparea' &&
                    !seriesType.contains('stackedcolumn') &&
                    !seriesType.contains('stackedbar'))
            ? prevPoint.y ?? 0
            : 0;
        currentPoint.isDrop = true;
        currentPoint.isVisible = false;
        break;
      // ignore: no_default_cases
      default:
        currentPoint.y = 0;
        break;
    }
  }
}