onPaint method

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

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  _setSegmentProperties();
  final SeriesRendererDetails seriesRendererDetails =
      SeriesHelper.getSeriesRendererDetails(
          _segmentProperties.seriesRenderer);
  if (fillPaint != null &&
      (seriesRendererDetails.reAnimate == true ||
          !(seriesRendererDetails
                      .stateProperties.renderingDetails.widgetNeedUpdate ==
                  true &&
              seriesRendererDetails
                      .stateProperties.renderingDetails.isLegendToggled ==
                  false))) {
    _segmentProperties.path = Path();
    _linePath = Path();

    if (!_isTransposed &&
        _segmentProperties.currentPoint!.open >
                _segmentProperties.currentPoint!.close ==
            true) {
      final double temp = _segmentProperties.closeY;
      _segmentProperties.closeY = _segmentProperties.openY;
      _segmentProperties.openY = temp;
    }

    if (seriesRendererDetails
            .stateProperties.renderingDetails.isLegendToggled ==
        true) {
      animationFactor = 1;
    }
    _centersY = _segmentProperties.closeY +
        ((_segmentProperties.closeY - _segmentProperties.openY).abs() / 2);
    _segmentProperties.topRectY = _centersY -
        ((_centersY - _segmentProperties.closeY).abs() * animationFactor);
    _topLineY = _segmentProperties.topRectY -
        ((_segmentProperties.topRectY - _highY).abs() * animationFactor);
    _segmentProperties.bottomRectY = _centersY +
        ((_centersY - _segmentProperties.openY).abs() * animationFactor);
    _bottomLineY = _segmentProperties.bottomRectY +
        ((_segmentProperties.bottomRectY - _lowY).abs() * animationFactor);

    _bottomLineY = _lowY < _segmentProperties.openY
        ? _segmentProperties.bottomRectY -
            ((_segmentProperties.openY - _lowY).abs() * animationFactor)
        : _bottomLineY;

    _topLineY = _highY > _segmentProperties.closeY
        ? _segmentProperties.topRectY +
            ((_segmentProperties.closeY - _highY).abs() * animationFactor)
        : _topLineY;

    if (_isTransposed) {
      _segmentProperties.currentPoint!.open >
                  _segmentProperties.currentPoint!.close ==
              true
          ? _calculateCandlePositions(
              _segmentProperties.openX, _segmentProperties.closeX)
          : _calculateCandlePositions(
              _segmentProperties.closeX, _segmentProperties.openX);

      if (_showSameValue) {
        canvas.drawLine(Offset(_centerHighPoint.x, _centerHighPoint.y),
            Offset(_centerLowPoint.x, _centerHighPoint.y), fillPaint!);
      } else {
        _segmentProperties.path.moveTo(_segmentProperties.topRectY, _highY);
        _centerHigh < _segmentProperties.closeX
            ? _segmentProperties.path.lineTo(
                _segmentProperties.topRectY -
                    ((_segmentProperties.closeX - _centerHigh).abs() *
                        animationFactor),
                _highY)
            : _segmentProperties.path.lineTo(
                _segmentProperties.topRectY +
                    ((_segmentProperties.closeX - _centerHigh).abs() *
                        animationFactor),
                _highY);
        _segmentProperties.path
            .moveTo(_segmentProperties.bottomRectY, _highY);
        _centerLow > _segmentProperties.openX
            ? _segmentProperties.path.lineTo(
                _segmentProperties.bottomRectY +
                    ((_segmentProperties.openX - _centerLow).abs() *
                        animationFactor),
                _highY)
            : _segmentProperties.path.lineTo(
                _segmentProperties.bottomRectY -
                    ((_segmentProperties.openX - _centerLow).abs() *
                        animationFactor),
                _highY);
        _linePath = _segmentProperties.path;
      }
      _segmentProperties.openX == _segmentProperties.closeX
          ? canvas.drawLine(
              Offset(_segmentProperties.openX, _segmentProperties.openY),
              Offset(_segmentProperties.closeX, _segmentProperties.closeY),
              fillPaint!)
          : _drawRectPath();
    } else {
      _showSameValue
          ? canvas.drawLine(
              Offset(_centerHighPoint.x, _segmentProperties.highPoint.y),
              Offset(_centerHighPoint.x, _segmentProperties.lowPoint.y),
              fillPaint!)
          : _drawLine(canvas);

      _segmentProperties.openY == _segmentProperties.closeY
          ? canvas.drawLine(
              Offset(_segmentProperties.openX, _segmentProperties.openY),
              Offset(_segmentProperties.closeX, _segmentProperties.closeY),
              fillPaint!)
          : _drawRectPath();
    }

    if (seriesRendererDetails.dashArray![0] != 0 &&
        seriesRendererDetails.dashArray![1] != 0 &&
        fillPaint!.style != PaintingStyle.fill &&
        _segmentProperties.series.animationDuration <= 0 == true) {
      drawDashedLine(canvas, seriesRendererDetails.dashArray!, fillPaint!,
          _segmentProperties.path);
    } else {
      canvas.drawPath(_segmentProperties.path, fillPaint!);
      if (fillPaint!.style == PaintingStyle.fill) {
        _isTransposed
            ? _showSameValue
                ? canvas.drawLine(
                    Offset(_centerHighPoint.x, _centerHighPoint.y),
                    Offset(_centerLowPoint.x, _centerHighPoint.y),
                    fillPaint!)
                : _drawFillLine(canvas)
            : _showSameValue
                ? canvas.drawLine(
                    Offset(
                        _centerHighPoint.x, _segmentProperties.highPoint.y),
                    Offset(_centerHighPoint.x, _segmentProperties.lowPoint.y),
                    fillPaint!)
                : _drawLine(canvas);
      }
    }
  } else if (seriesRendererDetails
          .stateProperties.renderingDetails.isLegendToggled ==
      false) {
    _currentSegment =
        seriesRendererDetails.segments[currentSegmentIndex!] as CandleSegment;
    final SegmentProperties currentSegmentProperties =
        SegmentHelper.getSegmentProperties(_currentSegment);
    SegmentProperties? oldSegmentProperties;
    final SeriesRendererDetails? oldRendererDetails =
        currentSegmentProperties.oldSeriesRenderer != null
            ? SeriesHelper.getSeriesRendererDetails(
                currentSegmentProperties.oldSeriesRenderer!)
            : null;
    _oldSegment = seriesRendererDetails.reAnimate == false &&
            (oldRendererDetails != null &&
                oldRendererDetails.segments.isNotEmpty == true &&
                oldRendererDetails.segments[0] is CandleSegment &&
                oldRendererDetails.segments.length - 1 >=
                        currentSegmentIndex! ==
                    true)
        ? oldRendererDetails.segments[currentSegmentIndex!] as CandleSegment?
        : null;
    if (_oldSegment != null) {
      oldSegmentProperties = SegmentHelper.getSegmentProperties(_oldSegment!);
    }
    animateCandleSeries(
        _showSameValue,
        _segmentProperties.high,
        _isTransposed,
        _segmentProperties.currentPoint!.open!.toDouble(),
        _segmentProperties.currentPoint!.close!.toDouble(),
        _lowY,
        _highY,
        _oldSegment?._lowY,
        _oldSegment?._highY,
        _segmentProperties.openX,
        _segmentProperties.openY,
        _segmentProperties.closeX,
        _segmentProperties.closeY,
        _centerLow,
        _centerHigh,
        oldSegmentProperties?.openX,
        oldSegmentProperties?.openY,
        oldSegmentProperties?.closeX,
        oldSegmentProperties?.closeY,
        _oldSegment?._centerLow,
        _oldSegment?._centerHigh,
        animationFactor,
        fillPaint!,
        canvas,
        SeriesHelper.getSeriesRendererDetails(
            _segmentProperties.seriesRenderer));
  }
}