dataLabelPosition method

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

Implementation

Offset dataLabelPosition(
  ChartElementParentData current,
  ChartDataLabelAlignment alignment,
  Size size,
) {
  double markerHeightWithPadding = dataLabelPadding;
  double markerWidthWithPadding = dataLabelPadding;
  if (markerSettings.isVisible) {
    final ChartMarker marker = markerAt(current.dataPointIndex);
    markerHeightWithPadding += marker.height / 2;
    markerWidthWithPadding += marker.width / 2;
  }

  final EdgeInsets margin = dataLabelSettings.margin;
  double translationX = 0.0;
  double translationY = 0.0;
  switch (alignment) {
    case ChartDataLabelAlignment.outer:
    case ChartDataLabelAlignment.top:
      if (isTransposed) {
        translationX = markerWidthWithPadding;
        translationY = -margin.top;
      } else {
        translationX = -margin.left;
        translationY =
            -(markerHeightWithPadding + size.height + margin.vertical);
      }
      return translateTransform(
          current.x!, current.y!, translationX, translationY);

    case ChartDataLabelAlignment.bottom:
      if (isTransposed) {
        translationX =
            -(markerWidthWithPadding + size.width + margin.horizontal);
        translationY = -margin.top;
      } else {
        translationX = -margin.left;
        translationY = markerHeightWithPadding;
      }
      return translateTransform(
          current.x!, current.y!, translationX, translationY);

    case ChartDataLabelAlignment.auto:
    case ChartDataLabelAlignment.middle:
      if (isTransposed) {
        translationX = -margin.left - size.width / 2;
        translationY = -margin.top;
      } else {
        translationX = -margin.left;
        translationY = -margin.top - size.height / 2;
      }
      return translateTransform(
          current.x!, current.y!, translationX, translationY);
  }
}