calcMaxLabelWidthWithTransform function
double
calcMaxLabelWidthWithTransform(
- List<
String> labels, { - required FluentChartTextMeasurer measurer,
- required TextStyle style,
- required FluentChartAxisType xAxisType,
- bool wrapXAxisLabels = false,
- bool rotateXAxisLabels = false,
- bool showXAxisLabelsTooltip = false,
- int noOfCharsToTruncate = 4,
The widest tick label, measured after whatever transform the axis will apply.
Ports _calcMaxLabelWidthWithTransform (CartesianChart.tsx:576-612). The
four branches run in this order and the first match wins: rotated band labels
shrink by cos(pi/4); tooltip mode measures the truncated form; wrapping mode
measures individual words and floors the answer at kDefaultWrapWidth;
otherwise the labels are measured as they are. Every branch ceils.
Implementation
double calcMaxLabelWidthWithTransform(
List<String> labels, {
required FluentChartTextMeasurer measurer,
required TextStyle style,
required FluentChartAxisType xAxisType,
bool wrapXAxisLabels = false,
bool rotateXAxisLabels = false,
bool showXAxisLabelsTooltip = false,
int noOfCharsToTruncate = 4,
}) {
if (!wrapXAxisLabels &&
rotateXAxisLabels &&
xAxisType == FluentChartAxisType.category) {
final longest = measurer.longestWidth(labels, style);
return (longest * math.cos(math.pi / 4)).ceilToDouble();
}
if (showXAxisLabelsTooltip) {
final truncated = <String>[
// CartesianChart.tsx:587 compares the whole length against the budget, so
// a label of exactly noOfCharsToTruncate code units is left alone.
for (final label in labels)
if (label.length > noOfCharsToTruncate)
'${label.substring(0, noOfCharsToTruncate)}...'
else
label,
];
return measurer.longestWidth(truncated, style).ceilToDouble();
}
if (wrapXAxisLabels) {
// FIXME upstream: CartesianChart.tsx:596-597 notes this measures words
// rather than wrapped lines, which is close enough because overflow only
// happens when a single word exceeds the width.
final words = <String>[
for (final label in labels) ...label.split(RegExp(r'\s+')),
];
return math.max(
measurer.longestWidth(words, style).ceilToDouble(),
kDefaultWrapWidth,
);
}
return measurer.longestWidth(labels, style).ceilToDouble();
}