Skip to content

Commit

Permalink
added degrees to compass
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenratio committed Dec 29, 2018
1 parent fdb2d87 commit 4122095
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/components/additional-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { html } from '../libs/preact.js';
import { degreeToCompass } from '../modules/utils.js';

/**
* @param {AdditionalInfoProps} props
Expand All @@ -16,7 +17,7 @@ export const AdditionalInfoPanel = ({ show, data }) => {
<div>Humidity: ${humidity}%</div>
<div>Pressure: ${pressure} hPa</div>
<div>Wind Speed: ${windSpeed} m/s</div>
<div>Wind Direction: ${windDirection}°</div>
<div>Wind Direction: ${windDirection}° (${degreeToCompass(windDirection)})</div>
</div>
</div>
`;
Expand Down
14 changes: 13 additions & 1 deletion src/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}
Expand All @@ -219,6 +230,7 @@ export function onDocumentClick(callback) {
document.removeEventListener('click', listener);
};
}

/**
* @return {void}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/service-worker.js
Original file line number Diff line number Diff line change
@@ -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}`;
Expand Down

0 comments on commit 4122095

Please sign in to comment.