react-native-chart-kit
Version:
Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.
23 lines (22 loc) • 776 B
JavaScript
export const normalizePadding = (padding = {}) => ({
top: padding.top ?? 0,
right: padding.right ?? 0,
bottom: padding.bottom ?? 0,
left: padding.left ?? 0
});
export const createRect = (x, y, width, height) => ({
x,
y,
width: Math.max(0, width),
height: Math.max(0, height)
});
export const solveChartBoxes = (size, padding = {}) => {
const normalizedPadding = normalizePadding(padding);
const outer = createRect(0, 0, size.width, size.height);
const plot = createRect(normalizedPadding.left, normalizedPadding.top, size.width - normalizedPadding.left - normalizedPadding.right, size.height - normalizedPadding.top - normalizedPadding.bottom);
return {
outer,
plot,
padding: normalizedPadding
};
};