onPaint method

  1. @override
void onPaint(
  1. Canvas canvas
)
override

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  if (strokePaint != null) {
    _path = Path();
    if (_series.animationDuration > 0 &&
        !_seriesRenderer._chartState!._isLegendToggled) {
      if (!_seriesRenderer._chartState!._widgetNeedUpdate ||
          _seriesRenderer._reAnimate) {
        if (_isTransposed) {
          _centerX = _highX + ((_lowX - _highX) / 2);
          _openX = _centerX -
              ((_centerX - _currentPoint!.openPoint!.x) * animationFactor);
          _closeX = _centerX +
              ((_currentPoint!.closePoint!.x - _centerX) * animationFactor);
          _highX = _centerX + ((_centerX - _highX).abs() * animationFactor);
          _lowX = _centerX - ((_lowX - _centerX).abs() * animationFactor);
          canvas.drawLine(Offset(_lowX, _centerLowPoint.y),
              Offset(_highX, _centerHighPoint.y), strokePaint!);
          canvas.drawLine(
              Offset(_openX, _openY), Offset(_openX, _highY), strokePaint!);
          canvas.drawLine(
              Offset(_closeX, _lowY), Offset(_closeX, _closeY), strokePaint!);
        } else {
          _centerY = _high + ((_low - _high) / 2);
          _openY = _centerY -
              ((_centerY - _currentPoint!.openPoint!.y) * animationFactor);
          _closeY = _centerY +
              ((_currentPoint!.closePoint!.y - _centerY) * animationFactor);
          _highY = _centerY - ((_centerY - _high) * animationFactor);
          _lowY = _centerY + ((_low - _centerY) * animationFactor);
          canvas.drawLine(Offset(_centerHigh, _highY),
              Offset(_centerLow, _lowY), strokePaint!);
          canvas.drawLine(Offset(_openX, _openY), Offset(_centerHigh, _openY),
              strokePaint!);
          canvas.drawLine(Offset(_centerLow, _closeY),
              Offset(_closeX, _closeY), strokePaint!);
        }
      } else {
        _currentSegment = _seriesRenderer._segments[currentSegmentIndex!]
            as HiloOpenCloseSegment;
        _oldSegment = !_seriesRenderer._reAnimate &&
                (_currentSegment._oldSeriesRenderer != null &&
                    _currentSegment
                        ._oldSeriesRenderer!._segments.isNotEmpty &&
                    _currentSegment._oldSeriesRenderer!._segments[0]
                        is HiloOpenCloseSegment &&
                    _currentSegment._oldSeriesRenderer!._segments.length -
                            1 >=
                        currentSegmentIndex!)
            ? _currentSegment._oldSeriesRenderer!
                ._segments[currentSegmentIndex!] as HiloOpenCloseSegment?
            : null;
        _animateHiloOpenCloseSeries(
            _isTransposed,
            _isTransposed ? _lowPoint.x : _low,
            _isTransposed ? _highPoint.x : _high,
            _isTransposed
                ? (_oldSegment != null ? _oldSegment!._lowPoint.x : null)
                : _oldSegment?._low,
            _isTransposed
                ? (_oldSegment != null ? _oldSegment!._highPoint.x : null)
                : _oldSegment?._high,
            _openX,
            _openY,
            _closeX,
            _closeY,
            _isTransposed ? _centerLowPoint.y : _centerLow,
            _isTransposed ? _centerHighPoint.y : _centerHigh,
            _oldSegment?._openX,
            _oldSegment?._openY,
            _oldSegment?._closeX,
            _oldSegment?._closeY,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._centerLowPoint.y
                    : null)
                : _oldSegment?._centerLow,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._centerHighPoint.y
                    : null)
                : _oldSegment?._centerHigh,
            animationFactor,
            strokePaint!,
            canvas,
            _seriesRenderer);
      }
    } else {
      if (_series.dashArray[0] != 0 && _series.dashArray[1] != 0) {
        _drawDashedLine(canvas, _series.dashArray, strokePaint!,
            _drawDashedHiloOpenClosePath(canvas));
      } else {
        drawHiloOpenClosePath(canvas);
      }
    }
  }
}