drawHorizontalAxesTitle method Null safety

  1. @override
void drawHorizontalAxesTitle(
  1. Canvas canvas,
  2. ChartAxisRenderer axisRenderer,
  3. SfCartesianChart chart
)

To draw the axis title of horizontal axes

Implementation

@override
void drawHorizontalAxesTitle(
    Canvas canvas, ChartAxisRenderer axisRenderer, SfCartesianChart chart) {
  final ChartAxis axis = axisRenderer._axis;
  final Rect axisBounds = axisRenderer._bounds;
  Offset point;
  final String title = axis.title.text ?? '';
  const int labelRotation = 0, innerPadding = 8;
  TextStyle style = axis.title.textStyle;
  style = _getTextStyle(
      textStyle: style,
      fontColor: style.color ?? _chartState._chartTheme.axisTitleColor);
  final Size textSize = measureText(title, style);
  double top;
  if (axis.labelPosition == ChartDataLabelPosition.inside) {
    top = !axis.opposedPosition
        ? axisBounds.top +
            (axisRenderer._isInsideTickPosition!
                ? 0
                : axis.majorTickLines.size) +
            (!kIsWeb ? innerPadding : innerPadding + textSize.height / 2)
        : axisBounds.top -
            (axisRenderer._isInsideTickPosition!
                ? 0
                : axis.majorTickLines.size) -
            innerPadding -
            textSize.height;
  } else {
    top = !axis.opposedPosition
        ? axisBounds.top +
            (axisRenderer._isInsideTickPosition!
                ? 0
                : axis.majorTickLines.size) +
            innerPadding +
            (!kIsWeb
                ? axisRenderer._maximumLabelSize.height
                : axisRenderer._maximumLabelSize.height + textSize.height / 2)
        : axisBounds.top -
            (axisRenderer._isInsideTickPosition!
                ? 0
                : axis.majorTickLines.size) -
            innerPadding -
            axisRenderer._maximumLabelSize.height -
            textSize.height;
  }
  axis.title.alignment == ChartAlignment.near
      ? point = Offset(_chartState._chartAxis._axisClipRect.left, top)
      : axis.title.alignment == ChartAlignment.far
          ? point = Offset(
              _chartState._chartAxis._axisClipRect.right - textSize.width,
              top)
          : point = Offset(
              axisBounds.left +
                  ((axisBounds.width / 2) - (textSize.width / 2)),
              top);
  if (axisRenderer._seriesRenderers.isNotEmpty ||
      axisRenderer._name == 'primaryXAxis') {
    _drawText(canvas, title, point, style, labelRotation);
  }
}