dataLabelPosition method

Offset dataLabelPosition(
  1. ChartElementParentData current,
  2. Size size
)

Implementation

Offset dataLabelPosition(ChartElementParentData current, Size size) {
  final int segmentsLastIndex = segments.length - 1;
  final List<Offset> points =
      segments[segmentsLastIndex - current.dataPointIndex].points;
  final Rect region = _calculateSegmentRect(
      segments[segmentsLastIndex - current.dataPointIndex].points,
      segmentsLastIndex - current.dataPointIndex);
  final List<Offset> connectorPoints = segments[0].points;
  final double connectorLength = _calculateConnectorLength(
    connectorPoints,
    dataLabelSettings,
  );

  final Offset insideLabelOffset =
      dataLabelSettings.labelPosition == ChartDataLabelPosition.inside
          ? Offset(region.left + region.width / 2 - size.width / 2,
              region.top + region.height / 2 - size.height / 2)
          : Offset((points[0].dx + points[1].dx) / 2 - size.width / 2,
              (points[0].dy + points[2].dy) / 2 - size.height / 2);
  final double connectorLengthWithXValue =
      insideLabelOffset.dx + connectorLength + size.width / 2;
  final Offset outsideLabelOffset = Offset(
      (connectorLengthWithXValue +
                  size.width +
                  dataLabelSettings.margin.left +
                  dataLabelSettings.margin.right >
              paintBounds.right)
          ? connectorLengthWithXValue -
              (percentToValue(explodeOffset, paintBounds.width)!)
          : connectorLengthWithXValue,
      insideLabelOffset.dy);
  final Offset finalOffset =
      dataLabelSettings.labelPosition == ChartDataLabelPosition.inside
          ? insideLabelOffset
          : outsideLabelOffset;

  return finalOffset;
}