Skip to content
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

Hourly Dew Point Forecast #258

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions dist/weather-chart-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const locale = {
'tempHi': 'Temperature',
'tempLo': 'Temperature night',
'precip': 'Precipitations',
'dewpoint': 'Dew Point',
'feelsLike': 'Feels like',
'units': {
'km/h': 'km/h',
Expand Down Expand Up @@ -1545,6 +1546,15 @@ class WeatherChartCardEditor extends s {
Show Wind Forecast
</label>
</div>
<div class="switch-container">
<ha-switch
@change="${(e) => this._valueChanged(e, 'forecast.show_dew_point_forecast')}"
.checked="${forecastConfig.show_dew_point_forecast !== false}"
></ha-switch>
<label class="switch-label">
Show Dew Point Forecast
</label>
</div>
<div class="switch-container">
<ha-switch
@change="${(e) => this._valueChanged(e, 'forecast.round_temp')}"
Expand Down Expand Up @@ -17833,6 +17843,7 @@ static getStubConfig(hass, unusedEntities, allEntities) {
show_wind_forecast: true,
condition_icons: true,
round_temp: false,
show_dew_point_forecast: false,
type: 'daily',
number_of_forecasts: '0',
disable_animation: false,
Expand Down Expand Up @@ -17883,9 +17894,11 @@ setConfig(config) {
temperature1_color: 'rgba(255, 152, 0, 1.0)',
temperature2_color: 'rgba(68, 115, 158, 1.0)',
precipitation_color: 'rgba(132, 209, 253, 1.0)',
dewpoint_color: 'blue',
condition_icons: true,
show_wind_forecast: true,
round_temp: false,
show_dew_point_forecast: false,
type: 'daily',
number_of_forecasts: '0',
'12hourformat': false,
Expand Down Expand Up @@ -18341,6 +18354,15 @@ drawChart({ config, language, weather, forecastItems } = this) {
offset: -10,
},
},
{
label: this.ll('dewpoint'),
type: 'line',
data: data.dewPoint,
yAxisID: 'DPAxis',
borderColor: config.forecast.dewpoint_color,
backgroundColor: config.forecast.dewpoint_color,
pointRadius: 1,
},
];

const chart_text_color = (config.forecast.chart_text_color === 'auto') ? textColor : config.forecast.chart_text_color;
Expand Down Expand Up @@ -18381,6 +18403,24 @@ drawChart({ config, language, weather, forecastItems } = this) {
lineHeight: 0.7,
},
};

datasets[3].datalabels = {
display: function (context) {
return 'auto';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
},
align: 'bottom',
anchor: 'center',
backgroundColor: 'transparent',
borderColor: 'transparent',
color: config.forecast.chart_text_color,
font: {
size: parseInt(config.forecast.labels_font_size) + 1,
lineHeight: 0.7,
},
};
}

this.forecastChart = new Chart(ctx, {
Expand Down Expand Up @@ -18468,6 +18508,19 @@ drawChart({ config, language, weather, forecastItems } = this) {
display: false,
},
},
DPAxis: {
position: 'left',
beginAtZero: false,
suggestedMin: Math.min(...data.tempHigh, ...data.tempLow, ...data.dewPoint) - 5,
suggestedMax: Math.max(...data.tempHigh, ...data.tempLow, ...data.dewPoint) + 3,
grid: {
display: false,
drawTicks: false,
},
ticks: {
display: false,
},
},
},
plugins: {
legend: {
Expand Down Expand Up @@ -18525,10 +18578,12 @@ drawChart({ config, language, weather, forecastItems } = this) {
computeForecastData({ config, forecastItems } = this) {
var forecast = this.forecasts ? this.forecasts.slice(0, forecastItems) : [];
var roundTemp = config.forecast.round_temp == true;
var showDewpointForecast = config.forecast.show_dew_point_forecast == true;
var dateTime = [];
var tempHigh = [];
var tempLow = [];
var precip = [];
var dewPoint = [];

for (var i = 0; i < forecast.length; i++) {
var d = forecast[i];
Expand All @@ -18555,6 +18610,9 @@ computeForecastData({ config, forecastItems } = this) {
} else {
precip.push(d.precipitation);
}
if (showDewpointForecast && typeof d.dew_point !== 'undefined') {
dewPoint.push(d.dew_point);
}
}

return {
Expand All @@ -18563,6 +18621,7 @@ computeForecastData({ config, forecastItems } = this) {
tempHigh,
tempLow,
precip,
dewPoint,
}
}

Expand All @@ -18578,6 +18637,7 @@ updateChart({ forecasts, forecastChart } = this) {
forecastChart.data.datasets[0].data = data.tempHigh;
forecastChart.data.datasets[1].data = data.tempLow;
forecastChart.data.datasets[2].data = data.precip;
forecastChart.data.datasets[3].data = data.dewPoint;
forecastChart.update();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const locale = {
'tempHi': 'Temperature',
'tempLo': 'Temperature night',
'precip': 'Precipitations',
'dewpoint': 'Dew Point',
'feelsLike': 'Feels like',
'units': {
'km/h': 'km/h',
Expand Down
50 changes: 50 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static getStubConfig(hass, unusedEntities, allEntities) {
show_wind_forecast: true,
condition_icons: true,
round_temp: false,
show_dew_point_forecast: false,
type: 'daily',
number_of_forecasts: '0',
disable_animation: false,
Expand Down Expand Up @@ -108,9 +109,11 @@ setConfig(config) {
temperature1_color: 'rgba(255, 152, 0, 1.0)',
temperature2_color: 'rgba(68, 115, 158, 1.0)',
precipitation_color: 'rgba(132, 209, 253, 1.0)',
dewpoint_color: 'blue',
condition_icons: true,
show_wind_forecast: true,
round_temp: false,
show_dew_point_forecast: false,
type: 'daily',
number_of_forecasts: '0',
'12hourformat': false,
Expand Down Expand Up @@ -566,6 +569,15 @@ drawChart({ config, language, weather, forecastItems } = this) {
offset: -10,
},
},
{
label: this.ll('dewpoint'),
type: 'line',
data: data.dewPoint,
yAxisID: 'DPAxis',
borderColor: config.forecast.dewpoint_color,
backgroundColor: config.forecast.dewpoint_color,
pointRadius: 1,
},
];

const chart_text_color = (config.forecast.chart_text_color === 'auto') ? textColor : config.forecast.chart_text_color;
Expand Down Expand Up @@ -606,6 +618,24 @@ drawChart({ config, language, weather, forecastItems } = this) {
lineHeight: 0.7,
},
};

datasets[3].datalabels = {
display: function (context) {
return 'auto';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
},
align: 'bottom',
anchor: 'center',
backgroundColor: 'transparent',
borderColor: 'transparent',
color: config.forecast.chart_text_color,
font: {
size: parseInt(config.forecast.labels_font_size) + 1,
lineHeight: 0.7,
},
};
}

this.forecastChart = new Chart(ctx, {
Expand Down Expand Up @@ -693,6 +723,19 @@ drawChart({ config, language, weather, forecastItems } = this) {
display: false,
},
},
DPAxis: {
position: 'left',
beginAtZero: false,
suggestedMin: Math.min(...data.tempHigh, ...data.tempLow, ...data.dewPoint) - 5,
suggestedMax: Math.max(...data.tempHigh, ...data.tempLow, ...data.dewPoint) + 3,
grid: {
display: false,
drawTicks: false,
},
ticks: {
display: false,
},
},
},
plugins: {
legend: {
Expand Down Expand Up @@ -750,10 +793,12 @@ drawChart({ config, language, weather, forecastItems } = this) {
computeForecastData({ config, forecastItems } = this) {
var forecast = this.forecasts ? this.forecasts.slice(0, forecastItems) : [];
var roundTemp = config.forecast.round_temp == true;
var showDewpointForecast = config.forecast.show_dew_point_forecast == true;
var dateTime = [];
var tempHigh = [];
var tempLow = [];
var precip = [];
var dewPoint = [];

for (var i = 0; i < forecast.length; i++) {
var d = forecast[i];
Expand All @@ -780,6 +825,9 @@ computeForecastData({ config, forecastItems } = this) {
} else {
precip.push(d.precipitation);
}
if (showDewpointForecast && typeof d.dew_point !== 'undefined') {
dewPoint.push(d.dew_point);
}
}

return {
Expand All @@ -788,6 +836,7 @@ computeForecastData({ config, forecastItems } = this) {
tempHigh,
tempLow,
precip,
dewPoint,
}
}

Expand All @@ -803,6 +852,7 @@ updateChart({ forecasts, forecastChart } = this) {
forecastChart.data.datasets[0].data = data.tempHigh;
forecastChart.data.datasets[1].data = data.tempLow;
forecastChart.data.datasets[2].data = data.precip;
forecastChart.data.datasets[3].data = data.dewPoint;
forecastChart.update();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/weather-chart-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,15 @@ class WeatherChartCardEditor extends LitElement {
Show Wind Forecast
</label>
</div>
<div class="switch-container">
<ha-switch
@change="${(e) => this._valueChanged(e, 'forecast.show_dew_point_forecast')}"
.checked="${forecastConfig.show_dew_point_forecast !== false}"
></ha-switch>
<label class="switch-label">
Show Dew Point Forecast
</label>
</div>
<div class="switch-container">
<ha-switch
@change="${(e) => this._valueChanged(e, 'forecast.round_temp')}"
Expand Down