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();
    _drawIndexes.clear();
    _oldHighPoints.clear();
    _oldLowPoints.clear();
    _oldStartControlHighPoints.clear();
    _oldEndControlHighPoints.clear();
    return;
  }

  if (series.animationDuration > 0) {
    if (points.isEmpty) {
      _oldHighPoints.clear();
      _oldLowPoints.clear();
      _oldStartControlHighPoints.clear();
      _oldEndControlHighPoints.clear();
      return;
    }

    final int oldPointsLength = _oldHighPoints.length;
    final int newPointsLength = _highPoints.length;
    if (oldPointsLength == newPointsLength) {
      for (int i = 0; i < oldPointsLength; i++) {
        _oldHighPoints[i] = _oldHighPoints[i]
            .lerp(_highPoints[i], segmentAnimationFactor, bottom)!;
        _oldLowPoints[i] = _oldLowPoints[i]
            .lerp(_lowPoints[i], segmentAnimationFactor, bottom)!;
      }
    } else if (oldPointsLength < newPointsLength) {
      for (int i = 0; i < oldPointsLength; i++) {
        _oldHighPoints[i] = _oldHighPoints[i]
            .lerp(_highPoints[i], segmentAnimationFactor, bottom)!;
        _oldLowPoints[i] = _oldLowPoints[i]
            .lerp(_lowPoints[i], segmentAnimationFactor, bottom)!;
      }
      _oldHighPoints.addAll(_highPoints.sublist(oldPointsLength));
      _oldLowPoints.addAll(_lowPoints.sublist(oldPointsLength));
    } else {
      for (int i = 0; i < newPointsLength; i++) {
        _oldHighPoints[i] = _oldHighPoints[i]
            .lerp(_highPoints[i], segmentAnimationFactor, bottom)!;
        _oldLowPoints[i] = _oldLowPoints[i]
            .lerp(_lowPoints[i], segmentAnimationFactor, bottom)!;
      }
      _oldHighPoints.removeRange(newPointsLength, oldPointsLength);
      _oldLowPoints.removeRange(newPointsLength, oldPointsLength);
    }

    final int oldControlPointsLength = _oldStartControlHighPoints.length;
    final int newControlPointsLength = _startControlHighPoints.length;
    if (oldControlPointsLength == newControlPointsLength) {
      for (int i = 0; i < oldControlPointsLength; i++) {
        _oldStartControlHighPoints[i] = _oldStartControlHighPoints[i].lerp(
            _startControlHighPoints[i], segmentAnimationFactor, bottom)!;
        _oldEndControlHighPoints[i] = _oldEndControlHighPoints[i]
            .lerp(_endControlHighPoints[i], segmentAnimationFactor, bottom)!;
      }
    } else if (oldControlPointsLength < newControlPointsLength) {
      for (int i = 0; i < oldControlPointsLength; i++) {
        _oldStartControlHighPoints[i] = _oldStartControlHighPoints[i].lerp(
            _startControlHighPoints[i], segmentAnimationFactor, bottom)!;
        _oldEndControlHighPoints[i] = _oldEndControlHighPoints[i]
            .lerp(_endControlHighPoints[i], segmentAnimationFactor, bottom)!;
      }
      _oldStartControlHighPoints
          .addAll(_startControlHighPoints.sublist(oldControlPointsLength));
      _oldEndControlHighPoints
          .addAll(_endControlHighPoints.sublist(oldControlPointsLength));
    } else {
      for (int i = 0; i < newControlPointsLength; i++) {
        _oldStartControlHighPoints[i] = _oldStartControlHighPoints[i].lerp(
            _startControlHighPoints[i], segmentAnimationFactor, bottom)!;
        _oldEndControlHighPoints[i] = _oldEndControlHighPoints[i]
            .lerp(_endControlHighPoints[i], segmentAnimationFactor, bottom)!;
      }
      _oldStartControlHighPoints.removeRange(
          newControlPointsLength, oldControlPointsLength);
      _oldEndControlHighPoints.removeRange(
          newControlPointsLength, oldControlPointsLength);
    }
  } else {
    _oldHighPoints.clear();
    _oldLowPoints.clear();
    _oldStartControlHighPoints.clear();
    _oldEndControlHighPoints.clear();
  }
}