-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull request to enable display of barometric pressure #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,9 @@ Module.register("MMM-WeatherChart", { | |
iconURLBase: "https://openweathermap.org/img/wn/", | ||
dataType: "hourly", | ||
nightBorderDash: [5, 1], | ||
pressureBorderDash: [5,1], | ||
showIcon: false, | ||
showPressure: false, | ||
showRain: false, | ||
showZeroRain: true, | ||
rainUnit: "mm", | ||
|
@@ -45,6 +47,7 @@ Module.register("MMM-WeatherChart", { | |
colorMax: "rgba(255, 255, 255, 1)", | ||
colorRain: "rgba(255, 255, 255, 1)", | ||
colorSnow: "rgba(255, 255, 255, 1)", | ||
colorPressure: "rgba(255, 255, 255, 1)", | ||
backgroundColor: "rgba(0, 0, 0, 0)", | ||
fillColor: "rgba(255, 255, 255, 0.1)", | ||
dailyLabel: "date", | ||
|
@@ -199,6 +202,14 @@ Module.register("MMM-WeatherChart", { | |
} | ||
return max; | ||
}, | ||
|
||
getPressureValue( hPa ){ | ||
if( this.config.units == "imperial" ){ | ||
return hPa * 0.029529983071445; // return value as inHg | ||
} else { | ||
return hPa; | ||
} | ||
}, | ||
|
||
// Calculate MarginFactors from the simultanious equations | ||
// | ||
|
@@ -302,7 +313,8 @@ Module.register("MMM-WeatherChart", { | |
dayTemps = [NaN], | ||
nightTemps = [NaN], | ||
labels = [""], | ||
iconIDs = [NaN]; | ||
iconIDs = [NaN], | ||
pressures = [NaN]; | ||
|
||
data.sort(function (a, b) { | ||
if (a.dt < b.dt) return -1; | ||
|
@@ -311,6 +323,9 @@ Module.register("MMM-WeatherChart", { | |
}); | ||
let dayTime; | ||
for (let i = 0; i < Math.min(this.config.dataNum, data.length); i++) { | ||
|
||
pressures.push( this.getPressureValue(data[i].pressure) ); | ||
|
||
let dateTime = new Date( | ||
data[i].dt * 1000 + this.config.timeOffsetHours * 60 * 60 * 1000 | ||
); | ||
|
@@ -371,11 +386,14 @@ Module.register("MMM-WeatherChart", { | |
nightTemps.push(NaN); | ||
labels.push(""); | ||
iconIDs.push(NaN); | ||
pressures.push(NaN); | ||
|
||
const minTemp = this.getMin(temps), | ||
maxTemp = this.getMax(temps), | ||
maxRain = this.getMax(rains), | ||
maxSnow = this.getMax(snows), | ||
maxPressure = this.getMax(pressures), | ||
minPressure = this.getMin(pressures), | ||
iconLine = [], | ||
icons = []; | ||
|
||
|
@@ -452,6 +470,32 @@ Module.register("MMM-WeatherChart", { | |
data: nightTemps, | ||
yAxisID: "y1", | ||
}); | ||
if (this.config.showPressure) { | ||
datasets.push({ | ||
label: "Pressure", | ||
borderColor: this.config.colorPressure, | ||
pointBackgroundColor: this.config.colorPressure, | ||
borderDash: this.config.pressureBorderDash, | ||
datalabels: { | ||
color: this.config.color, | ||
align: "top", | ||
offset: this.config.datalabelsOffset, | ||
font: { | ||
weight: this.config.fontWeight, | ||
}, | ||
display: this.config.datalabelsDisplay, | ||
formatter: function (value) { | ||
let place = 10 ** self.config.datalabelsRoundDecimalPlace; | ||
let label = Math.round(value * place) / place; | ||
return label; | ||
}, | ||
}, | ||
data: pressures, | ||
//pointStyle: "star", | ||
//fill: true, | ||
yAxisID: "y3", | ||
}); | ||
} | ||
if (this.config.showIcon) { | ||
datasets.push({ | ||
label: "Icons", | ||
|
@@ -539,7 +583,10 @@ Module.register("MMM-WeatherChart", { | |
y2_max = | ||
Math.max(maxRain, maxSnow, this.config.rainMinHeight) * | ||
(2 + iconTopMargin + iconBelowMargin + tempRainMargin), | ||
y2_min = 0; | ||
y2_min = 0, | ||
y3_min = minPressure - (maxPressure - minPressure) * iconTopMargin, | ||
y3_max = maxPressure + ((maxPressure - minPressure) * iconTopMargin); | ||
|
||
if (showRainSnow) y1_min = y1_min - (maxTemp - minTemp); | ||
const ranges = { | ||
y1: { | ||
|
@@ -550,6 +597,10 @@ Module.register("MMM-WeatherChart", { | |
min: y2_min, | ||
max: y2_max, | ||
}, | ||
y3: { | ||
min: y3_min, | ||
max: y3_max, | ||
}, | ||
}; | ||
|
||
return { labels: labels, datasets: datasets, ranges: ranges }; | ||
|
@@ -566,14 +617,18 @@ Module.register("MMM-WeatherChart", { | |
rains = [NaN], | ||
snows = [NaN], | ||
labels = [""], | ||
iconIDs = [NaN]; | ||
iconIDs = [NaN], | ||
pressures = [NaN]; | ||
|
||
data.sort(function (a, b) { | ||
if (a.dt < b.dt) return -1; | ||
if (a.dt > b.dt) return 1; | ||
return 0; | ||
}); | ||
for (let i = 0; i < Math.min(this.config.dataNum, data.length); i++) { | ||
|
||
pressures.push( this.getPressureValue(data[i].pressure) ); | ||
|
||
const dateTime = new Date( | ||
data[i].dt * 1000 + this.config.timeOffsetHours * 60 * 60 * 1000 | ||
); | ||
|
@@ -607,6 +662,7 @@ Module.register("MMM-WeatherChart", { | |
snows.push(0); | ||
} | ||
iconIDs.push(data[i].weather[0].icon); | ||
|
||
} | ||
|
||
// Add dummy data to make space on the left and right side of the chart | ||
|
@@ -617,6 +673,7 @@ Module.register("MMM-WeatherChart", { | |
snows.push(NaN); | ||
labels.push(""); | ||
iconIDs.push(NaN); | ||
pressures.push(NaN); | ||
|
||
const minValue = this.getMin(minTemps), | ||
maxValue = this.getMax(maxTemps), | ||
|
@@ -697,6 +754,33 @@ Module.register("MMM-WeatherChart", { | |
data: maxTemps, | ||
yAxisID: "y1", | ||
}); | ||
if (this.config.showPressure) { | ||
|
||
datasets.push({ | ||
label: "Pressure", | ||
borderColor: this.config.colorPressure, | ||
pointBackgroundColor: this.config.colorPressure, | ||
borderDash: this.config.pressureBorderDash, | ||
datalabels: { | ||
color: this.config.colorPressure, | ||
align: "top", | ||
offset: this.config.datalabelsOffset, | ||
font: { | ||
weight: this.config.fontWeight, | ||
}, | ||
display: this.config.datalabelsDisplay, | ||
formatter: function (value) { | ||
let place = 10 ** self.config.datalabelsRoundDecimalPlace; | ||
let label = Math.round(value * place) / place; | ||
return label; | ||
}, | ||
}, | ||
data: pressures, | ||
yAxisID: "y3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hide the y3 axis at the far left side. y1, y2 axis is hide by the below code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in commit: 90dff89 |
||
}); | ||
|
||
|
||
} | ||
if (this.config.showIcon) { | ||
datasets.push({ | ||
label: "Icons", | ||
|
@@ -777,14 +861,20 @@ Module.register("MMM-WeatherChart", { | |
}); | ||
} | ||
} | ||
|
||
minPressure = this.getMin(pressures); | ||
maxPressure = this.getMax(pressures); | ||
|
||
// Set Y-Axis range not to overlap each other | ||
let y1_max = iconLine[0] + (maxValue - minValue) * iconTopMargin, | ||
y1_min = minValue - (maxValue - minValue) * tempRainMargin, | ||
y2_max = | ||
Math.max(maxRain, maxSnow, this.config.rainMinHeight) * | ||
(2 + (iconTopMargin + iconBelowMargin + tempRainMargin) * 2), | ||
y2_min = 0; | ||
y2_min = 0, | ||
y3_min = minPressure - (maxPressure - minPressure) * iconTopMargin, | ||
y3_max = maxPressure + ((maxPressure - minPressure) * iconTopMargin); | ||
|
||
if (showRainSnow) y1_min = y1_min - (maxValue - minValue); | ||
const ranges = { | ||
y1: { | ||
|
@@ -795,6 +885,11 @@ Module.register("MMM-WeatherChart", { | |
min: y2_min, | ||
max: y2_max, | ||
}, | ||
y3: { | ||
min: y3_min, | ||
max: y3_max, | ||
}, | ||
|
||
}; | ||
|
||
return { labels: labels, datasets: datasets, ranges: ranges }; | ||
|
@@ -882,6 +977,12 @@ Module.register("MMM-WeatherChart", { | |
min: dataset.ranges.y2.min, | ||
max: dataset.ranges.y2.max, | ||
}, | ||
y3: { | ||
display: false, | ||
min: dataset.ranges.y3.min, | ||
max: dataset.ranges.y3.max, | ||
}, | ||
|
||
}, | ||
animation: { duration: 500 }, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloud you set borderDash so that the line style is selectable by users? The pressure line should be easily distinguishable because the pressure line overwrap with the other lines.
For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit: 90dff89