transformValues method

  1. @override
void transformValues()
override

Transforms the x and y values to screen coordinates.

Implementation

@override
void transformValues() {
  if (_xValues.isEmpty || _yValues.isEmpty || _errorBarValues.isEmpty) {
    return;
  }

  _verticalPath.reset();
  _verticalCapPath.reset();
  _horizontalPath.reset();
  _horizontalCapPath.reset();

  final PointToPixelCallback transformX = series.pointToPixelX;
  final PointToPixelCallback transformY = series.pointToPixelY;

  for (int i = 0; i < series.dataCount; i++) {
    double? verticalPositiveX;
    double? verticalPositiveY;
    double? verticalNegativeX;
    double? verticalNegativeY;
    double? horizontalPositiveX;
    double? horizontalPositiveY;
    double? horizontalNegativeX;
    double? horizontalNegativeY;

    final num xValue = _xValues[i];
    final num yValue = _yValues[i];
    final ErrorBarValues errorBarValues = _errorBarValues[i];

    if (animationFactor != 0) {
      final bool isTransposedChart = series.isTransposed;
      _errorBarMidPointX = transformX(xValue, yValue);
      _errorBarMidPointY = transformY(xValue, yValue);
      points.add(Offset(_errorBarMidPointX, _errorBarMidPointY));

      if (errorBarValues.verticalPositiveErrorValue != null) {
        verticalPositiveX =
            transformX(xValue, errorBarValues.verticalPositiveErrorValue!);
        verticalPositiveY =
            transformY(xValue, errorBarValues.verticalPositiveErrorValue!);
        points.add(Offset(verticalPositiveX, verticalPositiveY));
      }

      if (errorBarValues.verticalNegativeErrorValue != null) {
        verticalNegativeX =
            transformX(xValue, errorBarValues.verticalNegativeErrorValue!);
        verticalNegativeY =
            transformY(xValue, errorBarValues.verticalNegativeErrorValue!);
        points.add(Offset(verticalNegativeX, verticalNegativeY));
      }

      if (errorBarValues.horizontalPositiveErrorValue != null) {
        horizontalPositiveX =
            transformX(errorBarValues.horizontalPositiveErrorValue!, yValue);
        horizontalPositiveY =
            transformY(errorBarValues.horizontalPositiveErrorValue!, yValue);
        points.add(Offset(horizontalPositiveX, horizontalPositiveY));
      }

      if (errorBarValues.horizontalNegativeErrorValue != null) {
        horizontalNegativeX =
            transformX(errorBarValues.horizontalNegativeErrorValue!, yValue);
        horizontalNegativeY =
            transformY(errorBarValues.horizontalNegativeErrorValue!, yValue);
        points.add(Offset(horizontalNegativeX, horizontalNegativeY));
      }

      double animatingPoint;
      if (verticalPositiveX != null && verticalPositiveY != null) {
        animatingPoint = isTransposedChart
            ? _errorBarMidPointX +
                ((verticalPositiveX - _errorBarMidPointX) *
                    _effectiveAnimationFactor)
            : _errorBarMidPointY -
                ((_errorBarMidPointY - verticalPositiveY) *
                    _effectiveAnimationFactor);

        _capPointValue = animatingPoint -
            ((animatingPoint -
                    (isTransposedChart
                        ? verticalPositiveX
                        : verticalPositiveY)) *
                animationFactor);

        _calculateVerticalPath(_capPointValue, animationFactor,
            series.capLength!, isTransposedChart);
      }
      if (verticalNegativeX != null && verticalNegativeY != null) {
        animatingPoint = isTransposedChart
            ? _errorBarMidPointX +
                ((verticalNegativeX - _errorBarMidPointX) *
                    _effectiveAnimationFactor)
            : _errorBarMidPointY +
                ((verticalNegativeY - _errorBarMidPointY) *
                    _effectiveAnimationFactor);

        _capPointValue = animatingPoint +
            (((isTransposedChart ? verticalNegativeX : verticalNegativeY) -
                    animatingPoint) *
                animationFactor);

        _calculateVerticalPath(_capPointValue, animationFactor,
            series.capLength!, isTransposedChart);
      }
      if (horizontalPositiveX != null && horizontalPositiveY != null) {
        animatingPoint = isTransposedChart
            ? _errorBarMidPointY -
                ((_errorBarMidPointY - horizontalPositiveY) *
                    _effectiveAnimationFactor)
            : _errorBarMidPointX +
                ((horizontalPositiveX - _errorBarMidPointX) *
                    _effectiveAnimationFactor);

        _capPointValue = animatingPoint +
            (((isTransposedChart
                        ? horizontalPositiveY
                        : horizontalPositiveX) -
                    animatingPoint) *
                animationFactor);

        _calculateHorizontalPath(_capPointValue, animationFactor,
            series.capLength!, isTransposedChart);
      }
      if (horizontalNegativeX != null && horizontalNegativeY != null) {
        animatingPoint = isTransposedChart
            ? _errorBarMidPointY +
                ((horizontalNegativeY - _errorBarMidPointY) *
                    _effectiveAnimationFactor)
            : _errorBarMidPointX -
                ((_errorBarMidPointX - horizontalNegativeX) *
                    _effectiveAnimationFactor);

        _capPointValue = animatingPoint -
            ((animatingPoint -
                    (isTransposedChart
                        ? horizontalNegativeY
                        : horizontalNegativeX)) *
                animationFactor);

        _calculateHorizontalPath(_capPointValue, animationFactor,
            series.capLength!, isTransposedChart);
      }

      if (points.length > _oldPoints.length) {
        _oldPoints.addAll(points.sublist(_oldPoints.length));
      }
    }
  }
}