fix(map): anchor timeline offsets to the Now slot, not wall-clock
When wall-clock is past :30, the hour *after* Now rounded to "0h" and the Now slot kept its "Now" tag — two adjacent buttons both reading as the current hour. Anchor the offset math to the Now slot itself so the label sequence reads "-1h / Now / +1h / +2h" regardless of where inside the hour the user loaded the page.
This commit is contained in:
parent
fd48263992
commit
9db9e6a893
1 changed files with 8 additions and 3 deletions
|
|
@ -1326,8 +1326,7 @@ export const PropagationMap: Record<string, unknown> & {
|
|||
const dt = new Date(t.time)
|
||||
const isSelected = t.time === this.selectedTime
|
||||
const isPast = dt.getTime() < now.getTime() - 1800000 // 30min grace
|
||||
const offsetH = Math.round((dt.getTime() - now.getTime()) / 3600000)
|
||||
return { ...t, dt, isSelected, isPast, offsetH, idx, label: "" }
|
||||
return { ...t, dt, isSelected, isPast, offsetH: 0, idx, label: "" }
|
||||
})
|
||||
|
||||
// "Now" = the latest forecast hour at or before wall-clock. Picking
|
||||
|
|
@ -1343,11 +1342,17 @@ export const PropagationMap: Record<string, unknown> & {
|
|||
? items.indexOf(pastOrNow.reduce((latest, t) => t.dt.getTime() > latest.dt.getTime() ? t : latest))
|
||||
: -1
|
||||
|
||||
// Label offsets relative to the "Now" slot, not wall-clock. If we
|
||||
// round from wall-clock, the hour after "Now" rounds to "0h" when
|
||||
// the clock is past the half-hour, which reads as a second "now".
|
||||
const anchorMs = nowIdx >= 0 ? items[nowIdx].dt.getTime() : nowMs
|
||||
items.forEach((t, i) => {
|
||||
const diff = Math.round((t.dt.getTime() - anchorMs) / 3600000)
|
||||
t.offsetH = diff
|
||||
|
||||
if (i === nowIdx) {
|
||||
t.label = "Now"
|
||||
} else {
|
||||
const diff = t.offsetH
|
||||
t.label = diff > 0 ? `+${diff}h` : `${diff}h`
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue