mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Make the world timeline a scrubber under the dock
The timeline shows whenever a layer with time to show is on, live or not. Its track runs over the time those layers cover, reaching to now, with a tick for each launch or frame and a handle to drag; arrows step between the ticks, and a scrub to now goes live. The bar sits along the bottom of the screen, and the dock and everything anchored above it rise by its height; clean view, recording and the cockpit put it away with the dock.
This commit is contained in:
1 parent
9faec3028e
commit
48093108b1
15 files changed
+445
-81
No files matched your search
@@ -1,5 +1,5 @@
|
||||
// The world timeline shows the world time while it is away from live, with
|
||||
// play and pause on the left and the way back to live on the right.
|
||||
// The world timeline shows the world time while a layer with time to show is
|
||||
// on, with play and pause on the left and the way back to live on the right.
|
||||
import '../../../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -7,13 +7,17 @@ import { createApp, nextTick } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import { worldClock } from '../../../time/worldClock.js';
|
||||
import WorldTimeline from './WorldTimeline.vue';
|
||||
import { useWorldTimeStore } from '../../stores/worldTime.js';
|
||||
|
||||
function mount(t) {
|
||||
document.body.replaceChildren();
|
||||
const app = createApp(WorldTimeline).use(createPinia());
|
||||
const pinia = createPinia();
|
||||
const app = createApp(WorldTimeline).use(pinia);
|
||||
app.mount(document.body.appendChild(document.createElement('div')));
|
||||
t.after(() => {
|
||||
app.unmount();
|
||||
// The store outlives the view; dispose it with its clock subscription.
|
||||
useWorldTimeStore(pinia).$dispose();
|
||||
worldClock.goLive();
|
||||
});
|
||||
return () => document.getElementById('world-timeline');
|
||||
@@ -36,12 +40,15 @@ function supportingLayer(t, at) {
|
||||
};
|
||||
}
|
||||
|
||||
test('the timeline shows away from live and plays, pauses and goes back', async (t) => {
|
||||
test('the timeline shows live, and plays, pauses and goes back', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.UTC(2026, 9, 30, 6, 15, 42);
|
||||
supportingLayer(t, at);
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'hidden while live');
|
||||
assert.ok(bar(), 'shown while live');
|
||||
const live = bar().querySelector('.world-timeline-live');
|
||||
assert.equal(live.disabled, true, 'already live');
|
||||
assert.equal(live.getAttribute('aria-pressed'), 'true');
|
||||
|
||||
worldClock.seek(at);
|
||||
await nextTick();
|
||||
@@ -60,15 +67,19 @@ test('the timeline shows away from live and plays, pauses and goes back', async
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), false);
|
||||
|
||||
assert.equal(bar().querySelector('.world-timeline-live').disabled, false);
|
||||
bar().querySelector('.world-timeline-live').click();
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), true);
|
||||
assert.equal(bar(), null);
|
||||
assert.ok(bar(), 'still shown, live');
|
||||
assert.equal(bar().querySelector('.world-timeline-live').disabled, true);
|
||||
});
|
||||
|
||||
test('the timeline hides while no layer with time to show is on', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.UTC(2026, 9, 30, 6, 15, 42);
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'live, nothing to play');
|
||||
worldClock.seek(at);
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'away from live, but nothing to play');
|
||||
@@ -79,3 +90,61 @@ test('the timeline hides while no layer with time to show is on', async (t) => {
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'the layer went off');
|
||||
});
|
||||
|
||||
test('the track runs over the time the layers show, to now, and scrubs', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const at = now - 2 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start: at - 86_400_000, end: at, marks: [at - 86_400_000, at] }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
assert.equal(Number(input.min), at - 86_400_000);
|
||||
assert.ok(Number(input.max) >= now, 'reaches to now');
|
||||
assert.equal(bar().querySelectorAll('.world-timeline-tick').length, 2);
|
||||
|
||||
worldClock.play();
|
||||
input.value = String(at);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), false, 'a scrub stops playback');
|
||||
assert.equal(worldClock.now(), at);
|
||||
assert.equal(bar().querySelector('time').getAttribute('datetime'), new Date(at).toISOString());
|
||||
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), at - 86_400_000, 'the arrow goes to the previous mark');
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), at, 'and back to the next');
|
||||
|
||||
input.value = String(Date.now() + 2_000);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), true, 'a scrub to now goes live');
|
||||
|
||||
// A layer that reaches ahead of now, as satellites do.
|
||||
const holdAhead = worldClock.hold('test-ahead');
|
||||
const unregisterAhead = worldClock.register({
|
||||
id: 'test-ahead',
|
||||
coverage: () => ({ start: now, end: now + 3 * 86_400_000 }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterAhead();
|
||||
holdAhead();
|
||||
});
|
||||
await nextTick();
|
||||
const ahead = Date.now() + 86_400_000;
|
||||
input.value = String(ahead);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), false, 'a scrub past now stays there');
|
||||
assert.equal(worldClock.now(), ahead);
|
||||
});
|
||||
@@ -6,11 +6,12 @@ import { useWorldTimeStore } from '../../stores/worldTime.js';
|
||||
import UiButton from '../../kit/UiButton.vue';
|
||||
import UiIcon from '../../kit/UiIcon.vue';
|
||||
|
||||
// The world time while it is away from live: what is playing, or where it
|
||||
// was paused, with play and pause on the left and the way back to live on
|
||||
// the right. It shows only while a layer with a time of its own (weather,
|
||||
// satellites, launches, or one a host follows) is on with time to show; live,
|
||||
// or with only live feeds such as flights on, the bar stays hidden.
|
||||
// The world timeline: play and pause on the left, the time, a track across
|
||||
// the stretch the layers on can show (each launch or frame a tick) with a
|
||||
// handle to scrub, and the way back to live on the right, lit while live. It
|
||||
// shows while a layer with a time of its own (weather, satellites, launches,
|
||||
// or one a host follows) is on with time to show; with only live feeds such
|
||||
// as flights on, the bar stays hidden.
|
||||
const store = useWorldTimeStore();
|
||||
const { time } = storeToRefs(store);
|
||||
|
||||
@@ -19,18 +20,76 @@ const DATE_TIME = Object.freeze({
|
||||
timeStyle: 'medium',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
const EDGE_DATE = Object.freeze({
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
// The keyboard's fallback step, as a share of the track, with no mark to go to.
|
||||
const KEY_STEP = 0.01;
|
||||
const PAGE_STEP = 0.1;
|
||||
|
||||
const readout = computed(() =>
|
||||
Number.isFinite(time.value.timeMs)
|
||||
? `${formatDate(time.value.timeMs, DATE_TIME)} UTC`
|
||||
: '',
|
||||
);
|
||||
const span = computed(() => time.value.span);
|
||||
const at = computed(() => {
|
||||
const { start, end } = span.value;
|
||||
return Math.min(end, Math.max(start, time.value.timeMs));
|
||||
});
|
||||
const place = (ms) => {
|
||||
const { start, end } = span.value;
|
||||
return end > start ? ((ms - start) / (end - start)) * 100 : 100;
|
||||
};
|
||||
const ticks = computed(() =>
|
||||
span.value.marks.map((mark) => `${place(mark)}%`),
|
||||
);
|
||||
const scrub = (event) => store.scrub(Number(event.target.value));
|
||||
// Arrows go to the previous or next mark (a launch, a frame), or a step along
|
||||
// the track; Page keys take a tenth of it; Home and End go to its ends.
|
||||
const onKey = (event) => {
|
||||
const { start, end, marks } = span.value;
|
||||
const now = at.value;
|
||||
const length = end - start;
|
||||
let to = null;
|
||||
if (event.key === 'ArrowLeft' || event.key === 'ArrowDown')
|
||||
to = marks.findLast((mark) => mark < now) ?? now - length * KEY_STEP;
|
||||
else if (event.key === 'ArrowRight' || event.key === 'ArrowUp')
|
||||
to = marks.find((mark) => mark > now) ?? now + length * KEY_STEP;
|
||||
else if (event.key === 'PageDown') to = now - length * PAGE_STEP;
|
||||
else if (event.key === 'PageUp') to = now + length * PAGE_STEP;
|
||||
else if (event.key === 'Home') to = start;
|
||||
else if (event.key === 'End') to = end;
|
||||
if (to === null) return;
|
||||
event.preventDefault();
|
||||
store.scrub(Math.min(end, Math.max(start, to)));
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="!time.live && time.supported" id="world-timeline" role="group" :aria-label="t('World time')"
|
||||
<div v-if="time.supported && time.span" id="world-timeline" role="group" :aria-label="t('World time')"
|
||||
><UiButton class="world-timeline-play" :label="time.playing ? t('Pause') : t('Play')" @click="store.togglePlay()"
|
||||
><UiIcon :name="time.playing ? 'pause' : 'play_arrow'" :size="20" /></UiButton
|
||||
><time class="world-timeline-time" :datetime="new Date(time.timeMs).toISOString()" aria-live="off">{{ readout }}</time
|
||||
><UiButton class="world-timeline-live" :label="t('Back to live')" @click="store.goLive()">{{ t('Live') }}</UiButton
|
||||
><span class="world-timeline-edge">{{ formatDate(span.start, EDGE_DATE) }}</span
|
||||
><div class="world-timeline-track"
|
||||
><span v-for="(left, index) in ticks" :key="index" class="world-timeline-tick" :style="{ left }" aria-hidden="true"></span
|
||||
><span class="world-timeline-fill" :style="{ width: `${place(at)}%` }" aria-hidden="true"></span
|
||||
><input
|
||||
class="world-timeline-scrub"
|
||||
type="range"
|
||||
:aria-label="t('World time')"
|
||||
:aria-valuetext="readout"
|
||||
:min="span.start"
|
||||
:max="span.end"
|
||||
step="any"
|
||||
:value="at"
|
||||
@input="scrub"
|
||||
@keydown="onKey"
|
||||
/></div
|
||||
><span class="world-timeline-edge">{{ formatDate(span.end, EDGE_DATE) }}</span
|
||||
><UiButton class="world-timeline-live" :label="time.live ? t('Live') : t('Back to live')" :pressed="time.live" pressed-class="is-live" :disabled="time.live" @click="store.goLive()">{{ t('Live') }}</UiButton
|
||||
></div>
|
||||
</template>
|
||||
Reference in new issue
Block a user