Skip to content

Commit

Permalink
only show precipiation graph if there's rain
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcinnes committed Oct 10, 2016
1 parent 340c4b4 commit c5da38a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions MMM-forecast-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Module.register("MMM-forecast-io", {
showForecast: true,
showPrecipitationGraph: true,
precipitationGraphWidth: 400,
precipitationProbabilityThreshold: 0.1,
unitTable: {
'default': 'auto',
'metric': 'si',
Expand Down Expand Up @@ -157,7 +158,8 @@ Module.register("MMM-forecast-io", {
wrapper.appendChild(large);
wrapper.appendChild(summary);

if (minutely && this.config.showPrecipitationGraph) {
if (this.config.showPrecipitationGraph &&
this.isAnyPrecipitation(minutely)) {
wrapper.appendChild(this.renderPrecipitationGraph());
}

Expand All @@ -168,6 +170,20 @@ Module.register("MMM-forecast-io", {
return wrapper;
},

isAnyPrecipitation: function (minutely) {
if (!minutely) {
return false;
}
var data = this.weatherData.minutely.data;
var threshold = this.config.precipitationProbabilityThreshold;
for (i = 0; i < data.length; i++) {
if (data[i].precipProbability > threshold) {
return true;
}
}
return false;
},

renderPrecipitationGraph: function () {
var i;
var width = this.config.precipitationGraphWidth;
Expand Down Expand Up @@ -209,9 +225,10 @@ Module.register("MMM-forecast-io", {
context.globalCompositeOperation = 'xor';
context.beginPath();
context.moveTo(0, height);
var intensity
var threshold = this.config.precipitationProbabilityThreshold;
var intensity;
for (i = 0; i < data.length; i++) {
if (data[i].precipProbability < 0.1) {
if (data[i].precipProbability < threshold) {
intensity = 0;
} else {
intensity = data[i].precipIntensity * height * 5;
Expand Down

0 comments on commit c5da38a

Please sign in to comment.