Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windy #274

Merged
merged 4 commits into from
Jul 19, 2024
Merged

Windy #274

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/windy-sounding/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release history

## 4.1.2 - Jul 19, 2024

- Prevent an infinite loop when height === 0
- Better handling of burst of wheel events
- Refresh windy data cache on re-render

## 4.1.1 - July 17, 2024

- Do not throw when remote config can not be loaded
Expand Down
4 changes: 2 additions & 2 deletions libs/windy-sounding/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/windy-sounding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "windy-plugin-fxc-soundings",
"version": "4.1.1",
"version": "4.1.2",
"type": "module",
"private": true,
"description": "Alternative sounding graphs with custom features for PG/HG pilots.",
Expand Down
16 changes: 14 additions & 2 deletions libs/windy-sounding/src/components/skewt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ function DryAdiabatic({
pressureToPxScale: Scale;
pathGenerator: (points: [x: number, y: number][]) => string;
}) {
if (height === 0) {
// prevent an infinite loop when height === 0.
return;
}
const points: [x: number, y: number][] = [];
const stepPx = height / 15;
const stepPx = height / 20;
for (let y = height; y > -stepPx; y -= stepPx) {
const p = pressureToPxScale.invert(y);
const t = atm.dryLapse(p, temp, pressure);
Expand All @@ -226,9 +230,13 @@ function WetAdiabatic({
pressureToPxScale: Scale;
pathGenerator: (points: [x: number, y: number][]) => string;
}) {
if (height === 0) {
// prevent an infinite loop when height === 0.
return;
}
const points: [x: number, y: number][] = [];
let previousPressure = pressure;
const stepPx = height / 15;
const stepPx = height / 20;
for (let y = height; y > -stepPx; y -= stepPx) {
const p = pressureToPxScale.invert(y);
temp += (p - previousPressure) * atm.wetTempGradient(p, temp);
Expand All @@ -252,6 +260,10 @@ function IsoHume({
pressureToPxScale: Scale;
pathGenerator: (points: [x: number, y: number][]) => string;
}) {
if (height === 0) {
// prevent an infinite loop when height === 0.
return;
}
const points: [x: number, y: number][] = [];
const mixingRatio = atm.mixingRatio(atm.saturationVaporPressure(temp), pressure);
const stepPx = height;
Expand Down
13 changes: 12 additions & 1 deletion libs/windy-sounding/src/containers/containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function Plugin() {
fetchStatus,
availableVersion,
isWindyDataAvailableAtCurrentTime,
modelName,
location,
} = useSelector((state: RootState) => {
const modelName = pluginSlice.selModelName(state);
const location = pluginSlice.selLocation(state);
Expand All @@ -55,6 +57,10 @@ export function Plugin() {
};
}, shallowEqual);

if (startHeight === 0) {
return;
}

// Resizable height on mobile.
const [mobileHeight, setMobileHeight] = useState<number | undefined>();
const height = mobileHeight ?? startHeight;
Expand All @@ -63,6 +69,8 @@ export function Plugin() {
let heightOnStartDrag = 0;

const dispatch: AppDispatch = useDispatch();
// Fetch data when the cache has expired.
dispatch(forecastSlice.fetchForecast({ modelName, location }));
const selectFavorite = useCallback((location: LatLon) => {
dispatch(changeLocation(location));
centerMap(location);
Expand Down Expand Up @@ -110,7 +118,10 @@ export function Plugin() {
size,
};
dispatch(updateTime(step));
ignoreWheelEventUntilMs = Date.now() + (size === 'day' ? 500 : 10);
ignoreWheelEventUntilMs = timeMs + (size === 'day' ? 600 : 50);
} else if (ignoreWheelEventUntilMs < timeMs + 50) {
// Ignore bursts of events (windows/mac).
ignoreWheelEventUntilMs += 10;
}
e.stopImmediatePropagation();
e.preventDefault();
Expand Down
12 changes: 8 additions & 4 deletions libs/windy-sounding/src/redux/forecast-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,19 @@ export const fetchForecast = createAsyncThunk<Forecast, ModelAndLocation, { stat
},
{
condition: (modelAndLocation, api: AppThunkAPI) => {
// Prevent fetching again while loading.
// Prevent fetching again while loading or when data is already cached.
const { modelName, location } = modelAndLocation;
const state = api.getState();
const pluginStatus = pluginSlice.selStatus(state);
const windyData = selMaybeLoadedWindyData(state, modelName, location);
return (
pluginStatus === pluginSlice.PluginStatus.Ready &&
(windyData === undefined ||
!(windyData.fetchStatus == FetchStatus.Loading || windyData.fetchStatus === FetchStatus.ErrorOutOfBounds))
!(
windyData.fetchStatus == FetchStatus.Loaded ||
windyData.fetchStatus == FetchStatus.Loading ||
windyData.fetchStatus === FetchStatus.ErrorOutOfBounds
))
);
},
},
Expand All @@ -207,7 +211,7 @@ function windyDataKey(modelName: string, location: LatLon): string {
* @param state - The state object containing forecast data.
* @param key - The key to identify the forecast data.
* */
function isDataCached(state: ForecastState, key: string) {
function isWindyDataCached(state: ForecastState, key: string) {
const forecast = state.data[key];
if (forecast == null) {
return false;
Expand Down Expand Up @@ -311,7 +315,7 @@ const selMaybeWindyData = (state: RootState, modelName: string, location: LatLon

const selMaybeLoadedWindyData = (state: RootState, modelName: string, location: LatLon): Forecast | undefined => {
const key = windyDataKey(modelName, location);
return isDataCached(state[slice.name], key) ? state[slice.name].data[key] : undefined;
return isWindyDataCached(state[slice.name], key) ? state[slice.name].data[key] : undefined;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions libs/windy-sounding/src/redux/plugin-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type PluginState = {
const initialState: PluginState = {
favorites: [],
isZoomedIn: true,
width: 0,
height: 0,
width: 100,
height: 100,
location: { lat: 0, lon: 0 },
modelName: 'ecmwf',
timeMs: windyStore.get('timestamp'),
Expand Down
Loading