Skip to content

Commit

Permalink
Merge pull request #133 from mlamberts78/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mlamberts78 committed Mar 6, 2024
2 parents c07434d + 6a1737e commit a12dacd
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ HACS is a third party community store and is not included in Home Assistant out
| show_time_seconds | boolean | false | Show or hide seconds for the current time on the card. |
| show_day | boolean | false | Show or hide the current day on the card. (Only visible when show_time is true.) |
| show_date | boolean | false | Show or hide the current date the card. (Only visible when show_time is true.) |
| show_humid | boolean | true | Show or hide humidity on the card. |
| show_humidity | boolean | true | Show or hide humidity on the card. |
| show_pressure | boolean | true | Show or hide pressure on the card. |
| show_wind_direction | boolean | true | Show or hide wind_direction on the card. |
| show_wind_speed | boolean | true | Show or hide wind_speed on the card. |
Expand Down
68 changes: 42 additions & 26 deletions dist/weather-chart-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -18175,7 +18175,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
categoryPercentage: 1.0,
datalabels: {
display: function (context) {
return context.dataset.data[context.dataIndex] > 0 ? 'auto' : false;
return context.dataset.data[context.dataIndex] > 0 ? 'true' : false;
},
formatter: function (value, context) {
const precipitationType = config.forecast.precipitation_type;
Expand All @@ -18186,7 +18186,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
let formattedValue;
if (precipitationType === 'rainfall') {
if (probability !== undefined && probability !== null && config.forecast.show_probability) {
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}\n${Math.round(probability)}%`;
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}\n${Math.round(probability)}%`;
} else {
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}`;
}
Expand All @@ -18210,7 +18210,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
if (config.forecast.style === 'style2') {
datasets[0].datalabels = {
display: function (context) {
return 'auto';
return 'true';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
Expand All @@ -18228,7 +18228,7 @@ drawChart({ config, language, weather, forecastItems } = this) {

datasets[1].datalabels = {
display: function (context) {
return 'auto';
return 'true';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
Expand Down Expand Up @@ -18268,30 +18268,46 @@ drawChart({ config, language, weather, forecastItems } = this) {
drawTicks: false,
color: dividerColor,
},
ticks: {
maxRotation: 0,
color: config.forecast.chart_datetime_color || textColor,
padding: 10,
callback: function (value, index, values) {
var datetime = this.getLabelForValue(value);
var dateObj = new Date(datetime);
var weekday = dateObj.toLocaleString(language, { weekday: 'short' }).toUpperCase();
ticks: {
maxRotation: 0,
color: config.forecast.chart_datetime_color || textColor,
padding: config.forecast.precipitation_type === 'rainfall' && config.forecast.show_probability && config.forecast.type !== 'hourly' ? 4 : 10,
callback: function (value, index, values) {
var datetime = this.getLabelForValue(value);
var dateObj = new Date(datetime);

var timeFormatOptions = {
hour12: config.use_12hour_format,
hour: 'numeric',
...(config.use_12hour_format ? {} : { minute: 'numeric' }),
};

var timeFormatOptions = {
hour12: config.use_12hour_format,
hour: 'numeric',
...(config.use_12hour_format ? {} : { minute: 'numeric' }),
};
var time = dateObj.toLocaleTimeString(language, timeFormatOptions);
var mode = 'daily';

var time = dateObj.toLocaleTimeString(language, timeFormatOptions);
if (forecast.length >= 3 && new Date(forecast[2].datetime) - new Date(forecast[1].datetime) < 864e5) {
mode = 'hourly';
}

time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
if (mode === 'hourly') {
return time;
}
return weekday;
},
},
if (dateObj.getHours() === 0 && dateObj.getMinutes() === 0 && mode === 'hourly') {
var dateFormatOptions = {
day: 'numeric',
month: 'short',
};
var date = dateObj.toLocaleDateString(language, dateFormatOptions);
time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
return [date, time];
}

if (mode !== 'hourly') {
var weekday = dateObj.toLocaleString(language, { weekday: 'short' }).toUpperCase();
return weekday;
}

time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
return time;
},
},
},
TempAxis: {
position: 'left',
Expand Down Expand Up @@ -18327,7 +18343,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
borderColor: context => context.dataset.backgroundColor,
borderRadius: 0,
borderWidth: 1.5,
padding: 4,
padding: config.forecast.precipitation_type === 'rainfall' && config.forecast.show_probability && config.forecast.type !== 'hourly' ? 3 : 4,
color: config.forecast.chart_text_color || textColor,
font: {
size: config.forecast.labels_font_size,
Expand Down
70 changes: 43 additions & 27 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
categoryPercentage: 1.0,
datalabels: {
display: function (context) {
return context.dataset.data[context.dataIndex] > 0 ? 'auto' : false;
return context.dataset.data[context.dataIndex] > 0 ? 'true' : false;
},
formatter: function (value, context) {
const precipitationType = config.forecast.precipitation_type;
Expand All @@ -519,7 +519,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
let formattedValue;
if (precipitationType === 'rainfall') {
if (probability !== undefined && probability !== null && config.forecast.show_probability) {
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}\n${Math.round(probability)}%`;
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}\n${Math.round(probability)}%`;
} else {
formattedValue = `${rainfall > 9 ? Math.round(rainfall) : rainfall.toFixed(1)} ${precipUnit}`;
}
Expand All @@ -543,7 +543,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
if (config.forecast.style === 'style2') {
datasets[0].datalabels = {
display: function (context) {
return 'auto';
return 'true';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
Expand All @@ -561,7 +561,7 @@ drawChart({ config, language, weather, forecastItems } = this) {

datasets[1].datalabels = {
display: function (context) {
return 'auto';
return 'true';
},
formatter: function (value, context) {
return context.dataset.data[context.dataIndex] + '°';
Expand Down Expand Up @@ -602,28 +602,44 @@ drawChart({ config, language, weather, forecastItems } = this) {
color: dividerColor,
},
ticks: {
maxRotation: 0,
color: config.forecast.chart_datetime_color || textColor,
padding: 10,
callback: function (value, index, values) {
var datetime = this.getLabelForValue(value);
var dateObj = new Date(datetime);
var weekday = dateObj.toLocaleString(language, { weekday: 'short' }).toUpperCase();

var timeFormatOptions = {
hour12: config.use_12hour_format,
hour: 'numeric',
...(config.use_12hour_format ? {} : { minute: 'numeric' }),
};

var time = dateObj.toLocaleTimeString(language, timeFormatOptions);

time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
if (mode === 'hourly') {
return time;
}
return weekday;
},
maxRotation: 0,
color: config.forecast.chart_datetime_color || textColor,
padding: config.forecast.precipitation_type === 'rainfall' && config.forecast.show_probability && config.forecast.type !== 'hourly' ? 4 : 10,
callback: function (value, index, values) {
var datetime = this.getLabelForValue(value);
var dateObj = new Date(datetime);

var timeFormatOptions = {
hour12: config.use_12hour_format,
hour: 'numeric',
...(config.use_12hour_format ? {} : { minute: 'numeric' }),
};

var time = dateObj.toLocaleTimeString(language, timeFormatOptions);
var mode = 'daily';

if (forecast.length >= 3 && new Date(forecast[2].datetime) - new Date(forecast[1].datetime) < 864e5) {
mode = 'hourly';
}

if (dateObj.getHours() === 0 && dateObj.getMinutes() === 0 && mode === 'hourly') {
var dateFormatOptions = {
day: 'numeric',
month: 'short',
};
var date = dateObj.toLocaleDateString(language, dateFormatOptions);
time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
return [date, time];
}

if (mode !== 'hourly') {
var weekday = dateObj.toLocaleString(language, { weekday: 'short' }).toUpperCase();
return weekday;
}

time = time.replace('a.m.', 'AM').replace('p.m.', 'PM');
return time;
},
},
},
TempAxis: {
Expand Down Expand Up @@ -660,7 +676,7 @@ drawChart({ config, language, weather, forecastItems } = this) {
borderColor: context => context.dataset.backgroundColor,
borderRadius: 0,
borderWidth: 1.5,
padding: 4,
padding: config.forecast.precipitation_type === 'rainfall' && config.forecast.show_probability && config.forecast.type !== 'hourly' ? 3 : 4,
color: config.forecast.chart_text_color || textColor,
font: {
size: config.forecast.labels_font_size,
Expand Down

0 comments on commit a12dacd

Please sign in to comment.