dataLabelPosition method

  1. @override
Offset dataLabelPosition(
  1. CircularDataLabelBoxParentData current,
  2. Size size
)
override

Implementation

@override
Offset dataLabelPosition(CircularDataLabelBoxParentData current, Size size) {
  const int labelPadding = 2;
  final num angle = dataLabelSettings.angle;

  final RadialBarSegment<T, D> segment =
      segments[current.dataPointIndex] as RadialBarSegment<T, D>;
  current.point!
    ..degree = segment._degree
    ..isVisible = segment.isVisible
    ..startAngle = segment._startAngle
    ..endAngle = segment._endAngle
    ..midAngle = (segment._startAngle + segment._endAngle) / 2
    ..innerRadius = segment._innerRadius
    ..outerRadius = segment._outerRadius
    ..center = center
    ..fill = palette[current.dataPointIndex % palette.length];
  final CircularChartPoint point = current.point!;

  Offset labelLocation = calculateOffset(point.startAngle!,
      (point.innerRadius! + point.outerRadius!) / 2, point.center!);
  labelLocation = Offset(
      (labelLocation.dx - size.width - 5) + (angle == 0 ? 0 : size.width / 2),
      (labelLocation.dy - size.height / 2) +
          (angle == 0 ? 0 : size.height / 2));
  if (point.isVisible && (point.y == 0 && !dataLabelSettings.showZeroValue)) {
    point.isVisible = false;
    return labelLocation;
  }
  if (size.width > 0 && size.height > 0) {
    point.labelRect = Rect.fromLTWH(
        labelLocation.dx - labelPadding,
        labelLocation.dy - labelPadding,
        size.width + (2 * labelPadding),
        size.height + (2 * labelPadding));
  } else {
    point.labelRect = Rect.zero;
  }
  return labelLocation;
}