drawVerticalAxesTickLines method Null safety

  1. @override
void drawVerticalAxesTickLines(
  1. Canvas canvas,
  2. ChartAxisRenderer axisRenderer,
  3. SfCartesianChart chart,
  4. [String? renderType,
  5. double? animationFactor,
  6. ChartAxisRenderer? oldAxisRenderer,
  7. bool? needAnimate]
)

To draw tick lines of vertical axes

Implementation

@override
void drawVerticalAxesTickLines(
    Canvas canvas, ChartAxisRenderer axisRenderer, SfCartesianChart chart,
    [String? renderType,
    double? animationFactor,
    ChartAxisRenderer? oldAxisRenderer,
    bool? needAnimate]) {
  final dynamic axis = axisRenderer._axis;
  final Rect axisBounds = axisRenderer._bounds;
  final List<AxisLabel> visibleLabels = axisRenderer._visibleLabels;
  double tempInterval, pointX, pointY;
  int length = visibleLabels.length;
  const num padding = 1;
  final bool isBetweenTicks =
      (axis is CategoryAxis || axis is DateTimeCategoryAxis) &&
          axis.labelPlacement == LabelPlacement.betweenTicks;
  final num tickBetweenLabel = isBetweenTicks ? 0.5 : 0;
  length += isBetweenTicks ? 1 : 0;
  for (int i = 0; i < length; i++) {
    tempInterval = (isBetweenTicks
            ? i < length - 1
                ? visibleLabels[i].value - tickBetweenLabel
                : (visibleLabels[i - 1].value +
                        axisRenderer._visibleRange!.interval) -
                    tickBetweenLabel
            : visibleLabels[i].value)
        .toDouble();
    pointY = (_valueToCoefficient(tempInterval, axisRenderer) *
            axisBounds.height) +
        axisBounds.top;
    pointY = (axisBounds.top + axisBounds.height) -
        (pointY - axisBounds.top).abs();
    pointX = axisBounds.left + padding - axis.axisLine.width / 2;

    if (needAnimate!) {
      final double? oldLocation =
          _getPrevLocation(axisRenderer, oldAxisRenderer!, tempInterval);
      pointY = oldLocation != null
          ? (oldLocation - (oldLocation - pointY) * animationFactor!)
          : pointY;
    }
    if (pointY >= axisBounds.top && pointY <= axisBounds.bottom) {
      if ((axis.majorGridLines.width > 0) == true &&
          renderType == 'outside' &&
          ((axis.plotOffset > 0) == true ||
              ((i == 0 || i == length - 1) &&
                  chart.plotAreaBorderWidth == 0) ||
              (((i == 0 && axis.opposedPosition == false) ||
                      (i == length - 1 && axis.opposedPosition == true)) &&
                  axis.axisLine.width == 0) ||
              (axisBounds.top < pointY - axis.majorGridLines.width &&
                  axisBounds.bottom > pointY + axis.majorGridLines.width))) {
        axisRenderer.drawVerticalAxesMajorGridLines(
            canvas,
            Offset(pointX, pointY),
            axisRenderer,
            axis.majorGridLines,
            i,
            chart);
      }
      if ((axis.minorGridLines.width > 0) == true ||
          (axis.minorTickLines.width > 0) == true) {
        axisRenderer.drawVerticalAxesMinorTickLines(canvas, axisRenderer,
            tempInterval, axisBounds, i, chart, renderType!);
      }
      if ((axis.majorTickLines.width > 0) == true &&
          renderType == axis.tickPosition.toString().split('.')[1]) {
        _drawDashedPath(
            canvas,
            _CustomPaintStyle(
                axisRenderer.getAxisMajorTickWidth(axis, i),
                axisRenderer.getAxisMajorTickColor(axis, i) ??
                    _chartState._chartTheme.majorTickLineColor,
                PaintingStyle.stroke),
            Offset(pointX, pointY),
            Offset(
                axis.opposedPosition == true
                    ? (axisRenderer._isInsideTickPosition!
                        ? pointX + axis.majorTickLines.size
                        : pointX - axis.majorTickLines.size)
                    : (axisRenderer._isInsideTickPosition!
                        ? pointX - axis.majorTickLines.size
                        : pointX + axis.majorTickLines.size),
                pointY));
      }
    }
  }
}