mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(cyclones): cards leave the map with their storms; null advisory values are left out
The world overlay drew on desynchronized 2D contexts. After a frame that only clears, Chrome could present an earlier buffer, so storm cards and forecast lead-hour labels stayed on screen when a snapshot without storms (or an unavailable one) replaced them, although the overlay held no entries and cleared every frame. Both overlay surfaces now use ordinary contexts. The storm readout no longer prints "Unavailable" for a null value: an advisory without pressure shows only its maximum sustained wind, one without wind only its pressure, and one without either has no intensity line. The advisory link stays hidden when an advisory has no link.
This commit is contained in:
1 parent
9b8f45e62b
commit
7b4b4d4184
17 files changed
+128
-16
No files matched your search
@@ -59,8 +59,22 @@ const classificationName = (code) =>
|
||||
Object.hasOwn(CLASSIFICATION_NAMES, code)
|
||||
? t(CLASSIFICATION_NAMES[code])
|
||||
: code;
|
||||
const number = (value, unit) =>
|
||||
value === null ? t('Unavailable') : formatQuantity(value, unit);
|
||||
// A value the advisory leaves out (null) is left out of the line too.
|
||||
const intensityText = (storm) => {
|
||||
const has = (value) => value !== null && value !== undefined;
|
||||
const wind = has(storm.windKt) ? formatQuantity(storm.windKt, 'kt') : null;
|
||||
const pressure = has(storm.pressureHpa)
|
||||
? formatQuantity(storm.pressureHpa, 'hPa')
|
||||
: null;
|
||||
if (wind && pressure)
|
||||
return t('Maximum sustained wind: {wind} · Pressure: {pressure}', {
|
||||
wind,
|
||||
pressure,
|
||||
});
|
||||
if (wind) return t('Maximum sustained wind: {wind}', { wind });
|
||||
if (pressure) return t('Pressure: {pressure}', { pressure });
|
||||
return '';
|
||||
};
|
||||
|
||||
/** Advisory status and coherent forecast geometry; selected through the shared row list. */
|
||||
export function createCyclonesLayer({
|
||||
@@ -424,12 +438,7 @@ export function createCyclonesLayer({
|
||||
const position = storm
|
||||
? t('Position as of {time}', { time: utc(storm.positionAt) })
|
||||
: '';
|
||||
const intensity = storm
|
||||
? t('Maximum sustained wind: {wind} · Pressure: {pressure}', {
|
||||
wind: number(storm.windKt, 'kt'),
|
||||
pressure: number(storm.pressureHpa, 'hPa'),
|
||||
})
|
||||
: '';
|
||||
const intensity = storm ? intensityText(storm) : '';
|
||||
const detail = storm
|
||||
? t('{name} · {classification} · Advisory {number} · issued {time}', {
|
||||
name: storm.name,
|
||||
@@ -479,7 +488,7 @@ export function createCyclonesLayer({
|
||||
text: intensity,
|
||||
},
|
||||
{ id: 'geometry', text: geometry, muted: true },
|
||||
]
|
||||
].filter((line) => line.text)
|
||||
: [],
|
||||
detail,
|
||||
status,
|
||||
@@ -511,7 +520,7 @@ export function createCyclonesLayer({
|
||||
]
|
||||
: [],
|
||||
info: storm
|
||||
? `${detail}\n${position}\n${intensity}\n${geometry}${status && status !== geometry ? '\n' + status : ''}\n${coverageText(snapshot.coverage)}`
|
||||
? `${detail}\n${position}\n${intensity ? intensity + '\n' : ''}${geometry}${status && status !== geometry ? '\n' + status : ''}\n${coverageText(snapshot.coverage)}`
|
||||
: `${detail}${status ? '\n' + status : ''}\n${coverageText(snapshot?.coverage)}`,
|
||||
infoTitle: t(
|
||||
'Select a storm on the map, or choose a storm in the list to select it and move the camera. Click empty map space to clear the selection. NOAA NHC/CPHC advisory context. The cone describes forecast center-track uncertainty, not storm size or the full hazard area. Forecast point labels are source lead hours, not times computed from advisory issuance. Geometry follows the surface; height is not weather altitude. Consult the official advisory.',
|
||||
|
||||
@@ -824,6 +824,59 @@ test('classification display expands known codes without altering the source or
|
||||
}
|
||||
}
|
||||
});
|
||||
// Quantities join number and unit with a no-break space.
|
||||
const plain = (text) => text?.replace(/\u00a0/g, ' ') ?? null;
|
||||
test('an advisory without pressure, movement or link leaves those values out', async () => {
|
||||
const record = {
|
||||
...storm(),
|
||||
windKt: 85,
|
||||
pressureHpa: null,
|
||||
movement: { directionDegrees: null, speedKt: null },
|
||||
advisoryUrl: null,
|
||||
};
|
||||
const h = harness({ getSnapshot: async () => snapshot([record]) });
|
||||
try {
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
const { summary, info } = h.layer.getRowControls();
|
||||
const intensity = summary.lines.find((line) => line.id === 'intensity');
|
||||
assert.equal(plain(intensity.text), 'Maximum sustained wind: 85 kt');
|
||||
assert.deepEqual(
|
||||
summary.lines.map((line) => line.id),
|
||||
['position', 'intensity', 'geometry'],
|
||||
);
|
||||
assert.deepEqual(summary.actions, [], 'no advisory link to open');
|
||||
assert.ok(plain(info).includes('Maximum sustained wind: 85 kt\n'));
|
||||
for (const text of [info, ...summary.lines.map((line) => line.text)])
|
||||
assert.doesNotMatch(text, /Unavailable|Pressure/);
|
||||
} finally {
|
||||
h.layer.destroy();
|
||||
}
|
||||
});
|
||||
test('an advisory with only one of wind and pressure shows that one alone', async () => {
|
||||
for (const [values, expected] of [
|
||||
[{ windKt: null, pressureHpa: 990 }, 'Pressure: 990 hPa'],
|
||||
[
|
||||
{ windKt: 60, pressureHpa: 990 },
|
||||
'Maximum sustained wind: 60 kt · Pressure: 990 hPa',
|
||||
],
|
||||
[{ windKt: null, pressureHpa: null }, null],
|
||||
]) {
|
||||
const h = harness({
|
||||
getSnapshot: async () => snapshot([{ ...storm(), ...values }]),
|
||||
});
|
||||
try {
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
const { summary, info } = h.layer.getRowControls();
|
||||
const intensity = summary.lines.find((line) => line.id === 'intensity');
|
||||
assert.equal(plain(intensity?.text), expected);
|
||||
assert.doesNotMatch(info, /Unavailable|\n\n/);
|
||||
} finally {
|
||||
h.layer.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
test('advisory selection uses accessible row descriptors and shared camera handoff', async () => {
|
||||
const h = harness(
|
||||
{ getSnapshot: async () => snapshot([storm(), storm('ep162026')]) },
|
||||
|
||||
Reference in new issue
Block a user