drawVerticalText method

  1. @override
void drawVerticalText({
  1. required Canvas canvas,
  2. required TextStyle style,
  3. required double maxValue,
  4. required double minValue,
  5. required int fixedLength,
  6. required Rect chartRect,
})
override

Implementation

@override
void drawVerticalText({
  required Canvas canvas,
  required TextStyle style,
  required double maxValue,
  required double minValue,
  required int fixedLength,
  required Rect chartRect,
}) {
  double jumpStep = maxValue - minValue;
  late int jumpValue;
  if (jumpStep >= 100) {
    jumpValue = 100;
  } else if (jumpStep >= 10) {
    jumpValue = 10;
  } else {
    jumpValue = 1;
  }

  /// max
  TextPainter maxTp = TextPainter(
    text: TextSpan(
      text: "${NumberUtil.formatFixed(
            (maxValue / jumpValue).round() * jumpValue,
            0,
          ) ?? ''}",
      style: style,
    ),
    textDirection: TextDirection.ltr,
  );
  maxTp.layout();
  maxTp.paint(
    canvas,
    Offset(
      chartRect.width - maxTp.width,
      chartRect.top,
    ),
  );

  /// min
  TextPainter minTp = TextPainter(
    text: TextSpan(
      text: "${NumberUtil.formatFixed(
            (minValue / jumpValue).round() * jumpValue,
            0,
          ) ?? ''}",
      style: style,
    ),
    textDirection: TextDirection.ltr,
  );
  minTp.layout();
  minTp.paint(
    canvas,
    Offset(
      chartRect.width - minTp.width,
      chartRect.bottom - minTp.height,
    ),
  );
}