diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-12-27 21:14:35 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-12-27 21:15:46 +1100 |
| commit | a96fa2c3e331e28837cf0b5a7734fbb5ab4fadf0 (patch) | |
| tree | 47cc72aaa5818e875a11d5f11afe64ae731f1e18 /src/lib.ts | |
| parent | 4261c285072a88e7fd7f631f46fdbc40fa9f14a7 (diff) | |
Avoid dashed event-line at scales at/above event-start precision
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -473,6 +473,26 @@ export function getUnitDiff(date: HistDate, date2: HistDate, scale: number): num return date.getYearDiff(date2) / scale; } } +export function getEventPrecision(event: HistEvent): number { + // Returns smallest scale at which 'event's start-startUpper range is within one unit, or infinity + // Note: Intentionally not adding an exception for century and millenia ranges like + // 101 to 200 (as opposed to 100 to 199) being interpreted as 'within' one 100/1000-year scale unit + const {start, startUpper} = event; + if (startUpper == null || start.getDayDiff(startUpper) == 0){ + return DAY_SCALE; + } + if (start.getMonthDiff(startUpper) == 0){ + return MONTH_SCALE; + } + const yearScaleIdx = SCALES.length - 1 - 2; + for (let scaleIdx = yearScaleIdx; scaleIdx >= 0; scaleIdx--){ + const scale = SCALES[scaleIdx]; + if (Math.floor(start.year / scale) == Math.floor(startUpper.year / scale)){ + return scale; + } + } + return Number.POSITIVE_INFINITY; +} // For sending timeline-bound data to BaseLine export class TimelineState { |
