dataLabelPosition method
Offset
dataLabelPosition(
- ChartElementParentData current,
- Size size
)
Implementation
Offset dataLabelPosition(ChartElementParentData current, Size size) {
final List<Offset> points = segments[current.dataPointIndex].points;
final List<Offset> connectorPoints = segments[segments.length - 1].points;
final double connectorLength = _calculateConnectorLength(
connectorPoints,
dataLabelSettings,
);
final Offset insideLabelOffset = 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;
}