transformValues method

  1. @override
void transformValues()
override

Transforms the x and y values to screen coordinates.

Implementation

@override
void transformValues() {
  _reset();

  double degree = _degree;
  double startAngle = _startAngle;
  double endAngle = _endAngle;
  double innerRadius = _innerRadius;
  double outerRadius = _outerRadius;

  if (animationFactor == 1) {
    // Resets `_isLegendToggled` to `false` to handle endAngle animations during dynamically.
    _isLegendToggled = false;
  }

  if (!_isLegendToggled &&
      !degree.isNaN &&
      !_endAngle.isNaN &&
      !_priorEndAngle.isNaN &&
      _priorEndAngle != _endAngle) {
    // Handles endAngle animation  when the data is reset dynamically.
    endAngle = lerpDouble(_priorEndAngle, _endAngle, animationFactor)!;
    degree = endAngle - startAngle;
  } else {
    if (!_priorInnerRadius.isNaN && !_priorOuterRadius.isNaN) {
      // Handles inner and outer radius animation when the legend is toggled.
      if (isVisible) {
        innerRadius =
            lerpDouble(_priorInnerRadius, _innerRadius, animationFactor)!;
        outerRadius =
            lerpDouble(_priorOuterRadius, _outerRadius, animationFactor)!;
      } else {
        final double halfRadii = (_priorOuterRadius + _priorInnerRadius) / 2;
        endAngle = _priorEndAngle;
        degree = endAngle - startAngle;
        innerRadius = _priorInnerRadius +
            (halfRadii - _priorInnerRadius) * animationFactor;
        outerRadius = _priorOuterRadius -
            (_priorOuterRadius - halfRadii) * animationFactor;
        _innerRadius = innerRadius;
        _outerRadius = outerRadius;
      }
    } else {
      // Handles endAngle animation at load time.
      degree = degree * animationFactor;
      endAngle = startAngle + degree;
    }
  }

  trackPath = calculateArcPath(
      innerRadius, outerRadius, _center, 0, fullAngle, fullAngle,
      isAnimate: true);

  if (_outerRadius > 0 && degree > 0) {
    final num angleDeviation =
        findAngleDeviation(innerRadius, outerRadius, 360);
    final CornerStyle cornerStyle = series.cornerStyle;
    if (cornerStyle == CornerStyle.bothCurve ||
        cornerStyle == CornerStyle.startCurve) {
      startAngle += angleDeviation;
    }

    if (cornerStyle == CornerStyle.bothCurve ||
        cornerStyle == CornerStyle.endCurve) {
      endAngle -= angleDeviation;
    }

    if (degree > 360) {
      yValuePath = calculateRoundedCornerArcPath(
          cornerStyle, innerRadius, outerRadius, _center, 0, fullAngle);
      yValuePath.arcTo(
          Rect.fromCircle(center: _center, radius: outerRadius),
          degreesToRadians(_startAngle),
          degreesToRadians(_endAngle - _startAngle),
          true);
      yValuePath.arcTo(
          Rect.fromCircle(center: _center, radius: innerRadius),
          degreesToRadians(_endAngle),
          degreesToRadians(_startAngle) - degreesToRadians(_endAngle),
          false);
    } else {
      yValuePath = calculateRoundedCornerArcPath(cornerStyle, innerRadius,
          outerRadius, _center, startAngle, endAngle);
    }

    if (degree > 360 && endAngle >= startAngle + 180) {
      _calculateShadowPath(endAngle, degree, innerRadius, outerRadius);
    }
  }
}