dataLabelPosition method
Offset
dataLabelPosition(
- ChartElementParentData current,
- ChartDataLabelAlignment alignment,
- 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;
final num y = current.y!;
switch (alignment) {
case ChartDataLabelAlignment.outer:
case ChartDataLabelAlignment.top:
if (isTransposed) {
translationX = y.isNegative
? -(markerWidthWithPadding + size.width + margin.horizontal)
: markerWidthWithPadding;
translationY = -margin.top;
} else {
translationX = -margin.left;
translationY = y.isNegative
? markerHeightWithPadding
: -(markerHeightWithPadding + size.height + margin.vertical);
}
return translateTransform(current.x!, y, translationX, translationY);
case ChartDataLabelAlignment.bottom:
if (isTransposed) {
translationX = y.isNegative
? markerWidthWithPadding
: -(markerWidthWithPadding + size.width + margin.horizontal);
translationY = -margin.top;
} else {
translationX = -margin.left;
translationY = y.isNegative
? -(markerHeightWithPadding + size.height + margin.vertical)
: markerHeightWithPadding;
}
return translateTransform(current.x!, 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);
}
}