UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

20 lines (19 loc) 729 B
import { scaleTime } from '@mui/x-charts-vendor/d3-scale'; /** * Checks if the provided data array contains Date objects. * @param data The data array to check. * @returns A type predicate indicating if the data is an array of Date objects. */ export const isDateData = data => data?.[0] instanceof Date; /** * Creates a formatter function for date values. * @param axis The axis configuration. * @param range The range for the time scale. * @returns A formatter function for date values. */ export function createDateFormatter(axis, range) { const timeScale = scaleTime(axis.data, range); return (v, { location }) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`; }