From 8b2d544576a69804e05071543550301a622298eb Mon Sep 17 00:00:00 2001 From: fwitte Date: Sun, 6 Jan 2019 12:24:26 +0100 Subject: [PATCH 1/5] added fade and maxnumberofdays options for forecast --- modules/default/weather/forecast.njk | 6 +++++- modules/default/weather/weather.js | 26 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/default/weather/forecast.njk b/modules/default/weather/forecast.njk index 556a98ff05..d03d30189e 100644 --- a/modules/default/weather/forecast.njk +++ b/modules/default/weather/forecast.njk @@ -1,7 +1,10 @@ {% if forecast %} + {% set numSteps = forecast | calcNumSteps %} + {% set currentStep = 0 %} + {% set forecast = forecast.slice(0, numSteps) %} {% for f in forecast %} - + {% endif %} + {% set currentStep = currentStep + 1 %} {% endfor %}
{{ f.date.format('ddd') }} @@ -16,6 +19,7 @@
{% else %} diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 52e9cfee5d..818bc40a4f 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -33,6 +33,9 @@ Module.register("weather",{ decimalSymbol: ".", showIndoorTemperature: false, showIndoorHumidity: false, + maxNumberOfDays: 3, + fade: true, + fadePoint: 0.25, // Start on 1/4th of the list. initialLoadDelay: 0, // 0 seconds delay retryDelay: 2500, @@ -198,7 +201,7 @@ Module.register("weather",{ } } } else if (type === "rain") { - if (isNaN(value)) { + if (isNaN(value) || value === 0) { value = ""; } else { value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`; @@ -217,5 +220,26 @@ Module.register("weather",{ this.nunjucksEnvironment().addFilter("decimalSymbol", function(value) { return value.replace(/\./g, this.config.decimalSymbol); }.bind(this)); + + this.nunjucksEnvironment().addFilter("calcNumSteps", function(forecast) { + return Math.min(forecast.length, this.config.maxNumberOfDays); + }.bind(this)); + + this.nunjucksEnvironment().addFilter("opacity", function(currentStep, numSteps) { + if (this.config.fade && this.config.fadePoint < 1) { + if (this.config.fadePoint < 0) { + this.config.fadePoint = 0; + } + var startingPoint = numSteps * this.config.fadePoint; + var numFadesteps = numSteps - startingPoint; + if (currentStep >= startingPoint) { + return 1 - (currentStep - startingPoint) / numFadesteps; + } else { + return 1; + } + } else { + return 1; + } + }.bind(this)); } }); From 63aa840b55cb989fe419b0e633ae6b6da00be714 Mon Sep 17 00:00:00 2001 From: fwitte Date: Sun, 6 Jan 2019 12:30:26 +0100 Subject: [PATCH 2/5] replaced tabs with spaces --- modules/default/weather/forecast.njk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/default/weather/forecast.njk b/modules/default/weather/forecast.njk index d03d30189e..315ebff82c 100644 --- a/modules/default/weather/forecast.njk +++ b/modules/default/weather/forecast.njk @@ -1,8 +1,8 @@ {% if forecast %} - {% set numSteps = forecast | calcNumSteps %} - {% set currentStep = 0 %} + {% set numSteps = forecast | calcNumSteps %} + {% set currentStep = 0 %} - {% set forecast = forecast.slice(0, numSteps) %} + {% set forecast = forecast.slice(0, numSteps) %} {% for f in forecast %} @@ -19,7 +19,7 @@ {% endif %} - {% set currentStep = currentStep + 1 %} + {% set currentStep = currentStep + 1 %} {% endfor %}
{{ f.date.format('ddd') }}
{% else %} From 733dfa1467741f749f7aca63fa6b8aea4f088383 Mon Sep 17 00:00:00 2001 From: fwitte Date: Sun, 6 Jan 2019 12:34:27 +0100 Subject: [PATCH 3/5] adjusted README --- modules/default/weather/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/default/weather/README.md b/modules/default/weather/README.md index d10297d173..a035e85e40 100644 --- a/modules/default/weather/README.md +++ b/modules/default/weather/README.md @@ -71,6 +71,9 @@ The following properties can be configured: | `tableClass` | The class for the forecast table.

**Default value:** `'small'` | `colored` | If set to `true`, the min and max temperature are color coded.

**Default value:** `false` | `showRainAmount` | Show the amount of rain in the forecast

**Possible values:** `true` or `false`
**Default value:** `true` +| `fade` | Fade the future events to black. (Gradient)

**Possible values:** `true` or `false`
**Default value:** `true` +| `fadePoint` | Where to start fade?

**Possible values:** `0` (top of the list) - `1` (bottom of list)
**Default value:** `0.25` +| `maxNumberOfDays` | How many days of forecast to return. Specified by config.js

**Possible values:** `1` - `16`
**Default value:** `5` (5 days)
This value is optional. By default the weatherforecast module will return 5 days. ### Openweathermap options From 766f21b5254bb045b94bb0e6687c1f72c05232c2 Mon Sep 17 00:00:00 2001 From: fwitte Date: Sun, 6 Jan 2019 12:34:44 +0100 Subject: [PATCH 4/5] adjusted default values --- modules/default/weather/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 818bc40a4f..0c2304240a 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -33,7 +33,7 @@ Module.register("weather",{ decimalSymbol: ".", showIndoorTemperature: false, showIndoorHumidity: false, - maxNumberOfDays: 3, + maxNumberOfDays: 5, fade: true, fadePoint: 0.25, // Start on 1/4th of the list. From a79e51c76f8dcfc2ac4dddfb1b18554ecb9af6d5 Mon Sep 17 00:00:00 2001 From: fwitte Date: Mon, 7 Jan 2019 08:51:17 +0100 Subject: [PATCH 5/5] updated +CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a849a2e6..f4fd8af871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Aligned indoor values in current weather vertical [#1499](https://github.com/MichMich/MagicMirror/issues/1499). - Added humidity support to nunjuck unit filter. - Do not display degree symbol for temperature in Kelvin [#1503](https://github.com/MichMich/MagicMirror/issues/1503). +- Added fade, fadePoint and maxNumberOfDays properties to the forecast mode [#1516](https://github.com/MichMich/MagicMirror/issues/1516) ## [2.6.0] - 2019-01-01