mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +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
@@ -2,64 +2,6 @@ export const EARTHQUAKE_OVERLAY_SOURCE_ID = 'earthquakes';
|
||||
export const EARTHQUAKE_OVERLAY_COHORT_LIMIT = 96;
|
||||
export const EARTHQUAKE_OVERLAY_COLLISION_CAPACITY = 48;
|
||||
|
||||
/**
|
||||
* The smallest magnitude the timeline marks. Most quakes are small shakes;
|
||||
* M6 and up come about once every two days worldwide, so each is an event
|
||||
* worth stepping to. The map still draws every quake.
|
||||
*/
|
||||
export const EARTHQUAKE_MARK_MAGNITUDE = 6;
|
||||
|
||||
/** The longest place a timeline mark's label carries, ellipsis and all. */
|
||||
const MARK_PLACE_LENGTH = 40;
|
||||
|
||||
/** A magnitude as the map's labels show it: `M6.4`. */
|
||||
export const earthquakeMagnitudeTitle = (magnitude) =>
|
||||
`M${Number(magnitude).toFixed(1)}`;
|
||||
|
||||
/**
|
||||
* A strong quake's timeline label: its magnitude and, where the feed names
|
||||
* one, its place, cut short (`M6.4 · 113 km SSE of Lata, Solomon Islands`).
|
||||
* @param {{mag: number, place?: string | null}} event
|
||||
* @returns {string}
|
||||
*/
|
||||
export function earthquakeMarkLabel({ mag, place }) {
|
||||
const title = earthquakeMagnitudeTitle(mag);
|
||||
const where =
|
||||
typeof place === 'string' ? place.replace(/\s+/g, ' ').trim() : '';
|
||||
if (!where) return title;
|
||||
const short =
|
||||
where.length > MARK_PLACE_LENGTH
|
||||
? `${where.slice(0, MARK_PLACE_LENGTH - 1).trimEnd()}…`
|
||||
: where;
|
||||
return `${title} · ${short}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time a world clock's timeline can show for `events` (`{mag, time,
|
||||
* place?, usgsId?}`, time in ms): the span of the quakes of
|
||||
* EARTHQUAKE_MARK_MAGNITUDE and up, each one a mark labelled with its
|
||||
* magnitude and place, or null with none, so the layer never stretches the
|
||||
* timeline past what its feed covers.
|
||||
* @returns {{start: number, end: number, marks: Array<{time: number, label: string, id?: string, kind: string}>} | null}
|
||||
*/
|
||||
export function earthquakeCoverage(events) {
|
||||
const marks = events
|
||||
.filter(
|
||||
({ mag, time }) =>
|
||||
mag >= EARTHQUAKE_MARK_MAGNITUDE && Number.isFinite(time),
|
||||
)
|
||||
.map((event) => ({
|
||||
time: event.time,
|
||||
label: earthquakeMarkLabel(event),
|
||||
...(event.usgsId ? { id: String(event.usgsId) } : {}),
|
||||
kind: 'earthquake',
|
||||
}))
|
||||
.sort((a, b) => a.time - b.time);
|
||||
return marks.length
|
||||
? { start: marks[0].time, end: marks.at(-1).time, marks }
|
||||
: null;
|
||||
}
|
||||
|
||||
// The depth bands' colours: CSS red, orange and yellow, as the renderer's
|
||||
// colour tuples (`[r, g, b, a]`, 0..1) and as CSS for the labels' accent.
|
||||
const SHALLOW = Object.freeze({ rgba: [1, 0, 0, 1], css: 'rgb(255,0,0)' });
|
||||
@@ -108,7 +50,7 @@ export function createEarthquakeOverlayEntry({
|
||||
id: String(id),
|
||||
position,
|
||||
variant: 'label',
|
||||
title: earthquakeMagnitudeTitle(mag),
|
||||
title: `M${mag.toFixed(1)}`,
|
||||
accent,
|
||||
priority: Math.round(mag * 1000),
|
||||
collisionGroup: 'ambient-label',
|
||||
|
||||
Reference in new issue
Block a user