drawDataLabelWithBackground method

void drawDataLabelWithBackground(
  1. int index,
  2. Canvas canvas,
  3. String dataLabel,
  4. Offset offset,
  5. int angle,
  6. TextStyle style,
  7. Paint fillPaint,
  8. Paint strokePaint,
)

Implementation

void drawDataLabelWithBackground(
  int index,
  Canvas canvas,
  String dataLabel,
  Offset offset,
  int angle,
  TextStyle style,
  Paint fillPaint,
  Paint strokePaint,
) {
  final EdgeInsets margin = dataLabelSettings.margin;
  final Offset settingsOffset = dataLabelSettings.offset;
  if (!dataLabelSettings.showZeroValue && dataLabel == '0') {
    return;
  }
  if (!offset.dx.isNaN && !offset.dy.isNaN) {
    if (dataLabel.isNotEmpty) {
      // TODO(VijayakumarM): Check and optimize.
      if (fillPaint.color != Colors.transparent ||
          (strokePaint.color != const Color.fromARGB(0, 25, 5, 5) &&
              strokePaint.strokeWidth > 0)) {
        final TextPainter textPainter = TextPainter(
          text: TextSpan(text: dataLabel, style: style),
          textDirection: TextDirection.ltr,
        )..layout();
        final RRect labelRect = RRect.fromRectAndRadius(
            Rect.fromLTWH(
              offset.dx + settingsOffset.dx,
              offset.dy - settingsOffset.dy,
              textPainter.width + margin.horizontal,
              textPainter.height + margin.vertical,
            ),
            Radius.circular(dataLabelSettings.borderRadius));
        canvas.save();
        canvas.translate(labelRect.center.dx, labelRect.center.dy);
        canvas.rotate((angle * pi) / 180);
        canvas.translate(-labelRect.center.dx, -labelRect.center.dy);
        if (strokePaint.color != Colors.transparent &&
            strokePaint.strokeWidth > 0) {
          canvas.drawRRect(labelRect, strokePaint);
        }

        if (fillPaint.color != Colors.transparent) {
          canvas.drawRRect(labelRect, fillPaint);
        }
        canvas.restore();
      }
    }
  }
  drawDataLabel(
      index,
      canvas,
      dataLabel,
      offset.dx + settingsOffset.dx + margin.left,
      offset.dy - settingsOffset.dy + margin.top,
      angle,
      style);
}