diff options
| author | Terry Truong <terry06890@gmail.com> | 2023-01-07 12:37:05 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2023-01-07 12:37:05 +1100 |
| commit | e5d4b142f6f7eb21c2b55edfbd472f503e7f3b89 (patch) | |
| tree | 7a91ccd3d970dfc9e154ca498c36a7870d4b8d39 /src/lib.ts | |
| parent | cd890bc47df00f16c54755549314cd7e15ec3219 (diff) | |
At each scale, always display a unit that includes MAX_DATEunit-after-max
Without this, with a MAX_DATE of, say 2000/1/1, zooming out to
scale 1e9 won't show events after 1 AD.
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -582,14 +582,31 @@ export function dateToUnit(date: HistDate, scale: number): number { } } } -export function dateToScaleDate(date: HistDate, scale: number): HistDate { +export function dateToScaleDate(date: HistDate, scale: number, upward=false): HistDate { // Returns a date representing the unit on 'scale' that 'date' is within if (scale == DAY_SCALE){ return new CalDate(date.year, date.month, date.day); } else if (scale == MONTH_SCALE){ - return new CalDate(date.year, date.month, 1); + if (upward && date.day > 1){ + return stepDate(new CalDate(date.year, date.month, 1), MONTH_SCALE); + } else { + return new CalDate(date.year, date.month, 1); + } + } else if (scale == 1){ + if (upward && date.month > 1){ + return stepDate(new CalDate(date.year, 1, 1), 1); + } else { + if (date.year < MIN_CAL_YEAR){ + return new YearDate(date.year); + } else { + return new CalDate(date.year == 0 ? 1 : date.year, 1, 1); + } + } } else { - const year = Math.floor(date.year / scale) * scale; + let year = Math.floor(date.year / scale) * scale; + if (upward && moduloPositive(date.year, scale) > 0){ + year += scale; + } if (year < MIN_CAL_YEAR){ return new YearDate(year); } else { |
