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 &&
          _segmentProperties.oldSeriesRenderer != null &&
          seriesRendererDetails
                  .stateProperties.renderingDetails.isLegendToggled ==
              false))) {
    _segmentProperties.path = Path();
    if (!_isTransposed &&
        _segmentProperties.currentPoint!.lowerQuartile! >
                _segmentProperties.currentPoint!.upperQuartile! ==
            true) {
      final double temp = _upperY;
      _upperY = _lowerY;
      _lowerY = temp;
    }

    if (seriesRendererDetails
            .stateProperties.renderingDetails.isLegendToggled ==
        true) {
      animationFactor = 1;
    }
    if (_lowerY > _upperY) {
      _centersY = _upperY + ((_upperY - _lowerY).abs() / 2);
      _segmentProperties.topRectY =
          _centersY - ((_centersY - _upperY).abs() * animationFactor);
      _segmentProperties.bottomRectY =
          _centersY + ((_centersY - _lowerY).abs() * animationFactor);
    } else {
      _centersY = _lowerY + ((_lowerY - _upperY).abs() / 2);
      _segmentProperties.topRectY =
          _centersY - ((_centersY - _upperY).abs() * animationFactor);
      _segmentProperties.bottomRectY =
          _centersY + ((_centersY - _lowerY).abs() * animationFactor);
    }
    _topLineY = _segmentProperties.topRectY -
        ((_segmentProperties.topRectY - _maxY).abs() * animationFactor);
    _bottomLineY = _segmentProperties.bottomRectY +
        ((_segmentProperties.bottomRectY - _minY).abs() * animationFactor);

    _bottomLineY = _minY < _lowerY
        ? _segmentProperties.bottomRectY +
            ((_upperY - _maxY).abs() * animationFactor)
        : _bottomLineY;

    _topLineY = _maxY > _upperY
        ? _segmentProperties.topRectY -
            ((_lowerY - _minY).abs() * animationFactor)
        : _topLineY;

    if (_isTransposed) {
      if (_segmentProperties.lowerX > _segmentProperties.upperX == true) {
        _centersY = _segmentProperties.upperX +
            ((_segmentProperties.lowerX - _segmentProperties.upperX).abs() /
                2);
        _segmentProperties.topRectY = _centersY +
            ((_centersY - _segmentProperties.lowerX).abs() * animationFactor);
        _segmentProperties.bottomRectY = _centersY -
            ((_centersY - _segmentProperties.upperX).abs() * animationFactor);
      } else {
        _centersY = _segmentProperties.lowerX +
            (_segmentProperties.upperX - _segmentProperties.lowerX).abs() / 2;
        _segmentProperties.topRectY = _centersY +
            ((_centersY - _segmentProperties.upperX).abs() * animationFactor);
        _segmentProperties.bottomRectY = _centersY -
            ((_centersY - _segmentProperties.lowerX).abs() * animationFactor);
      }
      _segmentProperties.path.moveTo(_centerMax, _upperY);
      _segmentProperties.path.lineTo(_centerMax, _lowerY);
      if (_centerMax < _segmentProperties.upperX) {
        _segmentProperties.path.moveTo(_segmentProperties.bottomRectY, _maxY);
        _segmentProperties.path.lineTo(
            _segmentProperties.topRectY -
                ((_segmentProperties.lowerX - _centerMax).abs() *
                    animationFactor),
            _maxY);
      } else {
        _segmentProperties.path.moveTo(_segmentProperties.topRectY, _maxY);
        _segmentProperties.path.lineTo(
            _segmentProperties.topRectY +
                ((_segmentProperties.upperX - _centerMax).abs() *
                    animationFactor),
            _maxY);
      }
      _segmentProperties.path.moveTo(_medianX, _upperY);
      _segmentProperties.path.lineTo(_medianX, _lowerY);
      if (_centerMin > _segmentProperties.lowerX) {
        _segmentProperties.path.moveTo(_segmentProperties.topRectY, _maxY);
        _segmentProperties.path.lineTo(
            _segmentProperties.bottomRectY +
                ((_segmentProperties.upperX - _centerMin).abs() *
                    animationFactor),
            _maxY);
      } else {
        _segmentProperties.path.moveTo(_segmentProperties.bottomRectY, _maxY);
        _segmentProperties.path.lineTo(
            _segmentProperties.bottomRectY -
                ((_segmentProperties.lowerX - _centerMin).abs() *
                    animationFactor),
            _maxY);
      }
      _segmentProperties.path.moveTo(_centerMin, _upperY);
      _segmentProperties.path.lineTo(_centerMin, _lowerY);
      if (_boxAndWhiskerSeries.showMean) {
        _drawMeanLine(
            canvas,
            Offset(_segmentProperties.currentPoint!.centerMeanPoint!.y,
                _segmentProperties.currentPoint!.centerMeanPoint!.x),
            Size(_segmentProperties.series.markerSettings.width,
                _segmentProperties.series.markerSettings.height),
            _isTransposed);
      }

      _segmentProperties.lowerX == _segmentProperties.upperX
          ? canvas.drawLine(Offset(_segmentProperties.lowerX, _lowerY),
              Offset(_segmentProperties.upperX, _upperY), fillPaint!)
          : _drawRectPath();
    } else {
      if (_segmentProperties.currentPoint!.lowerQuartile! >
              _segmentProperties.currentPoint!.upperQuartile! ==
          true) {
        final double temp = _upperY;
        _upperY = _lowerY;
        _lowerY = temp;
      }
      _drawLine(canvas);
      if (_boxAndWhiskerSeries.showMean) {
        _drawMeanLine(
            canvas,
            Offset(_segmentProperties.currentPoint!.centerMeanPoint!.x,
                _segmentProperties.currentPoint!.centerMeanPoint!.y),
            Size(_segmentProperties.series.markerSettings.width,
                _segmentProperties.series.markerSettings.height),
            _isTransposed);
      }
      _lowerY == _upperY
          ? canvas.drawLine(Offset(_segmentProperties.lowerX, _lowerY),
              Offset(_segmentProperties.upperX, _upperY), fillPaint!)
          : _drawRectPath();
    }

    if (seriesRendererDetails.dashArray![0] != 0 &&
        seriesRendererDetails.dashArray![1] != 0 &&
        _segmentProperties.series.animationDuration <= 0 == true) {
      canvas.drawPath(_segmentProperties.path, fillPaint!);
      drawDashedLine(canvas, seriesRendererDetails.dashArray!, strokePaint!,
          _segmentProperties.path);
    } else {
      canvas.drawPath(_segmentProperties.path, fillPaint!);
      canvas.drawPath(_segmentProperties.path, strokePaint!);
    }
    if (fillPaint!.style == PaintingStyle.fill) {
      if (_isTransposed) {
        if (_segmentProperties.currentPoint!.lowerQuartile! >
                _segmentProperties.currentPoint!.upperQuartile! ==
            true) {
          _drawFillLine(canvas);
        }
        if (_boxAndWhiskerSeries.showMean) {
          _drawMeanLine(
              canvas,
              Offset(_segmentProperties.currentPoint!.centerMeanPoint!.y,
                  _segmentProperties.currentPoint!.centerMeanPoint!.x),
              Size(_segmentProperties.series.markerSettings.width,
                  _segmentProperties.series.markerSettings.height),
              _isTransposed);
        }
      } else {
        _drawLine(canvas);
        if (_boxAndWhiskerSeries.showMean) {
          _drawMeanLine(
              canvas,
              Offset(_segmentProperties.currentPoint!.centerMeanPoint!.x,
                  _segmentProperties.currentPoint!.centerMeanPoint!.y),
              Size(_segmentProperties.series.markerSettings.width,
                  _segmentProperties.series.markerSettings.height),
              _isTransposed);
        }
      }
    }
  } else if (seriesRendererDetails
          .stateProperties.renderingDetails.isLegendToggled ==
      false) {
    final BoxAndWhiskerSegment currentSegment = seriesRendererDetails
        .segments[currentSegmentIndex!] as BoxAndWhiskerSegment;
    final SegmentProperties chartSegmentPropeties =
        SegmentHelper.getSegmentProperties(currentSegment);
    final SeriesRendererDetails oldSeriesRendererDetails =
        SeriesHelper.getSeriesRendererDetails(
            chartSegmentPropeties.oldSeriesRenderer!);
    final BoxAndWhiskerSegment? oldSegment =
        (oldSeriesRendererDetails.segments.isNotEmpty == true &&
                oldSeriesRendererDetails.segments[0]
                    is BoxAndWhiskerSegment &&
                oldSeriesRendererDetails.segments.length - 1 >=
                        currentSegmentIndex! ==
                    true)
            ? oldSeriesRendererDetails.segments[currentSegmentIndex!]
                as BoxAndWhiskerSegment?
            : null;
    SegmentProperties? oldSegmentProperties;
    if (oldSegment != null) {
      oldSegmentProperties = SegmentHelper.getSegmentProperties(oldSegment);
    }

    animateBoxSeries(
        _boxAndWhiskerSeries.showMean,
        Offset(_segmentProperties.currentPoint!.centerMeanPoint!.x,
            _segmentProperties.currentPoint!.centerMeanPoint!.y),
        Offset(_segmentProperties.currentPoint!.centerMeanPoint!.y,
            _segmentProperties.currentPoint!.centerMeanPoint!.x),
        Size(_segmentProperties.series.markerSettings.width,
            _segmentProperties.series.markerSettings.height),
        _segmentProperties.max,
        _isTransposed,
        _segmentProperties.currentPoint!.lowerQuartile!,
        _segmentProperties.currentPoint!.upperQuartile!,
        _minY,
        _maxY,
        oldSegment?._minY,
        oldSegment?._maxY,
        _segmentProperties.lowerX,
        _lowerY,
        _segmentProperties.upperX,
        _upperY,
        _centerMin,
        _centerMax,
        oldSegmentProperties?.lowerX,
        oldSegment?._lowerY,
        oldSegmentProperties?.upperX,
        oldSegment?._upperY,
        oldSegment?._centerMin,
        oldSegment?._centerMax,
        _medianX,
        _medianY,
        animationFactor,
        fillPaint!,
        strokePaint!,
        canvas,
        SeriesHelper.getSeriesRendererDetails(
            _segmentProperties.seriesRenderer));
  }
}