drawDataLabelWithBackground method

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,
)

Implementation

void drawDataLabelWithBackground(
  CircularChartDataLabelPositioned dataLabelPositioned,
  int index,
  Canvas canvas,
  String dataLabel,
  Offset offset,
  int angle,
  TextStyle style,
  Paint fillPaint,
  Paint strokePaint,
) {
  final SfChartThemeData chartThemeData = parent!.chartThemeData!;
  final ThemeData themeData = parent!.themeData!;
  final ChartSegment segment = segments[index];
  Color surfaceColor = dataLabelSurfaceColor(fillPaint.color, index,
      dataLabelSettings.labelPosition, chartThemeData, themeData, segment);
  TextStyle effectiveTextStyle = saturatedTextStyle(surfaceColor, style);
  final CircularChartPoint point = dataLabelPositioned.point!;
  if (!point.isVisible || !segments[index].isVisible) {
    return;
  }

  if (point.connectorPath != null) {
    // TODO(Lavanya): Recheck here.
    drawConnectorLine(point.connectorPath!, canvas, index);
  }

  if (point.saturationRegionOutside &&
      dataLabelSettings.labelPosition == ChartDataLabelPosition.inside &&
      dataLabelSettings.color == null &&
      !dataLabelSettings.useSeriesColor) {
    if (style.color == Colors.transparent) {
      surfaceColor = dataLabelSurfaceColor(fillPaint.color, index,
          ChartDataLabelPosition.outside, chartThemeData, themeData, segment);
      effectiveTextStyle = saturatedTextStyle(surfaceColor, style);
    }
  }

  // TODO(Lavanya): Handle data label animation.
  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);
}