calculateEmptyPointValue method Null safety

  1. @override
void calculateEmptyPointValue(
  1. int pointIndex,
  2. dynamic currentPoint,
  3. dynamic seriesRenderer
)
inherited

To calculate empty point values if null values are provided

Implementation

@override
void calculateEmptyPointValue(
    int pointIndex, dynamic currentPoint, dynamic seriesRenderer) {
  final List<PointInfo<dynamic>> dataPoints = seriesRenderer._dataPoints;
  final EmptyPointSettings empty = emptyPointSettings;
  final int pointLength = dataPoints.length;
  final PointInfo<dynamic> point = dataPoints[pointIndex];
  if (point.y == null) {
    switch (empty.mode) {
      case EmptyPointMode.average:
        final num previous =
            pointIndex - 1 >= 0 ? dataPoints[pointIndex - 1].y ?? 0 : 0;
        final num next = pointIndex + 1 <= pointLength - 1
            ? dataPoints[pointIndex + 1].y ?? 0
            : 0;
        point.y = (previous + next).abs() / 2;
        point.isVisible = true;
        point.isEmpty = true;
        break;
      case EmptyPointMode.zero:
        point.y = 0;
        point.isVisible = true;
        point.isEmpty = true;
        break;
      case EmptyPointMode.drop:
      case EmptyPointMode.gap:
        point.isEmpty = true;
        point.isVisible = false;
        break;
    }
  }
}