UNPKG

react-native-chart-kit

Version:

Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.

41 lines (40 loc) 1.18 kB
export const clamp = (value, min, max) => { if (max < min) { return min; } return Math.min(Math.max(value, min), max); }; export const unique = (values) => { return values.filter((value, index) => values.indexOf(value) === index); }; export const getSeriesColor = (theme, index) => { return theme.series[index % theme.series.length] ?? "#2563eb"; }; export const defaultFormatXLabel = (value) => { if (value instanceof Date) { return value.toLocaleDateString("en-US", { month: "short", day: "numeric" }); } return String(value); }; export const defaultFormatYLabel = (value) => { const absolute = Math.abs(value); if (absolute >= 1000) { return `${Number((value / 1000).toFixed(1))}k`; } return String(Number(value.toFixed(2))); }; export const getXKey = (value) => { return value instanceof Date ? value.valueOf() : value; }; export const getXScaleType = (values) => { if (values.every((value) => value instanceof Date)) { return "time"; } if (values.every((value) => typeof value === "number")) { return "linear"; } return "point"; };