onPaint method

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

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  double? prevX, prevY;
  LineSegment? prevSegment;
  final Rect rect = _calculatePlotOffset(
      _seriesRenderer._chartState!._chartAxis._axisClipRect,
      Offset(_seriesRenderer._xAxisRenderer!._axis.plotOffset,
          _seriesRenderer._yAxisRenderer!._axis.plotOffset));
  _path = Path();
  if (_series.animationDuration > 0 &&
      !_seriesRenderer._reAnimate &&
      _oldSeriesRenderer != null &&
      _oldSeriesRenderer!._segments.isNotEmpty &&
      _oldSeriesRenderer!._segments[0] is LineSegment &&
      _seriesRenderer._chartState!._oldSeriesRenderers.length - 1 >=
          _seriesRenderer._segments[currentSegmentIndex!]._seriesIndex &&
      _seriesRenderer._segments[currentSegmentIndex!]._oldSeriesRenderer!
          ._segments.isNotEmpty) {
    _currentSegment =
        _seriesRenderer._segments[currentSegmentIndex!] as LineSegment;
    _oldSegment = (_currentSegment._oldSeriesRenderer!._segments.length - 1 >=
            currentSegmentIndex!)
        ? _currentSegment._oldSeriesRenderer!._segments[currentSegmentIndex!]
            as LineSegment?
        : null;
    if (currentSegmentIndex! > 0) {
      prevSegment =
          (_currentSegment._oldSeriesRenderer!._segments.length - 1 >=
                  currentSegmentIndex! - 1)
              ? _currentSegment._oldSeriesRenderer!
                  ._segments[currentSegmentIndex! - 1] as LineSegment?
              : null;
    }
    _oldX1 = _oldSegment?._x1;
    _oldY1 = _oldSegment?._y1;
    _oldX2 = _oldSegment?._x2;
    _oldY2 = _oldSegment?._y2;
    if (_oldSegment == null && _chartState._widgetNeedUpdate) {
      _newlyAddedSegment = true;
      prevX = prevSegment?._x2;
      prevY = prevSegment?._y2;
    } else {
      _newlyAddedSegment = false;
    }
    if (_oldSegment != null &&
        (_oldX1!.isNaN || _oldX2!.isNaN) &&
        _seriesRenderer._chartState!._oldAxisRenderers.isNotEmpty) {
      _oldXAxisRenderer = _getOldAxisRenderer(_seriesRenderer._xAxisRenderer!,
          _seriesRenderer._chartState!._oldAxisRenderers);
      _oldYAxisRenderer = _getOldAxisRenderer(_seriesRenderer._yAxisRenderer!,
          _seriesRenderer._chartState!._oldAxisRenderers);
      if (_oldYAxisRenderer != null && _oldXAxisRenderer != null) {
        _needAnimate = _oldYAxisRenderer!._visibleRange!.minimum !=
                _seriesRenderer._yAxisRenderer!._visibleRange!.minimum ||
            _oldYAxisRenderer!._visibleRange!.maximum !=
                _seriesRenderer._yAxisRenderer!._visibleRange!.maximum ||
            _oldXAxisRenderer!._visibleRange!.minimum !=
                _seriesRenderer._xAxisRenderer!._visibleRange!.minimum ||
            _oldXAxisRenderer!._visibleRange!.maximum !=
                _seriesRenderer._xAxisRenderer!._visibleRange!.maximum;
      }
      if (_needAnimate) {
        _first = _calculatePoint(
            _currentPoint!.xValue,
            _currentPoint!.yValue,
            _oldXAxisRenderer!,
            _oldYAxisRenderer!,
            _seriesRenderer._chartState!._requireInvertedAxis,
            _series,
            rect);
        _second = _calculatePoint(
            _nextPoint!.xValue,
            _nextPoint!.yValue,
            _oldXAxisRenderer!,
            _oldYAxisRenderer!,
            _seriesRenderer._chartState!._requireInvertedAxis,
            _series,
            rect);
        _oldX1 = _first.x;
        _oldX2 = _second.x;
        _oldY1 = _first.y;
        _oldY2 = _second.y;
      }
    }
    if (_newlyAddedSegment) {
      _animateToPoint(
          canvas,
          _seriesRenderer,
          strokePaint!,
          animationFactor,
          _currentSegment._x1,
          _currentSegment._y1,
          _currentSegment._x2,
          _currentSegment._y2,
          prevX,
          prevY);
    } else {
      _animateLineTypeSeries(
        canvas,
        _seriesRenderer,
        strokePaint!,
        animationFactor,
        _currentSegment._x1,
        _currentSegment._y1,
        _currentSegment._x2,
        _currentSegment._y2,
        _oldX1,
        _oldY1,
        _oldX2,
        _oldY2,
      );
    }
  } else {
    if (_series.dashArray[0] != 0 && _series.dashArray[1] != 0) {
      _path.moveTo(_x1, _y1);
      _path.lineTo(_x2, _y2);
      _drawDashedLine(canvas, _series.dashArray, strokePaint!, _path);
    } else {
      canvas.drawLine(Offset(_x1, _y1), Offset(_x2, _y2), strokePaint!);
    }
  }
}