From 628270ac2e26d20036994c5c69d81eba8f612ae9 Mon Sep 17 00:00:00 2001 From: mrkmntal Date: Tue, 7 Apr 2026 17:15:43 -0400 Subject: [PATCH] make Travel Forecast more global with regional city buckets and scroll fixes --- datagenerators/output/travelcities.json | 564 +++++++++++++--------- datagenerators/travelcities-raw.json | 204 ++++---- datagenerators/travelcities.mjs | 50 +- server/scripts/modules/travelforecast.mjs | 118 ++++- 4 files changed, 542 insertions(+), 394 deletions(-) diff --git a/datagenerators/output/travelcities.json b/datagenerators/output/travelcities.json index 6eaac71..16b8a2d 100644 --- a/datagenerators/output/travelcities.json +++ b/datagenerators/output/travelcities.json @@ -1,242 +1,338 @@ -[ - { - "Name": "Atlanta", - "Latitude": 33.749, - "Longitude": -84.388, - "point": { - "x": 51, - "y": 87, - "wfo": "FFC" +{ + "north-america": [ + { + "Name": "Atlanta", + "Latitude": 33.749, + "Longitude": -84.388 + }, + { + "Name": "Chicago", + "Latitude": 41.8781, + "Longitude": -87.6298 + }, + { + "Name": "Dallas", + "Latitude": 32.7767, + "Longitude": -96.797 + }, + { + "Name": "Los Angeles", + "Latitude": 34.0522, + "Longitude": -118.2437 + }, + { + "Name": "Mexico City", + "Latitude": 19.4326, + "Longitude": -99.1332 + }, + { + "Name": "Miami", + "Latitude": 25.7617, + "Longitude": -80.1918 + }, + { + "Name": "Montreal", + "Latitude": 45.5019, + "Longitude": -73.5674 + }, + { + "Name": "New York", + "Latitude": 40.7128, + "Longitude": -74.006 + }, + { + "Name": "Seattle", + "Latitude": 47.6062, + "Longitude": -122.3321 + }, + { + "Name": "Toronto", + "Latitude": 43.6532, + "Longitude": -79.3832 + }, + { + "Name": "Vancouver", + "Latitude": 49.2827, + "Longitude": -123.1207 + }, + { + "Name": "Washington DC", + "Latitude": 38.8951, + "Longitude": -77.0364 } - }, - { - "Name": "Boston", - "Latitude": 42.3584, - "Longitude": -71.0598, - "point": { - "x": 71, - "y": 90, - "wfo": "BOX" + ], + "south-america": [ + { + "Name": "Bogota", + "Latitude": 4.711, + "Longitude": -74.0721 + }, + { + "Name": "Buenos Aires", + "Latitude": -34.6037, + "Longitude": -58.3816 + }, + { + "Name": "Lima", + "Latitude": -12.0464, + "Longitude": -77.0428 + }, + { + "Name": "Quito", + "Latitude": -0.1807, + "Longitude": -78.4678 + }, + { + "Name": "Rio de Janeiro", + "Latitude": -22.9068, + "Longitude": -43.1729 + }, + { + "Name": "Santiago", + "Latitude": -33.4489, + "Longitude": -70.6693 + }, + { + "Name": "Sao Paulo", + "Latitude": -23.5558, + "Longitude": -46.6396 } - }, - { - "Name": "Chicago", - "Latitude": 41.9796, - "Longitude": -87.9045, - "point": { - "x": 66, - "y": 77, - "wfo": "LOT" + ], + "europe": [ + { + "Name": "Amsterdam", + "Latitude": 52.3676, + "Longitude": 4.9041 + }, + { + "Name": "Berlin", + "Latitude": 52.52, + "Longitude": 13.405 + }, + { + "Name": "London", + "Latitude": 51.5072, + "Longitude": -0.1276 + }, + { + "Name": "Madrid", + "Latitude": 40.4168, + "Longitude": -3.7038 + }, + { + "Name": "Paris", + "Latitude": 48.8566, + "Longitude": 2.3522 + }, + { + "Name": "Rome", + "Latitude": 41.9028, + "Longitude": 12.4964 + }, + { + "Name": "Stockholm", + "Latitude": 59.3293, + "Longitude": 18.0686 + }, + { + "Name": "Vienna", + "Latitude": 48.2082, + "Longitude": 16.3738 } - }, - { - "Name": "Cleveland", - "Latitude": 41.4995, - "Longitude": -81.6954, - "point": { - "x": 83, - "y": 65, - "wfo": "CLE" + ], + "africa": [ + { + "Name": "Cairo", + "Latitude": 30.0444, + "Longitude": 31.2357 + }, + { + "Name": "Cape Town", + "Latitude": -33.9249, + "Longitude": 18.4241 + }, + { + "Name": "Casablanca", + "Latitude": 33.5731, + "Longitude": -7.5898 + }, + { + "Name": "Johannesburg", + "Latitude": -26.2041, + "Longitude": 28.0473 + }, + { + "Name": "Lagos", + "Latitude": 6.5244, + "Longitude": 3.3792 + }, + { + "Name": "Nairobi", + "Latitude": -1.2864, + "Longitude": 36.8172 } - }, - { - "Name": "Dallas", - "Latitude": 32.8959, - "Longitude": -97.0372, - "point": { - "x": 80, - "y": 109, - "wfo": "FWD" + ], + "middle-east": [ + { + "Name": "Amman", + "Latitude": 31.9539, + "Longitude": 35.9106 + }, + { + "Name": "Dubai", + "Latitude": 25.2048, + "Longitude": 55.2708 + }, + { + "Name": "Doha", + "Latitude": 25.2854, + "Longitude": 51.531 + }, + { + "Name": "Jerusalem", + "Latitude": 31.7683, + "Longitude": 35.2137 + }, + { + "Name": "Kuwait City", + "Latitude": 29.3759, + "Longitude": 47.9774 + }, + { + "Name": "Riyadh", + "Latitude": 24.7136, + "Longitude": 46.6753 } - }, - { - "Name": "Denver", - "Latitude": 39.7391, - "Longitude": -104.9847, - "point": { - "x": 63, - "y": 61, - "wfo": "BOU" + ], + "east-asia": [ + { + "Name": "Beijing", + "Latitude": 39.9042, + "Longitude": 116.4074 + }, + { + "Name": "Hong Kong", + "Latitude": 22.3193, + "Longitude": 114.1694 + }, + { + "Name": "Osaka", + "Latitude": 34.6937, + "Longitude": 135.5023 + }, + { + "Name": "Seoul", + "Latitude": 37.5665, + "Longitude": 126.978 + }, + { + "Name": "Shanghai", + "Latitude": 31.2304, + "Longitude": 121.4737 + }, + { + "Name": "Taipei", + "Latitude": 25.033, + "Longitude": 121.5654 + }, + { + "Name": "Tokyo", + "Latitude": 35.6762, + "Longitude": 139.6503 } - }, - { - "Name": "Detroit", - "Latitude": 42.3314, - "Longitude": -83.0457, - "point": { - "x": 66, - "y": 34, - "wfo": "DTX" + ], + "oceania": [ + { + "Name": "Auckland", + "Latitude": -36.8509, + "Longitude": 174.7645 + }, + { + "Name": "Brisbane", + "Latitude": -27.4698, + "Longitude": 153.0251 + }, + { + "Name": "Melbourne", + "Latitude": -37.8136, + "Longitude": 144.9631 + }, + { + "Name": "Perth", + "Latitude": -31.9523, + "Longitude": 115.8613 + }, + { + "Name": "Sydney", + "Latitude": -33.8688, + "Longitude": 151.2093 + }, + { + "Name": "Wellington", + "Latitude": -41.2866, + "Longitude": 174.7756 } - }, - { - "Name": "Hartford", - "Latitude": 41.7637, - "Longitude": -72.6851, - "point": { - "x": 21, - "y": 54, - "wfo": "BOX" + ], + "global": [ + { + "Name": "Dubai", + "Latitude": 25.2048, + "Longitude": 55.2708 + }, + { + "Name": "Johannesburg", + "Latitude": -26.2041, + "Longitude": 28.0473 + }, + { + "Name": "London", + "Latitude": 51.5072, + "Longitude": -0.1276 + }, + { + "Name": "Los Angeles", + "Latitude": 34.0522, + "Longitude": -118.2437 + }, + { + "Name": "Mexico City", + "Latitude": 19.4326, + "Longitude": -99.1332 + }, + { + "Name": "New York", + "Latitude": 40.7128, + "Longitude": -74.006 + }, + { + "Name": "Paris", + "Latitude": 48.8566, + "Longitude": 2.3522 + }, + { + "Name": "Sao Paulo", + "Latitude": -23.5558, + "Longitude": -46.6396 + }, + { + "Name": "Singapore", + "Latitude": 1.3521, + "Longitude": 103.8198 + }, + { + "Name": "Sydney", + "Latitude": -33.8688, + "Longitude": 151.2093 + }, + { + "Name": "Tokyo", + "Latitude": 35.6762, + "Longitude": 139.6503 + }, + { + "Name": "Toronto", + "Latitude": 43.6532, + "Longitude": -79.3832 } - }, - { - "Name": "Houston", - "Latitude": 29.7633, - "Longitude": -95.3633, - "point": { - "x": 63, - "y": 95, - "wfo": "HGX" - } - }, - { - "Name": "Indianapolis", - "Latitude": 39.7684, - "Longitude": -86.158, - "point": { - "x": 58, - "y": 69, - "wfo": "IND" - } - }, - { - "Name": "Los Angeles", - "Latitude": 34.0522, - "Longitude": -118.2437, - "point": { - "x": 155, - "y": 45, - "wfo": "LOX" - } - }, - { - "Name": "Miami", - "Latitude": 25.7743, - "Longitude": -80.1937, - "point": { - "x": 110, - "y": 51, - "wfo": "MFL" - } - }, - { - "Name": "Minneapolis", - "Latitude": 44.98, - "Longitude": -93.2638, - "point": { - "x": 108, - "y": 72, - "wfo": "MPX" - } - }, - { - "Name": "New York", - "Latitude": 40.7142, - "Longitude": -74.0059, - "point": { - "x": 33, - "y": 35, - "wfo": "OKX" - } - }, - { - "Name": "Norfolk", - "Latitude": 36.8468, - "Longitude": -76.2852, - "point": { - "x": 90, - "y": 52, - "wfo": "AKQ" - } - }, - { - "Name": "Orlando", - "Latitude": 28.5383, - "Longitude": -81.3792, - "point": { - "x": 26, - "y": 68, - "wfo": "MLB" - } - }, - { - "Name": "Philadelphia", - "Latitude": 39.9523, - "Longitude": -75.1638, - "point": { - "x": 50, - "y": 76, - "wfo": "PHI" - } - }, - { - "Name": "Pittsburgh", - "Latitude": 40.4406, - "Longitude": -79.9959, - "point": { - "x": 78, - "y": 66, - "wfo": "PBZ" - } - }, - { - "Name": "St. Louis", - "Latitude": 38.6273, - "Longitude": -90.1979, - "point": { - "x": 95, - "y": 74, - "wfo": "LSX" - } - }, - { - "Name": "San Francisco", - "Latitude": 37.7749, - "Longitude": -122.4194, - "point": { - "x": 85, - "y": 105, - "wfo": "MTR" - } - }, - { - "Name": "Seattle", - "Latitude": 47.6062, - "Longitude": -122.3321, - "point": { - "x": 125, - "y": 68, - "wfo": "SEW" - } - }, - { - "Name": "Syracuse", - "Latitude": 43.0481, - "Longitude": -76.1474, - "point": { - "x": 52, - "y": 99, - "wfo": "BGM" - } - }, - { - "Name": "Tampa", - "Latitude": 27.9475, - "Longitude": -82.4584, - "point": { - "x": 71, - "y": 97, - "wfo": "TBW" - } - }, - { - "Name": "Washington DC", - "Latitude": 38.8951, - "Longitude": -77.0364, - "point": { - "x": 97, - "y": 71, - "wfo": "LWX" - } - } -] \ No newline at end of file + ] +} \ No newline at end of file diff --git a/datagenerators/travelcities-raw.json b/datagenerators/travelcities-raw.json index 30bdcc0..363f69a 100644 --- a/datagenerators/travelcities-raw.json +++ b/datagenerators/travelcities-raw.json @@ -1,122 +1,82 @@ -[ - { - "Name": "Atlanta", - "Latitude": 33.749, - "Longitude": -84.388 - }, - { - "Name": "Boston", - "Latitude": 42.3584, - "Longitude": -71.0598 - }, - { - "Name": "Chicago", - "Latitude": 41.9796, - "Longitude": -87.9045 - }, - { - "Name": "Cleveland", - "Latitude": 41.4995, - "Longitude": -81.6954 - }, - { - "Name": "Dallas", - "Latitude": 32.8959, - "Longitude": -97.0372 - }, - { - "Name": "Denver", - "Latitude": 39.7391, - "Longitude": -104.9847 - }, - { - "Name": "Detroit", - "Latitude": 42.3314, - "Longitude": -83.0457 - }, - { - "Name": "Hartford", - "Latitude": 41.7637, - "Longitude": -72.6851 - }, - { - "Name": "Houston", - "Latitude": 29.7633, - "Longitude": -95.3633 - }, - { - "Name": "Indianapolis", - "Latitude": 39.7684, - "Longitude": -86.158 - }, - { - "Name": "Los Angeles", - "Latitude": 34.0522, - "Longitude": -118.2437 - }, - { - "Name": "Miami", - "Latitude": 25.7743, - "Longitude": -80.1937 - }, - { - "Name": "Minneapolis", - "Latitude": 44.98, - "Longitude": -93.2638 - }, - { - "Name": "New York", - "Latitude": 40.7142, - "Longitude": -74.0059 - }, - { - "Name": "Norfolk", - "Latitude": 36.8468, - "Longitude": -76.2852 - }, - { - "Name": "Orlando", - "Latitude": 28.5383, - "Longitude": -81.3792 - }, - { - "Name": "Philadelphia", - "Latitude": 39.9523, - "Longitude": -75.1638 - }, - { - "Name": "Pittsburgh", - "Latitude": 40.4406, - "Longitude": -79.9959 - }, - { - "Name": "St. Louis", - "Latitude": 38.6273, - "Longitude": -90.1979 - }, - { - "Name": "San Francisco", - "Latitude": 37.7749, - "Longitude": -122.4194 - }, - { - "Name": "Seattle", - "Latitude": 47.6062, - "Longitude": -122.3321 - }, - { - "Name": "Syracuse", - "Latitude": 43.0481, - "Longitude": -76.1474 - }, - { - "Name": "Tampa", - "Latitude": 27.9475, - "Longitude": -82.4584 - }, - { - "Name": "Washington DC", - "Latitude": 38.8951, - "Longitude": -77.0364 - } -] \ No newline at end of file +{ + "north-america": [ + { "Name": "Atlanta", "Latitude": 33.749, "Longitude": -84.388 }, + { "Name": "Chicago", "Latitude": 41.8781, "Longitude": -87.6298 }, + { "Name": "Dallas", "Latitude": 32.7767, "Longitude": -96.797 }, + { "Name": "Los Angeles", "Latitude": 34.0522, "Longitude": -118.2437 }, + { "Name": "Mexico City", "Latitude": 19.4326, "Longitude": -99.1332 }, + { "Name": "Miami", "Latitude": 25.7617, "Longitude": -80.1918 }, + { "Name": "Montreal", "Latitude": 45.5019, "Longitude": -73.5674 }, + { "Name": "New York", "Latitude": 40.7128, "Longitude": -74.006 }, + { "Name": "Seattle", "Latitude": 47.6062, "Longitude": -122.3321 }, + { "Name": "Toronto", "Latitude": 43.6532, "Longitude": -79.3832 }, + { "Name": "Vancouver", "Latitude": 49.2827, "Longitude": -123.1207 }, + { "Name": "Washington DC", "Latitude": 38.8951, "Longitude": -77.0364 } + ], + "south-america": [ + { "Name": "Bogota", "Latitude": 4.711, "Longitude": -74.0721 }, + { "Name": "Buenos Aires", "Latitude": -34.6037, "Longitude": -58.3816 }, + { "Name": "Lima", "Latitude": -12.0464, "Longitude": -77.0428 }, + { "Name": "Quito", "Latitude": -0.1807, "Longitude": -78.4678 }, + { "Name": "Rio de Janeiro", "Latitude": -22.9068, "Longitude": -43.1729 }, + { "Name": "Santiago", "Latitude": -33.4489, "Longitude": -70.6693 }, + { "Name": "Sao Paulo", "Latitude": -23.5558, "Longitude": -46.6396 } + ], + "europe": [ + { "Name": "Amsterdam", "Latitude": 52.3676, "Longitude": 4.9041 }, + { "Name": "Berlin", "Latitude": 52.52, "Longitude": 13.405 }, + { "Name": "London", "Latitude": 51.5072, "Longitude": -0.1276 }, + { "Name": "Madrid", "Latitude": 40.4168, "Longitude": -3.7038 }, + { "Name": "Paris", "Latitude": 48.8566, "Longitude": 2.3522 }, + { "Name": "Rome", "Latitude": 41.9028, "Longitude": 12.4964 }, + { "Name": "Stockholm", "Latitude": 59.3293, "Longitude": 18.0686 }, + { "Name": "Vienna", "Latitude": 48.2082, "Longitude": 16.3738 } + ], + "africa": [ + { "Name": "Cairo", "Latitude": 30.0444, "Longitude": 31.2357 }, + { "Name": "Cape Town", "Latitude": -33.9249, "Longitude": 18.4241 }, + { "Name": "Casablanca", "Latitude": 33.5731, "Longitude": -7.5898 }, + { "Name": "Johannesburg", "Latitude": -26.2041, "Longitude": 28.0473 }, + { "Name": "Lagos", "Latitude": 6.5244, "Longitude": 3.3792 }, + { "Name": "Nairobi", "Latitude": -1.2864, "Longitude": 36.8172 } + ], + "middle-east": [ + { "Name": "Amman", "Latitude": 31.9539, "Longitude": 35.9106 }, + { "Name": "Dubai", "Latitude": 25.2048, "Longitude": 55.2708 }, + { "Name": "Doha", "Latitude": 25.2854, "Longitude": 51.531 }, + { "Name": "Jerusalem", "Latitude": 31.7683, "Longitude": 35.2137 }, + { "Name": "Kuwait City", "Latitude": 29.3759, "Longitude": 47.9774 }, + { "Name": "Riyadh", "Latitude": 24.7136, "Longitude": 46.6753 } + ], + "east-asia": [ + { "Name": "Beijing", "Latitude": 39.9042, "Longitude": 116.4074 }, + { "Name": "Hong Kong", "Latitude": 22.3193, "Longitude": 114.1694 }, + { "Name": "Osaka", "Latitude": 34.6937, "Longitude": 135.5023 }, + { "Name": "Seoul", "Latitude": 37.5665, "Longitude": 126.978 }, + { "Name": "Shanghai", "Latitude": 31.2304, "Longitude": 121.4737 }, + { "Name": "Taipei", "Latitude": 25.033, "Longitude": 121.5654 }, + { "Name": "Tokyo", "Latitude": 35.6762, "Longitude": 139.6503 } + ], + "oceania": [ + { "Name": "Auckland", "Latitude": -36.8509, "Longitude": 174.7645 }, + { "Name": "Brisbane", "Latitude": -27.4698, "Longitude": 153.0251 }, + { "Name": "Melbourne", "Latitude": -37.8136, "Longitude": 144.9631 }, + { "Name": "Perth", "Latitude": -31.9523, "Longitude": 115.8613 }, + { "Name": "Sydney", "Latitude": -33.8688, "Longitude": 151.2093 }, + { "Name": "Wellington", "Latitude": -41.2866, "Longitude": 174.7756 } + ], + "global": [ + { "Name": "Dubai", "Latitude": 25.2048, "Longitude": 55.2708 }, + { "Name": "Johannesburg", "Latitude": -26.2041, "Longitude": 28.0473 }, + { "Name": "London", "Latitude": 51.5072, "Longitude": -0.1276 }, + { "Name": "Los Angeles", "Latitude": 34.0522, "Longitude": -118.2437 }, + { "Name": "Mexico City", "Latitude": 19.4326, "Longitude": -99.1332 }, + { "Name": "New York", "Latitude": 40.7128, "Longitude": -74.006 }, + { "Name": "Paris", "Latitude": 48.8566, "Longitude": 2.3522 }, + { "Name": "Sao Paulo", "Latitude": -23.5558, "Longitude": -46.6396 }, + { "Name": "Singapore", "Latitude": 1.3521, "Longitude": 103.8198 }, + { "Name": "Sydney", "Latitude": -33.8688, "Longitude": 151.2093 }, + { "Name": "Tokyo", "Latitude": 35.6762, "Longitude": 139.6503 }, + { "Name": "Toronto", "Latitude": 43.6532, "Longitude": -79.3832 } + ] +} diff --git a/datagenerators/travelcities.mjs b/datagenerators/travelcities.mjs index eb1d0e2..466f24c 100644 --- a/datagenerators/travelcities.mjs +++ b/datagenerators/travelcities.mjs @@ -1,39 +1,25 @@ -// look up points for each travel city import { readFile, writeFile } from 'fs/promises'; -import chunk from './chunk.mjs'; -import https from './https.mjs'; -// source data -const travelCities = JSON.parse(await readFile('./datagenerators/travelcities-raw.json')); +const travelCitiesByRegion = JSON.parse(await readFile('./datagenerators/travelcities-raw.json')); -const result = []; -const dataChunks = chunk(travelCities, 5); +const validateCity = (city, region) => { + if (!city?.Name || typeof city.Latitude !== 'number' || typeof city.Longitude !== 'number') { + throw new Error(`Invalid travel city in region ${region}: ${JSON.stringify(city)}`); + } -// for loop intentional for use of await -// this keeps the api from getting overwhelmed -for (let i = 0; i < dataChunks.length; i += 1) { - const cityChunk = dataChunks[i]; + return { + Name: city.Name, + Latitude: city.Latitude, + Longitude: city.Longitude, + }; +}; - // eslint-disable-next-line no-await-in-loop - const chunkResult = await Promise.all(cityChunk.map(async (city) => { - try { - const data = await https(`https://api.weather.gov/points/${city.Latitude},${city.Longitude}`); - const point = JSON.parse(data); - return { - ...city, - point: { - x: point.properties.gridX, - y: point.properties.gridY, - wfo: point.properties.gridId, - }, - }; - } catch (e) { - console.error(e); - return city; - } - })); +const result = Object.fromEntries(Object.entries(travelCitiesByRegion).map(([region, cities]) => { + if (!Array.isArray(cities)) { + throw new Error(`Travel city region ${region} must be an array`); + } - result.push(...chunkResult); -} + return [region, cities.map((city) => validateCity(city, region))]; +})); -await writeFile('./datagenerators/output/travelcities.json', JSON.stringify(result, null, ' ')); +await writeFile('./datagenerators/output/travelcities.json', JSON.stringify(result, null, '\t')); diff --git a/server/scripts/modules/travelforecast.mjs b/server/scripts/modules/travelforecast.mjs index dc197e5..1a77b9b 100644 --- a/server/scripts/modules/travelforecast.mjs +++ b/server/scripts/modules/travelforecast.mjs @@ -32,6 +32,15 @@ class TravelForecast extends WeatherDisplay { }; } + resetScrollCache() { + this.scrollCache = { + displayHeight: 0, + contentHeight: 0, + maxOffset: 0, + travelLines: null, + }; + } + async getData(weatherParameters, refresh) { // super checks for enabled if (!super.getData(weatherParameters, refresh)) return; @@ -42,8 +51,9 @@ class TravelForecast extends WeatherDisplay { } const temperatureConverter = temperature(); + const selectedTravelCities = getTravelCitiesForLocation(this.weatherParameters); - const forecastPromises = TravelCities.map(async (city, index) => { + const forecastPromises = selectedTravelCities.map(async (city, index) => { try { let forecast; forecast = await getAggregatedOpenMeteoForecast(city.Latitude, city.Longitude); @@ -107,6 +117,7 @@ class TravelForecast extends WeatherDisplay { // get the element and populate const list = this.elem.querySelector('.travel-lines'); list.innerHTML = ''; + this.resetScrollCache(); // set up variables const cities = this.data; @@ -172,11 +183,12 @@ class TravelForecast extends WeatherDisplay { // get the travel lines element and cache measurements if needed const travelLines = this.elem.querySelector('.travel-lines'); if (!travelLines) return; + const displayHeight = getTravelDisplayHeight(this.elem); // update cache if needed (when content changes or first run) - if (this.scrollCache.travelLines !== travelLines || this.scrollCache.displayHeight === 0) { - this.scrollCache.displayHeight = this.elem.querySelector('.main').offsetHeight; - this.scrollCache.contentHeight = travelLines.offsetHeight; + if (this.scrollCache.travelLines !== travelLines || this.scrollCache.displayHeight !== displayHeight) { + this.scrollCache.displayHeight = displayHeight; + this.scrollCache.contentHeight = travelLines.scrollHeight; this.scrollCache.maxOffset = Math.max(0, this.scrollCache.contentHeight - this.scrollCache.displayHeight); this.scrollCache.travelLines = travelLines; @@ -201,8 +213,9 @@ class TravelForecast extends WeatherDisplay { } setTiming(list) { - const container = this.elem.querySelector('.main'); - const timingConfig = calculateScrollTiming(list, container, { + const timingConfig = calculateScrollTiming(list, { + offsetHeight: getTravelDisplayHeight(this.elem), + }, { staticDisplay: 5.0, // special static display time for travel forecast }); @@ -215,6 +228,99 @@ class TravelForecast extends WeatherDisplay { } } +const REGION_BY_COUNTRY_CODE = { + US: 'north-america', + CA: 'north-america', + MX: 'north-america', + BR: 'south-america', + AR: 'south-america', + CL: 'south-america', + PE: 'south-america', + CO: 'south-america', + EC: 'south-america', + UY: 'south-america', + PY: 'south-america', + BO: 'south-america', + VE: 'south-america', + GB: 'europe', + IE: 'europe', + FR: 'europe', + DE: 'europe', + ES: 'europe', + PT: 'europe', + IT: 'europe', + NL: 'europe', + BE: 'europe', + LU: 'europe', + CH: 'europe', + AT: 'europe', + DK: 'europe', + NO: 'europe', + SE: 'europe', + FI: 'europe', + PL: 'europe', + CZ: 'europe', + SK: 'europe', + HU: 'europe', + RO: 'europe', + BG: 'europe', + GR: 'europe', + HR: 'europe', + SI: 'europe', + RS: 'europe', + BA: 'europe', + ME: 'europe', + AL: 'europe', + MK: 'europe', + EE: 'europe', + LV: 'europe', + LT: 'europe', + IS: 'europe', + UA: 'europe', + MD: 'europe', + JP: 'east-asia', + KR: 'east-asia', + CN: 'east-asia', + TW: 'east-asia', + HK: 'east-asia', + MO: 'east-asia', + AU: 'oceania', + NZ: 'oceania', + EG: 'africa', + NG: 'africa', + KE: 'africa', + ZA: 'africa', + MA: 'africa', + TZ: 'africa', + GH: 'africa', + DZ: 'africa', + AE: 'middle-east', + SA: 'middle-east', + IL: 'middle-east', + JO: 'middle-east', + QA: 'middle-east', + KW: 'middle-east', + OM: 'middle-east', + BH: 'middle-east', + LB: 'middle-east', + IQ: 'middle-east', +}; + +const getTravelCitiesForLocation = (weatherParameters) => { + if (Array.isArray(TravelCities)) return TravelCities; + + const countryCode = (weatherParameters?.countryCode ?? '').toUpperCase(); + const selectedRegion = REGION_BY_COUNTRY_CODE[countryCode]; + return TravelCities[selectedRegion] ?? TravelCities.global ?? TravelCities['north-america'] ?? []; +}; + +const getTravelDisplayHeight = (elem) => { + const main = elem.querySelector('.main'); + const header = elem.querySelector('.column-headers'); + if (!main) return 0; + return Math.max(0, main.offsetHeight - (header?.offsetHeight ?? 0)); +}; + // effectively returns early on the first found date const getTravelCitiesDayName = (cities) => cities.reduce((dayName, city) => { if (city && dayName === '') {