drawVerticalAxesTitle method

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

To draw the axis title of vertical axes

Implementation

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