@mui/x-charts
Version:
The community edition of MUI X Charts components.
28 lines (26 loc) • 920 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDateFormatter = createDateFormatter;
exports.isDateData = void 0;
var _d3Scale = require("@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.
*/
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.
*/
exports.isDateData = isDateData;
function createDateFormatter(axis, range) {
const timeScale = (0, _d3Scale.scaleTime)(axis.data, range);
return (v, {
location
}) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
}
;