drawAxisTitles static method

void drawAxisTitles(
  1. Canvas canvas,
  2. ChartContext context
)

Draws optional X/Y axis title labels (cartesian charts).

Implementation

static void drawAxisTitles(Canvas canvas, ChartContext context) {
  final xTitle = context.config.xAxisTitle;
  final yTitle = context.config.yAxisTitle;
  if ((xTitle == null || xTitle.isEmpty) &&
      (yTitle == null || yTitle.isEmpty)) {
    return;
  }

  final bounds = context.bounds;
  final style = context.theme.axisTextStyle.copyWith(
    fontWeight: FontWeight.w600,
  );

  if (xTitle != null && xTitle.isNotEmpty) {
    _drawLabel(
      canvas,
      xTitle,
      Offset(bounds.left + bounds.width / 2, bounds.bottom + 22),
      style,
      align: TextAlign.center,
      maxWidth: bounds.width,
    );
  }

  if (yTitle != null && yTitle.isNotEmpty) {
    _drawRotatedLabel(
      canvas,
      yTitle,
      Offset(bounds.left - 8, bounds.top + bounds.height / 2),
      style,
      maxWidth: bounds.height,
    );
  }
}