-
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 2 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 |
---|---|---|
|
@@ -33,6 +33,7 @@ Module.register("MMM-WeatherChart", { | |
dataType: "hourly", | ||
nightBorderDash: [5, 1], | ||
showIcon: false, | ||
showPressure: false, | ||
showRain: false, | ||
showZeroRain: true, | ||
rainUnit: "mm", | ||
|
@@ -45,6 +46,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, 0, 0.8)", | ||
backgroundColor: "rgba(0, 0, 0, 0)", | ||
fillColor: "rgba(255, 255, 255, 0.1)", | ||
dailyLabel: "date", | ||
|
@@ -199,6 +201,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 +312,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 +322,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 +385,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 +469,31 @@ Module.register("MMM-WeatherChart", { | |
data: nightTemps, | ||
yAxisID: "y1", | ||
}); | ||
if (this.config.showPressure) { | ||
datasets.push({ | ||
label: "Pressure", | ||
borderColor: this.config.colorPressure, | ||
pointBackgroundColor: this.config.colorPressure, | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Updated in commit: 90dff89 |
||
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 +581,9 @@ Module.register("MMM-WeatherChart", { | |
y2_max = | ||
Math.max(maxRain, maxSnow, this.config.rainMinHeight) * | ||
(2 + iconTopMargin + iconBelowMargin + tempRainMargin), | ||
y2_min = 0; | ||
y2_min = 0, | ||
y3_max = maxPressure + 20, | ||
y3_min = minPressure - 20; | ||
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. y3_max and y3_min should be carefully calculated to make an appropriate margin. If it's difficult, I'll try to fix after the PR is merged. 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 (showRainSnow) y1_min = y1_min - (maxTemp - minTemp); | ||
const ranges = { | ||
y1: { | ||
|
@@ -550,6 +594,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 +614,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 +659,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 +670,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 +751,32 @@ Module.register("MMM-WeatherChart", { | |
data: maxTemps, | ||
yAxisID: "y1", | ||
}); | ||
if (this.config.showPressure) { | ||
|
||
datasets.push({ | ||
label: "Pressure", | ||
borderColor: this.config.colorPressure, | ||
pointBackgroundColor: this.config.colorPressure, | ||
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", | ||
|
@@ -784,7 +864,10 @@ Module.register("MMM-WeatherChart", { | |
y2_max = | ||
Math.max(maxRain, maxSnow, this.config.rainMinHeight) * | ||
(2 + (iconTopMargin + iconBelowMargin + tempRainMargin) * 2), | ||
y2_min = 0; | ||
y2_min = 0, | ||
yPressure_Min = this.getMin(pressures), | ||
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. Rename yPressure_Min, yPressure_Max to y3_min, y3_max. 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 |
||
yPressure_Max = this.getMax(pressures); | ||
|
||
if (showRainSnow) y1_min = y1_min - (maxValue - minValue); | ||
const ranges = { | ||
y1: { | ||
|
@@ -795,6 +878,11 @@ Module.register("MMM-WeatherChart", { | |
min: y2_min, | ||
max: y2_max, | ||
}, | ||
y3: { | ||
min: yPressure_Min, | ||
max: yPressure_Max, | ||
}, | ||
|
||
}; | ||
|
||
return { labels: labels, datasets: datasets, ranges: ranges }; | ||
|
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 the default color to white?
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