onPaint method

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

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  final SeriesRendererDetails seriesRendererDetails =
      SeriesHelper.getSeriesRendererDetails(
          _segmentProperties.seriesRenderer);
  if (strokePaint != null) {
    _segmentProperties.path = Path();
    if (_segmentProperties.series.animationDuration > 0 == true &&
        _segmentProperties.stateProperties.renderingDetails.isLegendToggled ==
            false) {
      if (_segmentProperties
                  .stateProperties.renderingDetails.widgetNeedUpdate ==
              false ||
          seriesRendererDetails.reAnimate == true) {
        if (_isTransposed) {
          _centerX = _highX + ((_lowX - _highX) / 2);
          _segmentProperties.openX = _centerX -
              ((_centerX - _segmentProperties.currentPoint!.openPoint!.x) *
                  animationFactor);
          _segmentProperties.closeX = _centerX +
              ((_segmentProperties.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(_segmentProperties.openX, _segmentProperties.openY),
              Offset(_segmentProperties.openX, _highY),
              strokePaint!);
          canvas.drawLine(
              Offset(_segmentProperties.closeX, _lowY),
              Offset(_segmentProperties.closeX, _segmentProperties.closeY),
              strokePaint!);
        } else {
          _centerY = _segmentProperties.high +
              ((_segmentProperties.low - _segmentProperties.high) / 2);
          _segmentProperties.openY = _centerY -
              ((_centerY - _segmentProperties.currentPoint!.openPoint!.y) *
                  animationFactor);
          _segmentProperties.closeY = _centerY +
              ((_segmentProperties.currentPoint!.closePoint!.y - _centerY) *
                  animationFactor);
          _highY = _centerY -
              ((_centerY - _segmentProperties.high) * animationFactor);
          _lowY = _centerY +
              ((_segmentProperties.low - _centerY) * animationFactor);
          canvas.drawLine(Offset(_centerHigh, _highY),
              Offset(_centerLow, _lowY), strokePaint!);
          canvas.drawLine(
              Offset(_segmentProperties.openX, _segmentProperties.openY),
              Offset(_centerHigh, _segmentProperties.openY),
              strokePaint!);
          canvas.drawLine(
              Offset(_centerLow, _segmentProperties.closeY),
              Offset(_segmentProperties.closeX, _segmentProperties.closeY),
              strokePaint!);
        }
      } else {
        _currentSegment = seriesRendererDetails.segments[currentSegmentIndex!]
            as HiloOpenCloseSegment;
        final SeriesRendererDetails? oldSeriesDetails =
            SeriesHelper.getSeriesRendererDetails(
                _currentSegment._segmentProperties.oldSeriesRenderer!);
        _oldSegment = seriesRendererDetails.reAnimate == false &&
                (_currentSegment._segmentProperties.oldSeriesRenderer !=
                        null &&
                    oldSeriesDetails!.segments.isNotEmpty == true &&
                    oldSeriesDetails.segments[0] is HiloOpenCloseSegment &&
                    oldSeriesDetails.segments.length - 1 >=
                            currentSegmentIndex! ==
                        true)
            ? oldSeriesDetails.segments[currentSegmentIndex!]
                as HiloOpenCloseSegment?
            : null;
        animateHiloOpenCloseSeries(
            _isTransposed,
            _isTransposed
                ? _segmentProperties.lowPoint.x
                : _segmentProperties.low,
            _isTransposed
                ? _segmentProperties.highPoint.x
                : _segmentProperties.high,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._segmentProperties.lowPoint.x
                    : null)
                : _oldSegment?._segmentProperties.low,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._segmentProperties.highPoint.x
                    : null)
                : _oldSegment?._segmentProperties.high,
            _segmentProperties.openX,
            _segmentProperties.openY,
            _segmentProperties.closeX,
            _segmentProperties.closeY,
            _isTransposed ? _centerLowPoint.y : _centerLow,
            _isTransposed ? _centerHighPoint.y : _centerHigh,
            _oldSegment?._segmentProperties.openX,
            _oldSegment?._segmentProperties.openY,
            _oldSegment?._segmentProperties.closeX,
            _oldSegment?._segmentProperties.closeY,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._centerLowPoint.y
                    : null)
                : _oldSegment?._centerLow,
            _isTransposed
                ? (_oldSegment != null
                    ? _oldSegment!._centerHighPoint.y
                    : null)
                : _oldSegment?._centerHigh,
            animationFactor,
            strokePaint!,
            canvas,
            SeriesHelper.getSeriesRendererDetails(
                _segmentProperties.seriesRenderer));
      }
    } else {
      (seriesRendererDetails.dashArray![0] != 0 &&
              seriesRendererDetails.dashArray![1] != 0)
          ? drawDashedLine(canvas, seriesRendererDetails.dashArray!,
              strokePaint!, _drawDashedHiloOpenClosePath(canvas))
          : drawHiloOpenClosePath(canvas);
    }
  }
}