copyOldSegmentValues method

  1. @override
void copyOldSegmentValues(
  1. double seriesAnimationFactor,
  2. double segmentAnimationFactor
)
override

Implementation

@override
void copyOldSegmentValues(
    double seriesAnimationFactor, double segmentAnimationFactor) {
  if (series.animationType == AnimationType.loading) {
    points.clear();
    _oldStartControlX = null;
    _oldStartControlY = null;
    _oldEndControlX = null;
    _oldEndControlY = null;
    _oldPoints.clear();
    return;
  }

  if (series.animationDuration > 0) {
    if (points.isEmpty) {
      _oldPoints.clear();
      return;
    }

    final int newPointsLength = points.length;
    final int oldPointsLength = _oldPoints.length;
    if (oldPointsLength == newPointsLength) {
      for (int i = 0; i < newPointsLength; i++) {
        _oldPoints[i] =
            Offset.lerp(_oldPoints[i], points[i], segmentAnimationFactor)!;
      }
    } else {
      final int minLength = min(oldPointsLength, newPointsLength);
      for (int i = 0; i < minLength; i++) {
        _oldPoints[i] =
            Offset.lerp(_oldPoints[i], points[i], segmentAnimationFactor)!;
      }

      if (newPointsLength > oldPointsLength) {
        _oldPoints.addAll(points.sublist(oldPointsLength));
      } else {
        _oldPoints.removeRange(minLength, oldPointsLength);
      }
    }

    _oldStartControlX =
        lerpDouble(_oldStartControlX, startControlX, segmentAnimationFactor);
    _oldStartControlY =
        lerpDouble(_oldStartControlY, startControlY, segmentAnimationFactor);
    _oldEndControlX =
        lerpDouble(_oldEndControlX, endControlX, segmentAnimationFactor);
    _oldEndControlY =
        lerpDouble(_oldEndControlY, endControlY, segmentAnimationFactor);
  } else {
    _oldPoints.clear();
  }
}