mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Take the timeline commits back out before merging their reviewed versions from main
5150279cc,97bd61711,900c76425and4f23ad330went to main, reviewed and changed, as #1745. They are taken out here so main brings them in as merged, rather than as two copies of the same changes in conflict.
This commit is contained in:
1 parent
4f23ad330c
commit
961e6321a5
45 files changed
+1316
-1078
No files matched your search
@@ -8,12 +8,11 @@ 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 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
|
||||
// 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
|
||||
// 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.
|
||||
@@ -54,8 +53,6 @@ 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)
|
||||
@@ -215,7 +212,6 @@ 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) {
|
||||
@@ -245,10 +241,6 @@ 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;
|
||||
@@ -274,14 +266,8 @@ 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(
|
||||
markNear(event.clientX, event.currentTarget)?.time ??
|
||||
timeAt(event.clientX, event.currentTarget),
|
||||
viewLength(),
|
||||
);
|
||||
store.scrub(timeAt(event.clientX, event.currentTarget), viewLength());
|
||||
// A finger lifted from a pinch ends it; the other one moves nothing.
|
||||
gesture = null;
|
||||
};
|
||||
@@ -290,66 +276,11 @@ 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) => ({
|
||||
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;
|
||||
.map((mark) => `${place(mark)}%`);
|
||||
});
|
||||
const shown = computed(() =>
|
||||
Math.min(view.value.end, Math.max(view.value.start, at.value)),
|
||||
@@ -363,11 +294,10 @@ const scrub = (event) => {
|
||||
}
|
||||
store.scrub(Number(event.target.value), viewLength());
|
||||
};
|
||||
// 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.
|
||||
// Arrows go to the previous or next mark (a launch, a frame), or a step along
|
||||
// the track as shown; 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'];
|
||||
const onKey = (event) => {
|
||||
if (ZOOM_KEYS.includes(event.key)) {
|
||||
@@ -401,18 +331,17 @@ 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="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"
|
||||
/><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"
|
||||
><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-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 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(shown)}%` }" aria-hidden="true"></span
|
||||
><input
|
||||
class="world-timeline-scrub"
|
||||
:class="{ 'is-off-view': handleOff }"
|
||||
type="range"
|
||||
:aria-label="t('World time')"
|
||||
:aria-valuetext="valueText"
|
||||
:aria-valuetext="readout"
|
||||
:min="view.start"
|
||||
:max="view.end"
|
||||
step="any"
|
||||
@@ -420,8 +349,6 @@ 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