calculateHeightForRotatedLabel method
Returns the height of a rotated labels on a domain axis.
Implementation
double calculateHeightForRotatedLabel(
int rotation,
double labelHeight,
double labelLength,
) {
if (rotation == 0) return labelHeight;
final rotationRadian = _degToRad(rotation.toDouble());
// Imagine a right triangle with a base that is parallel to the axis
// baseline. The side of this triangle that is perpendicular to the baseline
// is the height of the axis we wish to calculate. The hypotenuse of the
// triangle is the given length of the tick labels, labelLength. The angle
// between the perpendicular line and the hypotenuse (the tick label) is 90
// - the label rotation angle, since the tick label transformation is
// applied relative to the axis baseline. Given this triangle, we can
// calculate the height of the axis by using the cosine of this angle.
// The triangle assumes a zero-height line for the labels, but the actual
// rendered text will be drawn above and below this center line. To account
// for this, extend the label length by using a triangle with half the
// height of the label.
labelLength += labelHeight / 2.0 * tan(rotationRadian);
// To compute the label height, we need the angle between the label and a
// line perpendicular to the axis baseline, in radians.
final angle = pi / 2.0 - rotationRadian.abs();
return max(labelHeight, labelLength * cos(angle));
}