drawDataLabelWithBackground method

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

Implementation

@override
void drawDataLabelWithBackground(
    CircularChartDataLabelPositioned dataLabelPositioned,
    int index,
    Canvas canvas,
    String dataLabel,
    Offset offset,
    int angle,
    TextStyle style,
    Paint fillPaint,
    Paint strokePaint) {
  final TextStyle effectiveTextStyle = parent!.themeData!.textTheme.bodySmall!
      .copyWith(color: Colors.black)
      .merge(parent!.chartThemeData!.dataLabelTextStyle)
      .merge(dataLabelSettings.textStyle);

  final CircularChartPoint point = dataLabelPositioned.point!;
  if (!point.isVisible || !segments[index].isVisible) {
    return;
  }

  final Rect labelRect = point.labelRect;
  canvas.save();
  canvas.translate(labelRect.center.dx, labelRect.center.dy);
  canvas.rotate((angle * pi) / 180);
  canvas.translate(-labelRect.center.dx, -labelRect.center.dy);
  if (dataLabelSettings.borderWidth > 0 &&
      strokePaint.color != Colors.transparent) {
    _drawLabelRect(
        strokePaint,
        Rect.fromLTRB(
            labelRect.left, labelRect.top, labelRect.right, labelRect.bottom),
        dataLabelSettings.borderRadius,
        canvas);
  }

  if (fillPaint.color != Colors.transparent) {
    _drawLabelRect(
        fillPaint,
        Rect.fromLTRB(
            labelRect.left, labelRect.top, labelRect.right, labelRect.bottom),
        dataLabelSettings.borderRadius,
        canvas);
  }
  canvas.restore();

  drawDataLabel(
      canvas, dataLabel, offset, effectiveTextStyle, dataLabelSettings.angle);
}