drawHorizontalAxesTickLines method

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

To draw the horizontal axes tick lines

Implementation

@override
void drawHorizontalAxesTickLines(
    Canvas canvas, ChartAxisRenderer axisRenderer, SfCartesianChart chart,
    [String? renderType,
    double? animationFactor,
    ChartAxisRenderer? oldAxisRenderer,
    bool? needAnimate]) {
  final Rect axisBounds = axisRenderer._bounds;
  final dynamic axis = axisRenderer._axis;
  final List<AxisLabel> visibleLabels = axisRenderer._visibleLabels;
  late double tempInterval, pointX, pointY;
  int length = visibleLabels.length;
  if (length > 0) {
    final MajorTickLines ticks = axis.majorTickLines;
    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();
      pointX = ((_valueToCoefficient(tempInterval, axisRenderer) *
                  axisBounds.width) +
              axisBounds.left)
          .roundToDouble();
      pointY = axisBounds.top - padding + axis.axisLine.width / 2;

      if (needAnimate!) {
        final double? oldLocation =
            _getPrevLocation(axisRenderer, oldAxisRenderer!, tempInterval);
        pointX = oldLocation != null
            ? (oldLocation - (oldLocation - pointX) * animationFactor!)
            : pointX;
      }
      if (axisBounds.left.roundToDouble() <= pointX &&
          axisBounds.right.roundToDouble() >= pointX) {
        if ((axis.majorGridLines.width > 0) == true &&
            renderType == 'outside' &&
            ((axis.plotOffset > 0) == true ||
                (i != 0 &&
                    (isBetweenTicks ? i != length - 1 : i != length)) ||
                (axisBounds.left <= pointX &&
                    axisBounds.right >= pointX &&
                    !_chartState._requireInvertedAxis))) {
          axisRenderer.drawHorizontalAxesMajorGridLines(
              canvas,
              Offset(pointX, pointY),
              axisRenderer,
              axis.majorGridLines,
              i,
              chart);
        }
        if ((axis.minorGridLines.width > 0) == true ||
            (axis.minorTickLines.width > 0) == true) {
          num? nextValue = isBetweenTicks
              ? (tempInterval + axisRenderer._visibleRange!.interval)
              : i == length - 1
                  ? axisRenderer._visibleRange!.maximum
                  : visibleLabels[i + 1].value;
          if (nextValue != null) {
            nextValue = ((_valueToCoefficient(nextValue, axisRenderer) *
                        axisBounds.width) +
                    axisBounds.left)
                .roundToDouble();
            axisRenderer.drawHorizontalAxesMinorLines(canvas, axisRenderer,
                pointX, axisBounds, nextValue, i, chart, renderType);
          }
        }
      }
      if ((axis.majorTickLines.width > 0) == true &&
          (axisBounds.left <= pointX &&
              axisBounds.right.roundToDouble() >= pointX) &&
          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(
                pointX,
                axis.opposedPosition == false
                    ? (axisRenderer._isInsideTickPosition!
                        ? pointY - ticks.size
                        : pointY + ticks.size)
                    : (axisRenderer._isInsideTickPosition!
                        ? pointY + ticks.size
                        : pointY - ticks.size)));
      }
    }
  }
}