effectiveDataLabelAlignment method
ChartDataLabelAlignment
effectiveDataLabelAlignment(
- ChartDataLabelAlignment alignment,
- ChartDataPointType position,
- ChartElementParentData? previous,
- ChartElementParentData current,
- ChartElementParentData? next,
Implementation
ChartDataLabelAlignment effectiveDataLabelAlignment(
ChartDataLabelAlignment alignment,
ChartDataPointType position,
ChartElementParentData? previous,
ChartElementParentData current,
ChartElementParentData? next,
) {
if (alignment == ChartDataLabelAlignment.auto) {
final bool isPrevEmpty = previous == null || previous.y!.isNaN;
final bool isNextEmpty = next == null || next.y!.isNaN;
if (isPrevEmpty && isNextEmpty) {
return ChartDataLabelAlignment.top;
} else if (isPrevEmpty) {
return current.y! < next!.y!
? ChartDataLabelAlignment.bottom
: ChartDataLabelAlignment.top;
} else if (isNextEmpty) {
return current.y! < previous.y!
? ChartDataLabelAlignment.bottom
: ChartDataLabelAlignment.top;
} else {
final num slope = (next.y! - previous.y!) / 2;
final num intersectY =
(slope * index) + (next.y! - (slope * (index + 1)));
return current.y! < intersectY
? ChartDataLabelAlignment.bottom
: ChartDataLabelAlignment.top;
}
} else {
return alignment;
}
}