victory-native
Version:
A charting library for React Native with a focus on performance and customization.
48 lines (47 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMaxAxisLabelLayout = exports.getAxisLabelLayout = void 0;
const textLayout_1 = require("../../utils/textLayout");
const normalizeDimension = (value) => Number.isFinite(value) ? Math.max(0, value !== null && value !== void 0 ? value : 0) : 0;
const getAxisLabelLayout = ({ axis, orientation, value, text, index, font, labelRenderer, }) => {
var _a, _b, _c;
if (labelRenderer) {
const measurement = labelRenderer.measure({
axis,
orientation,
value,
text,
index,
});
const fontSize = normalizeDimension((_a = measurement.fontSize) !== null && _a !== void 0 ? _a : font === null || font === void 0 ? void 0 : font.getSize());
const lineHeight = normalizeDimension((_c = (_b = measurement.lineHeight) !== null && _b !== void 0 ? _b : measurement.fontSize) !== null && _c !== void 0 ? _c : fontSize);
return {
axis,
orientation,
value,
text,
index,
lines: [text],
width: normalizeDimension(measurement.width),
height: normalizeDimension(measurement.height),
fontSize,
lineHeight,
};
}
const layout = (0, textLayout_1.getTextLayout)(text, font);
return Object.assign({ axis,
orientation,
value,
text,
index }, layout);
};
exports.getAxisLabelLayout = getAxisLabelLayout;
const getMaxAxisLabelLayout = (labels) => {
return labels.reduce((max, label) => ({
width: Math.max(max.width, label.width),
height: Math.max(max.height, label.height),
fontSize: label.fontSize,
lineHeight: label.lineHeight,
}), { width: 0, height: 0, fontSize: 0, lineHeight: 0 });
};
exports.getMaxAxisLabelLayout = getMaxAxisLabelLayout;