From 4122095665d3942564c318be23c2d86f286c5d75 Mon Sep 17 00:00:00 2001 From: kuuuurija Date: Sat, 29 Dec 2018 22:19:02 +0200 Subject: [PATCH] added degrees to compass --- package.json | 2 +- src/components/additional-info.js | 3 ++- src/modules/utils.js | 14 +++++++++++++- src/service-worker.js | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9d1f041..0f36206 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "weather-sucks", - "version": "8.0.0", + "version": "9.0.0", "description": "Our Earth needs yet another Weather App", "devDependencies": { "typescript": "^3.2.2" diff --git a/src/components/additional-info.js b/src/components/additional-info.js index e079f75..2c439e9 100644 --- a/src/components/additional-info.js +++ b/src/components/additional-info.js @@ -1,4 +1,5 @@ import { html } from '../libs/preact.js'; +import { degreeToCompass } from '../modules/utils.js'; /** * @param {AdditionalInfoProps} props @@ -16,7 +17,7 @@ export const AdditionalInfoPanel = ({ show, data }) => {
Humidity: ${humidity}%
Pressure: ${pressure} hPa
Wind Speed: ${windSpeed} m/s
-
Wind Direction: ${windDirection}°
+
Wind Direction: ${windDirection}° (${degreeToCompass(windDirection)})
`; diff --git a/src/modules/utils.js b/src/modules/utils.js index 50e99e8..c9ec7c3 100644 --- a/src/modules/utils.js +++ b/src/modules/utils.js @@ -123,7 +123,7 @@ export function convertKelvinTo(kelvin, unit) { } if (unit === 'F') { - return Math.round((kelvin - 273.15) * (9/5) + 32); + return Math.round((kelvin - 273.15) * (9 / 5) + 32); } throw Error('unknown unit: ' + unit); @@ -206,6 +206,17 @@ export function toUnit(val) { return 'C'; } +/** + * https://stackoverflow.com/a/25867068 + * @param {number} degree + * @return {string} + */ +export function degreeToCompass(degree) { + const val = Math.floor((degree / 22.5) + 0.5); + const arr = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']; + return arr[(val % 16)]; +} + /** * @param {Callback} callback * @return {DisposeCallback} @@ -219,6 +230,7 @@ export function onDocumentClick(callback) { document.removeEventListener('click', listener); }; } + /** * @return {void} */ diff --git a/src/service-worker.js b/src/service-worker.js index 6a98d16..d118a25 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -1,7 +1,7 @@ // @ts-nocheck // having issues with ServiceWorker types -const version = '9.0.0'; // version needs to be updated manually for now +const version = '10.0.0'; // version needs to be updated manually for now const projectName = 'weather-sucks'; const preCacheName = `${projectName}-precache-${version}`; const runtimeCacheName = `${projectName}-runtimeCache-${version}`;