Skip to content

Commit

Permalink
fix: snow fall showing wrong unit and using cm when should be using mm
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Nov 20, 2024
1 parent f925026 commit ea348de
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/components/HourlyItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
textPaint.setAlpha(150);
if (item.precipAccumulation >= 0.1) {
canvas.drawText(formatWeatherValue(item, item.precipShowSnow ? WeatherProps.snowfall : WeatherProps.precipAccumulation), w2, h - deltaY * $fontScale, textPaint);
canvas.drawText(formatWeatherValue(item, WeatherProps.precipAccumulation), w2, h - deltaY * $fontScale, textPaint);
deltaY += 10;
}
if (precipProbability > 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/components/TopWeatherView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
textPaint.setColor(colorOutline);
canvas.drawLine(0, h, w, h - 1, textPaint);
const centeredItemsToDraw = weatherDataService.getAllIconsData({ item, filter: [WeatherProps.windBeaufort] });
const centeredItemsToDraw = weatherDataService.getAllIconsData({ item, type: 'currently' });
canvas.clipRect(0, 0, w - weatherIconSize * (2 - $fontScale), h);
switch ($weatherDataLayout) {
case 'line': {
Expand Down
30 changes: 19 additions & 11 deletions app/helpers/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function convertValueToUnit(value: any, unit: UNITS, defaultUnit: UNITS,
const round = options.round ?? true;
let digits = 1;
let shouldRound = round;

switch (defaultUnit) {
case UNITS.Celcius:
shouldRound = true;
Expand All @@ -61,17 +60,26 @@ export function convertValueToUnit(value: any, unit: UNITS, defaultUnit: UNITS,
digits = 100;
value *= 0.03937008;
} else if (unit === UNITS.CM) {
value /= 10;
if (value < 1) {
unit = UNITS.MM;
} else {
value /= 10;
}
}
break;
case UNITS.CM:
digits = 10;
if (unit === UNITS.CM && value < 1) {
unit = UNITS.MM;
value *= 10;
}
// if (unit === UNITS.Inch) {
// digits = 10;
// value *= 0.3937008;
// } else if (unit === UNITS.MM) {
// value *= 10;
// }
break;
// case UNITS.CM:
// if (unit === UNITS.Inch) {
// digits = 10;
// value *= 0.3937008;
// } else if (unit === UNITS.MM) {
// value *= 10;
// }
// break;
case UNITS.Meters:
shouldRound = true;
if (unit === UNITS.Feet) {
Expand Down Expand Up @@ -528,7 +536,7 @@ export function formatAddress(address, startIndex = undefined, endIndex = undefi
if (address.postcode?.indexOf(';') >= 0) {
address.postcode = address.postcode.split(';')[0];
}
const { locality, county, ...cleanedUp } = address;
const { county, locality, ...cleanedUp } = address;
const result = addressFormatter.format(cleanedUp, {
fallbackCountryCode: langToCountryCode(lang)
});
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export enum UNIT_FAMILIES {
}

export const DEFAULT_IMPERIAL_UINTS = {
[UNIT_FAMILIES.DistanceSmall]: UNITS.CM,
[UNIT_FAMILIES.DistanceVerySmall]: UNITS.MM,
[UNIT_FAMILIES.DistanceSmall]: UNITS.Inch,
[UNIT_FAMILIES.DistanceVerySmall]: UNITS.Inch,
[UNIT_FAMILIES.Uv]: UNITS.UV,
[UNIT_FAMILIES.Percent]: UNITS.Percent,
[UNIT_FAMILIES.Temperature]: UNITS.Fahrenheit,
Expand All @@ -48,8 +48,8 @@ export const DEFAULT_IMPERIAL_UINTS = {
};

export const DEFAULT_METRIC_UINTS = {
[UNIT_FAMILIES.DistanceSmall]: UNITS.Inch,
[UNIT_FAMILIES.DistanceVerySmall]: UNITS.Inch,
[UNIT_FAMILIES.DistanceSmall]: UNITS.CM,
[UNIT_FAMILIES.DistanceVerySmall]: UNITS.MM,
[UNIT_FAMILIES.Uv]: UNITS.UV,
[UNIT_FAMILIES.Percent]: UNITS.Percent,
[UNIT_FAMILIES.Temperature]: UNITS.Celcius,
Expand Down
2 changes: 1 addition & 1 deletion app/services/weatherData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function propToUnit(prop: WeatherProps, item?: CommonWeatherData) {
return unitsSettings[UNIT_FAMILIES.Uv];
case WeatherProps.precipAccumulation:
if (item?.precipUnitFamily) {
return item?.precipUnitFamily;
return unitsSettings[item?.precipUnitFamily];
}
return unitsSettings[UNIT_FAMILIES.Precipitation];
case WeatherProps.snowfall:
Expand Down

0 comments on commit ea348de

Please sign in to comment.