onPaint method

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

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  final SegmentProperties segmentProperties =
      SegmentHelper.getSegmentProperties(this);
  final Rect rect = calculatePlotOffset(
      segmentProperties.stateProperties.chartAxis.axisClipRect,
      Offset(
          SeriesHelper.getSeriesRendererDetails(
                  segmentProperties.seriesRenderer)
              .xAxisDetails!
              .axis
              .plotOffset,
          SeriesHelper.getSeriesRendererDetails(
                  segmentProperties.seriesRenderer)
              .yAxisDetails!
              .axis
              .plotOffset));
  segmentProperties.path = Path();
  if (segmentProperties.series.animationDuration > 0 == true &&
      SeriesHelper.getSeriesRendererDetails(segmentProperties.seriesRenderer).reAnimate ==
          false &&
      segmentProperties.stateProperties.renderingDetails.widgetNeedUpdate ==
          true &&
      segmentProperties.stateProperties.renderingDetails.isLegendToggled ==
          false &&
      segmentProperties.stateProperties.oldSeriesRenderers.isNotEmpty ==
          true &&
      segmentProperties.oldSeriesRenderer != null &&
      SeriesHelper.getSeriesRendererDetails(segmentProperties.oldSeriesRenderer!)
              .segments
              .isNotEmpty ==
          true &&
      SeriesHelper.getSeriesRendererDetails(segmentProperties.oldSeriesRenderer!)
          .segments[0] is StepLineSegment &&
      segmentProperties.stateProperties.oldSeriesRenderers.length - 1 >=
              SegmentHelper.getSegmentProperties(SeriesHelper.getSeriesRendererDetails(segmentProperties.seriesRenderer).segments[currentSegmentIndex!])
                  .seriesIndex ==
          true &&
      SeriesHelper.getSeriesRendererDetails(SegmentHelper.getSegmentProperties(
                      SeriesHelper.getSeriesRendererDetails(segmentProperties.seriesRenderer)
                          .segments[currentSegmentIndex!])
                  .oldSeriesRenderer!)
              .segments
              .isNotEmpty ==
          true) {
    _currentSegment = SeriesHelper.getSeriesRendererDetails(
            segmentProperties.seriesRenderer)
        .segments[currentSegmentIndex!] as StepLineSegment;
    final SegmentProperties currentSegmentProperties =
        SegmentHelper.getSegmentProperties(_currentSegment);
    SegmentProperties? oldSegmentProperties;
    _oldSegment = (SeriesHelper.getSeriesRendererDetails(
                            currentSegmentProperties.oldSeriesRenderer!)
                        .segments
                        .length -
                    1 >=
                currentSegmentIndex! ==
            true)
        ? SeriesHelper.getSeriesRendererDetails(
                currentSegmentProperties.oldSeriesRenderer!)
            .segments[currentSegmentIndex!] as StepLineSegment?
        : null;
    if (_oldSegment != null) {
      oldSegmentProperties = SegmentHelper.getSegmentProperties(_oldSegment!);
    }
    _oldX1 = oldSegmentProperties?.x1;
    _oldY1 = oldSegmentProperties?.y1;
    _oldX2 = oldSegmentProperties?.x2;
    _oldY2 = oldSegmentProperties?.y2;
    _oldX3 = oldSegmentProperties?.x3;
    _oldY3 = oldSegmentProperties?.y3;

    if (_oldSegment != null &&
        (_oldX1!.isNaN || _oldX2!.isNaN) &&
        segmentProperties.stateProperties.oldAxisRenderers.isNotEmpty ==
            false) {
      _oldXAxisRenderer = getOldAxisRenderer(
          SeriesHelper.getSeriesRendererDetails(
                  segmentProperties.seriesRenderer)
              .xAxisDetails!
              .axisRenderer,
          segmentProperties.stateProperties.oldAxisRenderers);
      _oldYAxisRenderer = getOldAxisRenderer(
          SeriesHelper.getSeriesRendererDetails(
                  segmentProperties.seriesRenderer)
              .yAxisDetails!
              .axisRenderer,
          segmentProperties.stateProperties.oldAxisRenderers);
      final ChartAxisRendererDetails oldXAxisDetails =
          AxisHelper.getAxisRendererDetails(_oldXAxisRenderer!);
      final ChartAxisRendererDetails oldYAxisDetails =
          AxisHelper.getAxisRendererDetails(_oldYAxisRenderer!);
      if (_oldYAxisRenderer != null && _oldXAxisRenderer != null) {
        _needAnimate = oldYAxisDetails.visibleRange!.minimum !=
                SeriesHelper.getSeriesRendererDetails(
                        segmentProperties.seriesRenderer)
                    .yAxisDetails!
                    .visibleRange!
                    .minimum ||
            oldYAxisDetails.visibleRange!.maximum !=
                SeriesHelper.getSeriesRendererDetails(
                        segmentProperties.seriesRenderer)
                    .yAxisDetails!
                    .visibleRange!
                    .maximum ||
            oldXAxisDetails.visibleRange!.minimum !=
                SeriesHelper.getSeriesRendererDetails(
                        segmentProperties.seriesRenderer)
                    .xAxisDetails!
                    .visibleRange!
                    .minimum ||
            oldXAxisDetails.visibleRange!.maximum !=
                SeriesHelper.getSeriesRendererDetails(
                        segmentProperties.seriesRenderer)
                    .xAxisDetails!
                    .visibleRange!
                    .maximum;
      }
      if (_needAnimate) {
        final ChartAxisRendererDetails oldXAxisDetails =
            AxisHelper.getAxisRendererDetails(_oldXAxisRenderer!);
        final ChartAxisRendererDetails oldYAxisDetails =
            AxisHelper.getAxisRendererDetails(_oldYAxisRenderer!);
        _oldLocation = calculatePoint(
            _x1Pos,
            _y1Pos,
            oldXAxisDetails,
            oldYAxisDetails,
            segmentProperties.stateProperties.requireInvertedAxis,
            segmentProperties.series,
            rect);
        _oldX1 = _oldLocation!.x;
        _oldY1 = _oldLocation!.y;

        _oldLocation = calculatePoint(
            _x2Pos,
            _y2Pos,
            oldXAxisDetails,
            oldYAxisDetails,
            segmentProperties.stateProperties.requireInvertedAxis,
            segmentProperties.series,
            rect);
        _oldX2 = _oldLocation!.x;
        _oldY2 = _oldLocation!.y;
        _oldLocation = calculatePoint(
            segmentProperties.midX,
            segmentProperties.midY,
            oldXAxisDetails,
            oldYAxisDetails,
            segmentProperties.stateProperties.requireInvertedAxis,
            segmentProperties.series,
            rect);
        _oldX3 = _oldLocation!.x;
        _oldY3 = _oldLocation!.y;
      }
    }
    animateLineTypeSeries(
      canvas,
      SeriesHelper.getSeriesRendererDetails(segmentProperties.seriesRenderer),
      strokePaint!,
      animationFactor,
      currentSegmentProperties.x1,
      currentSegmentProperties.y1,
      currentSegmentProperties.x2,
      currentSegmentProperties.y2,
      _oldX1,
      _oldY1,
      _oldX2,
      _oldY2,
      currentSegmentProperties.x3,
      currentSegmentProperties.y3,
      _oldX3,
      _oldY3,
    );
  } else {
    final SeriesRendererDetails seriesRendererDetails =
        SeriesHelper.getSeriesRendererDetails(
            segmentProperties.seriesRenderer);
    if (seriesRendererDetails.dashArray![0] != 0 &&
        seriesRendererDetails.dashArray![1] != 0) {
      segmentProperties.path
          .moveTo(segmentProperties.x1, segmentProperties.y1);
      segmentProperties.path
          .lineTo(segmentProperties.x3, segmentProperties.y3);
      segmentProperties.path
          .lineTo(segmentProperties.x2, segmentProperties.y2);
      drawDashedLine(canvas, seriesRendererDetails.dashArray!, strokePaint!,
          segmentProperties.path);
    } else {
      canvas.drawLine(Offset(segmentProperties.x1, segmentProperties.y1),
          Offset(segmentProperties.x3, segmentProperties.y3), strokePaint!);
      canvas.drawLine(Offset(segmentProperties.x3, segmentProperties.y3),
          Offset(segmentProperties.x2, segmentProperties.y2), strokePaint!);
    }
  }
}