From 1c76bf712516fb69db63e1433c1cec8a00f48f74 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Mon, 26 Dec 2022 15:51:20 +1100 Subject: Make minor ticks more evenly spread Fix getNumDisplayUnits() not account for lack of 0 CE Add getNumSubUnits() in lib.ts --- src/lib.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib.ts') diff --git a/src/lib.ts b/src/lib.ts index 8cbd937..fdabe4b 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -451,6 +451,19 @@ export function getScaleRatio(scale: number, scale2: number, lowerVal=false){ } return scale2 / scale; } +export function getNumSubUnits(date: HistDate, scaleIdx: number){ + // Returns number of sub-units for a unit starting at 'date' on scale for 'scaleIdx' + const scale = SCALES[scaleIdx] + if (scale == DAY_SCALE){ + throw new Error('Cannot get sub-units for DAY_SCALE unit'); + } else if (scale == MONTH_SCALE){ + return getDaysInMonth(date.year, date.month); // Note: Intentionally not checking with MIN_CAL_YEAR + } else if (scale == 1){ + return 12; + } else { + return scale / SCALES[scaleIdx + 1] - (date.year == 1 ? 1 : 0); // Account for lack of 0 CE + } +} export function getUnitDiff(date: HistDate, date2: HistDate, scale: number): number { if (scale == DAY_SCALE){ return date.getDayDiff(date2); -- cgit v1.2.3