@antv/scale
Version:
Toolkit for mapping abstract data into visual representation.
16 lines (14 loc) • 564 B
text/typescript
import { IntervalMap } from './time-interval';
export function chooseNiceTimeMask(date: Date, intervalMap: IntervalMap): string {
const { second, minute, hour, day, week, month, year } = intervalMap;
if (second.floor(date) < date) return '.SSS';
if (minute.floor(date) < date) return ':ss';
if (hour.floor(date) < date) return 'hh:mm';
if (day.floor(date) < date) return 'hh A';
if (month.floor(date) < date) {
if (week.floor(date) < date) return 'MMM DD';
return 'ddd DD';
}
if (year.floor(date) < date) return 'MMMM';
return 'YYYY';
}