mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Timeline marks carry labels; a tap by a tick goes to its mark
A layer's world clock coverage may now give each mark as an object,
{ time, label?, id?, kind? }, as well as a bare epoch ms number, and the
two may be mixed. worldClock.coverage() keeps marks as the sorted list of
distinct times, so existing readers are unchanged, and adds markDetails:
the merged marks in time order (then kind, label and id), each frozen and
holding only the fields given. Marks given alike by several sources appear
once, a bare time is dropped where a labelled mark shares it, and a mark
with no finite time is ignored. The contract is documented in the
worldClock JSDoc and docs/APPLICATION.md.
Launches label their marks with the mission's name (the launch's where it
has none), cut to 27 characters in capitals as the mission index shows
names. Earthquakes of magnitude 6 and up label theirs with the magnitude
as the map shows it and the feed's place cut to 40 characters, such as
"M6.4 · 113 km SSE of Lata, Solomon Islands"; the layer now tells the clock
when the labels change as well as the times.
On the timeline, a pointer within 6 px of a tick shows its label over the
track (nothing for an unlabelled mark), and a tap there goes exactly to
the mark's time instead of the point tapped. A tap elsewhere and a drag
work as before, and ticks stay ticks. The arrow keys still step from mark
to mark; with the handle on a mark, its labels follow the time in the
handle's aria-valuetext, and show over the track while it has focus.
This commit is contained in:
1 parent
900c76425c
commit
4f23ad330c
17 files changed
+487
-48
No files matched your search
@@ -581,3 +581,91 @@ test('a pinch measures from where the fingers are, and a lifted finger ends it',
|
||||
assert.ok(Math.abs(length() - zoomedTo) < 1_000);
|
||||
on(input, 'pointercancel', 100, 1);
|
||||
});
|
||||
|
||||
test('a tick shows its label on hover, and a tap by it goes to its mark', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 10 * 86_400_000;
|
||||
// Ticks a fifth and seven tenths along a 1000 px track.
|
||||
const launch = start + (now - start) * 0.2;
|
||||
const quake = start + (now - start) * 0.7;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({
|
||||
start,
|
||||
end: now,
|
||||
marks: [
|
||||
start,
|
||||
{ time: launch, label: 'GAUNTLET PAYLOAD', id: 'l1', kind: 'launch' },
|
||||
{ time: quake, label: 'M6.4 · Fiji', kind: 'earthquake' },
|
||||
],
|
||||
}),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const track = bar().querySelector('.world-timeline-track');
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
Object.defineProperty(track, 'clientWidth', { value: 1_000 });
|
||||
track.getBoundingClientRect = () => ({ left: 0, width: 1_000, top: 0, height: 24 });
|
||||
const press = (type, clientX, pointerId = 1) =>
|
||||
track.dispatchEvent(new PointerEvent(type, { bubbles: true, clientX, pointerId }));
|
||||
const tip = () => bar().querySelector('.world-timeline-mark-label');
|
||||
assert.equal(bar().querySelectorAll('.world-timeline-tick').length, 3, 'ticks stay ticks');
|
||||
assert.equal(tip(), null);
|
||||
|
||||
// Hovering within 6 px of a tick shows its label, in place of the track's hint.
|
||||
press('pointermove', 205);
|
||||
await nextTick();
|
||||
assert.equal(tip()?.textContent, 'GAUNTLET PAYLOAD');
|
||||
assert.equal(track.hasAttribute('title'), false);
|
||||
press('pointermove', 698);
|
||||
await nextTick();
|
||||
assert.equal(tip()?.textContent, 'M6.4 · Fiji');
|
||||
// Further off, or on a tick with no label, nothing shows.
|
||||
press('pointermove', 690);
|
||||
await nextTick();
|
||||
assert.equal(tip(), null);
|
||||
assert.equal(track.hasAttribute('title'), true);
|
||||
press('pointermove', 2);
|
||||
await nextTick();
|
||||
assert.equal(tip(), null, 'an unlabelled mark has no label');
|
||||
press('pointermove', 205);
|
||||
track.dispatchEvent(new PointerEvent('pointerleave', { clientX: 1_100, pointerId: 1 }));
|
||||
await nextTick();
|
||||
assert.equal(tip(), null, 'leaving the track hides it');
|
||||
|
||||
// A tap by a tick goes to its mark exactly; elsewhere, to the time there.
|
||||
press('pointerdown', 704);
|
||||
press('pointerup', 704);
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), quake);
|
||||
assert.match(input.getAttribute('aria-valuetext'), / · M6\.4 · Fiji$/);
|
||||
press('pointerdown', 500);
|
||||
press('pointerup', 500);
|
||||
await nextTick();
|
||||
const middle = start + (now - start) / 2;
|
||||
assert.ok(Math.abs(worldClock.now() - middle) < 60_000, 'went to the middle');
|
||||
assert.notEqual(worldClock.now(), quake);
|
||||
assert.match(input.getAttribute('aria-valuetext'), /UTC$/, 'off a mark, the time alone');
|
||||
// A drag from a tick still scrubs.
|
||||
press('pointerdown', 200);
|
||||
press('pointermove', 300);
|
||||
press('pointerup', 300);
|
||||
await nextTick();
|
||||
assert.ok(Math.abs(worldClock.now() - (start + (now - start) * 0.3)) < 60_000);
|
||||
|
||||
// The arrows go to the marks and tell their labels; focused, the label shows.
|
||||
input.dispatchEvent(new Event('focus'));
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), launch);
|
||||
assert.match(input.getAttribute('aria-valuetext'), / · GAUNTLET PAYLOAD$/);
|
||||
assert.equal(tip()?.textContent, 'GAUNTLET PAYLOAD');
|
||||
input.dispatchEvent(new Event('blur'));
|
||||
await nextTick();
|
||||
assert.equal(tip(), null);
|
||||
});
|
||||
@@ -8,11 +8,12 @@ import UiIcon from '../../kit/UiIcon.vue';
|
||||
import UiSelect from '../../kit/UiSelect.js';
|
||||
|
||||
// The world timeline: play and pause and the speed on the left, a track
|
||||
// across the stretch the layers on can show (each launch or frame a tick)
|
||||
// with a handle to scrub and the time in a bubble over it, and the way back
|
||||
// to live on the right, lit while live. Scrolling or pinching the track
|
||||
// zooms it around the handle, dragging it moves along it, and a double-click
|
||||
// shows it all again. It shows
|
||||
// across the stretch the layers on can show (each mark, a launch or a strong
|
||||
// earthquake, a tick, its label shown over it on hover) with a handle to
|
||||
// scrub and the time in a bubble over it, and the way back to live on the
|
||||
// right, lit while live. Scrolling or pinching the track zooms it around the
|
||||
// handle, dragging it moves along it, a tap on or by a tick goes to its
|
||||
// mark's time exactly, and a double-click shows it all again. 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.
|
||||
@@ -53,6 +54,8 @@ const ZOOM_STEP = 1.5;
|
||||
const WHEEL_ZOOM = 0.0025;
|
||||
// Two presses this close are a double-click.
|
||||
const DOUBLE_PRESS_MS = 500;
|
||||
// A tap or a hover this near a tick, in pixels, is on its mark.
|
||||
const MARK_HIT_PX = 6;
|
||||
|
||||
const readout = computed(() =>
|
||||
Number.isFinite(time.value.timeMs)
|
||||
@@ -212,6 +215,7 @@ let movedTime = false;
|
||||
const onPointerDown = (event) => {
|
||||
// Only the main button: a right-click is for the menu.
|
||||
if (event.button > 0) return;
|
||||
hovered.value = null;
|
||||
const onHandle = event.target instanceof HTMLInputElement;
|
||||
pointers.set(event.pointerId, { x: event.clientX, onHandle });
|
||||
if (pointers.size === 1) {
|
||||
@@ -241,6 +245,10 @@ const onPointerDown = (event) => {
|
||||
gesture = { kind: 'press', x: event.clientX, end: view.value.end };
|
||||
};
|
||||
const onPointerMove = (event) => {
|
||||
// A pointer hovering, none pressed, shows the label of the tick under it.
|
||||
hovered.value = pointers.size
|
||||
? null
|
||||
: (markNear(event.clientX, event.currentTarget)?.time ?? null);
|
||||
const pointer = pointers.get(event.pointerId);
|
||||
if (!pointer) return;
|
||||
pointer.x = event.clientX;
|
||||
@@ -266,8 +274,14 @@ const onPointerMove = (event) => {
|
||||
};
|
||||
const onPointerUp = (event) => {
|
||||
if (!pointers.delete(event.pointerId)) return;
|
||||
// A tap on or by a tick goes to its mark exactly; elsewhere, to the time
|
||||
// under it.
|
||||
if (gesture?.kind === 'press' && event.type === 'pointerup')
|
||||
store.scrub(timeAt(event.clientX, event.currentTarget), viewLength());
|
||||
store.scrub(
|
||||
markNear(event.clientX, event.currentTarget)?.time ??
|
||||
timeAt(event.clientX, event.currentTarget),
|
||||
viewLength(),
|
||||
);
|
||||
// A finger lifted from a pinch ends it; the other one moves nothing.
|
||||
gesture = null;
|
||||
};
|
||||
@@ -276,11 +290,66 @@ const place = (ms) => {
|
||||
const { start, end } = view.value;
|
||||
return end > start ? ((ms - start) / (end - start)) * 100 : 100;
|
||||
};
|
||||
// The labels of the marks at each time marked; a time may have none.
|
||||
const markLabels = computed(() => {
|
||||
const labels = new Map();
|
||||
for (const mark of span.value?.markDetails ?? []) {
|
||||
if (!labels.has(mark.time)) labels.set(mark.time, []);
|
||||
if (mark.label) labels.get(mark.time).push(mark.label);
|
||||
}
|
||||
return labels;
|
||||
});
|
||||
// A tick for each time marked in view: where it sits, as a share of the
|
||||
// track, and its marks' labels.
|
||||
const ticks = computed(() => {
|
||||
const { start, end } = view.value;
|
||||
return span.value.marks
|
||||
.filter((mark) => mark >= start && mark <= end)
|
||||
.map((mark) => `${place(mark)}%`);
|
||||
.map((mark) => ({
|
||||
time: mark,
|
||||
share: place(mark) / 100,
|
||||
labels: markLabels.value.get(mark) ?? [],
|
||||
}));
|
||||
});
|
||||
// The tick nearest `clientX` within MARK_HIT_PX of it, or null.
|
||||
function markNear(clientX, track) {
|
||||
if (!view.value) return null;
|
||||
const { left, width } = track.getBoundingClientRect();
|
||||
if (!(width > 0)) return null;
|
||||
let near = null;
|
||||
let nearest = MARK_HIT_PX;
|
||||
for (const tick of ticks.value) {
|
||||
const off = Math.abs(left + tick.share * width - clientX);
|
||||
if (off <= nearest) {
|
||||
near = tick;
|
||||
nearest = off;
|
||||
}
|
||||
}
|
||||
return near;
|
||||
}
|
||||
// The time of the tick the pointer hovers, and whether the handle has focus.
|
||||
const hovered = shallowRef(null);
|
||||
const focused = shallowRef(false);
|
||||
// The labels shown over the track: the hovered tick's, or with the handle
|
||||
// focused and paused on a mark (an arrow key or a tap took it there), that
|
||||
// mark's. Nothing for a mark with no label.
|
||||
const markTip = computed(() => {
|
||||
if (!view.value) return null;
|
||||
const onMark = !time.value.live && focused.value ? time.value.timeMs : null;
|
||||
const over = ticks.value.find((each) => each.time === hovered.value);
|
||||
const tick = over ?? ticks.value.find((each) => each.time === onMark);
|
||||
return tick?.labels.length
|
||||
? { share: tick.share, text: tick.labels.join('\n'), hover: Boolean(over) }
|
||||
: null;
|
||||
});
|
||||
// The time as the handle tells it, with the labels of the mark it is on.
|
||||
const valueText = computed(() => {
|
||||
const labels = time.value.live
|
||||
? null
|
||||
: markLabels.value.get(time.value.timeMs);
|
||||
return labels?.length
|
||||
? `${readout.value} · ${labels.join('; ')}`
|
||||
: readout.value;
|
||||
});
|
||||
const shown = computed(() =>
|
||||
Math.min(view.value.end, Math.max(view.value.start, at.value)),
|
||||
@@ -294,8 +363,9 @@ const scrub = (event) => {
|
||||
}
|
||||
store.scrub(Number(event.target.value), viewLength());
|
||||
};
|
||||
// Arrows go to the previous or next mark (a launch, a strong earthquake), or
|
||||
// a step along the track as shown where there is none; Page keys take a tenth
|
||||
// Arrows go to the previous or next mark (a launch, a strong earthquake),
|
||||
// whose label the handle then tells with the time, or a step along the track
|
||||
// as shown where there is none; Page keys take a tenth
|
||||
// of it; Home and End go to the ends of all of it. Plus and minus zoom, and
|
||||
// zero shows it all; with a modifier they are the browser's own zoom.
|
||||
const ZOOM_KEYS = ['+', '=', '-', '0'];
|
||||
@@ -331,17 +401,18 @@ const onKey = (event) => {
|
||||
><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
|
||||
><UiSelect class="gev-field gev-field--compact world-timeline-speed" :aria-label="t('Play speed')" :title="t('Play speed')" :options="speeds" :model-value="speed" @update:model-value="store.setSpeed($event)"
|
||||
/><div class="world-timeline-track" :class="{ 'is-zoomed': zoomed }" :title="t('Scroll or pinch to zoom, drag to move along · double-click to see it all')" @wheel="onWheel" @dblclick="showAll" @pointerdown="onPointerDown" @pointermove="onPointerMove" @pointerup="onPointerUp" @pointercancel="onPointerUp"
|
||||
/><div class="world-timeline-track" :class="{ 'is-zoomed': zoomed }" :title="markTip?.hover ? undefined : t('Scroll or pinch to zoom, drag to move along · double-click to see it all')" @wheel="onWheel" @dblclick="showAll" @pointerdown="onPointerDown" @pointermove="onPointerMove" @pointerup="onPointerUp" @pointercancel="onPointerUp" @pointerleave="hovered = null"
|
||||
><time class="world-timeline-time" :class="{ 'is-waiting': waiting }" :style="{ '--at': place(shown) / 100 }" :datetime="new Date(time.timeMs).toISOString()" aria-live="off"
|
||||
><span v-if="waiting" class="world-timeline-spinner" aria-hidden="true"></span>{{ bubble }}</time
|
||||
><span v-for="(left, index) in ticks" :key="index" class="world-timeline-tick" :style="{ left }" aria-hidden="true"></span
|
||||
><span v-if="markTip" class="world-timeline-mark-label" :style="{ '--at': markTip.share }" aria-hidden="true">{{ markTip.text }}</span
|
||||
><span v-for="tick in ticks" :key="tick.time" class="world-timeline-tick" :style="{ left: `${tick.share * 100}%` }" aria-hidden="true"></span
|
||||
><span class="world-timeline-fill" :style="{ width: `${place(shown)}%` }" aria-hidden="true"></span
|
||||
><input
|
||||
class="world-timeline-scrub"
|
||||
:class="{ 'is-off-view': handleOff }"
|
||||
type="range"
|
||||
:aria-label="t('World time')"
|
||||
:aria-valuetext="readout"
|
||||
:aria-valuetext="valueText"
|
||||
:min="view.start"
|
||||
:max="view.end"
|
||||
step="any"
|
||||
@@ -349,6 +420,8 @@ const onKey = (event) => {
|
||||
@input="scrub"
|
||||
aria-keyshortcuts="+ - 0"
|
||||
@keydown="onKey"
|
||||
@focus="focused = true"
|
||||
@blur="focused = false"
|
||||
/></div
|
||||
><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>
|
||||
|
||||
Reference in new issue
Block a user