in packages/charts/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts [214:294]
function fill<C>(
shapeConstructor: ShapeConstructor<C>,
getShapeRowGeometry: GetShapeRowGeometry<C>,
getRotation: GetRotation,
) {
return function fillClosure(
fillLabel: FillLabelConfig,
layers: Layer[],
measure: TextMeasure,
rawTextGetter: RawTextGetter,
valueGetter: ValueGetterFunction,
formatter: ValueFormatter,
maxRowCount: number,
leftAlign: boolean,
middleAlign: boolean,
) {
const horizontalAlignment = leftAlign ? HorizontalAlignment.left : HorizontalAlignment.center;
return (allFontSizes: Pixels[][], textFillOrigin: PointTuple, node: QuadViewModel): RowSet => {
const container = shapeConstructor(node);
const rotation = getRotation(node);
const layer = layers[node.depth - 1];
if (!layer) {
throw new Error(`Failed to find layer at ${node.depth - 1}`);
}
const verticalAlignment = middleAlign
? VerticalAlignments.middle
: node.depth < layers.length
? VerticalAlignments.bottom
: VerticalAlignments.top;
const fontSizes = allFontSizes[Math.min(node.depth, allFontSizes.length) - 1] ?? [];
const { fontStyle, fontVariant, fontFamily, fontWeight, valueFormatter, padding, clipText } = {
...fillLabel,
valueFormatter: formatter,
...layer.fillLabel,
...layer.shape,
};
const valueFont = {
...fillLabel,
...fillLabel.valueFont,
...layer.fillLabel,
...layer.fillLabel?.valueFont,
};
const sizeInvariantFont: Font = {
fontStyle,
fontVariant,
fontWeight,
fontFamily,
textColor: node.textColor,
};
const isRtlString = isRTLString(rawTextGetter(node));
const allBoxes = getAllBoxes(rawTextGetter, valueGetter, valueFormatter, sizeInvariantFont, valueFont, node);
const [cx, cy] = textFillOrigin;
return {
...getRowSet(
allBoxes,
maxRowCount,
fontSizes,
measure,
rotation,
verticalAlignment,
horizontalAlignment,
container,
getShapeRowGeometry,
cx,
cy,
padding,
node,
clipText,
isRtlString,
),
fillTextColor: node.textColor,
};
};
};
}