effectiveDataLabelAlignment method

  1. @override
ChartDataLabelAlignment effectiveDataLabelAlignment(
  1. ChartDataLabelAlignment alignment,
  2. ChartDataPointType position,
  3. ChartElementParentData? previous,
  4. ChartElementParentData current,
  5. ChartElementParentData? next,
)
override

Implementation

@override
ChartDataLabelAlignment effectiveDataLabelAlignment(
  ChartDataLabelAlignment alignment,
  ChartDataPointType position,
  ChartElementParentData? previous,
  ChartElementParentData current,
  ChartElementParentData? next,
) {
  final int index = current.dataPointIndex;
  if (position == ChartDataPointType.open) {
    final num lower = lowerValues[index];
    final num upper = upperValues[index];

    return lower >= upper
        ? ChartDataLabelAlignment.top
        : ChartDataLabelAlignment.bottom;
  } else if (position == ChartDataPointType.close) {
    final num lower = lowerValues[index];
    final num upper = upperValues[index];
    return upper <= lower
        ? ChartDataLabelAlignment.top
        : ChartDataLabelAlignment.bottom;
  } else if (position == ChartDataPointType.outliers) {
    return ChartDataLabelAlignment.bottom;
  } else if (position == ChartDataPointType.median) {
    return ChartDataLabelAlignment.middle;
  }

  return alignment == ChartDataLabelAlignment.auto
      ? ChartDataLabelAlignment.outer
      : alignment;
}