react-native-chart-kit
Version:
Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.
24 lines (23 loc) • 902 B
JavaScript
import { dedupeXLabelCandidates } from "./xLabels";
export const buildXLabelCandidates = ({ dataIndexOffset, labelStrategy, series, xLabelSizes, xLabelTexts, xScale, xValues }) => {
const candidates = xValues.flatMap((value, index) => {
const point = series?.points[index];
const x = point ? xScale(value, point) : undefined;
const text = xLabelTexts[index];
const size = xLabelSizes[index];
if (x === undefined || text === undefined || size === undefined) {
return [];
}
return [
{
index: index + dataIndexOffset,
value,
text,
x,
size
}
];
});
const shouldDedupeLabels = labelStrategy === "auto" || labelStrategy === "skip";
return shouldDedupeLabels ? dedupeXLabelCandidates(candidates) : candidates;
};