Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Update custom-weather-card-chart.js
Browse files Browse the repository at this point in the history
Add localisation to date ticks. Tooltip: show zero if precipitation is null, support imperial units for precipitations
  • Loading branch information
Yevgenium authored Jan 9, 2019
1 parent e5e9b42 commit 45c63f4
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions custom-weather-card-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WeatherCardChart extends Polymer.Element {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
margin: 10px 0px 10px 0px;
}
.attributes div {
text-align: center;
Expand All @@ -42,10 +42,8 @@ class WeatherCardChart extends Polymer.Element {
display: flex;
justify-content: space-between;
align-items: center;
margin-left: 16px;
margin-right: -2px;
margin: 0px -2px 0px 16px;
}
</style>
<ha-card header="[[title]]">
<div class="card">
Expand Down Expand Up @@ -118,8 +116,8 @@ class WeatherCardChart extends Polymer.Element {
'windy-variant': 'hass:weather-windy-variant'
};
this.cardinalDirections = [
'N', 'NNO', 'NO', 'ONO', 'O', 'OZO', 'ZO', 'ZZO',
'Z', 'ZZW', 'ZW', 'WZW', 'W', 'WNW', 'NW', 'NNW', 'N'
'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'
];
this.cardinalDirectionsIcon = [
'mdi:arrow-down', 'mdi:arrow-bottom-left', 'mdi:arrow-left',
Expand Down Expand Up @@ -200,6 +198,8 @@ class WeatherCardChart extends Polymer.Element {
var dataArray = [];
var data = this.weatherObj.attributes.forecast.slice(0,9);
var tempUnit = this._hass.config.unit_system.temperature;
var lengthUnit = this._hass.config.unit_system.length;
var precipUnit = lengthUnit === 'km' ? 'mm' : 'in';
var i;
if (!this.weatherObj.attributes.forecast) {
return [];
Expand Down Expand Up @@ -276,11 +276,6 @@ class WeatherCardChart extends Polymer.Element {
},
legend: {
display: false,
position: 'top',
labels: {
fontColor: textColor,
boxWidth: 10,
},
},
scales: {
xAxes: [{
Expand All @@ -297,24 +292,21 @@ class WeatherCardChart extends Polymer.Element {
{
id: 'DateAxis',
position: 'top',
type: 'time',
gridLines: {
display: true,
drawBorder: false,
color: dividerColor,
},
time: {
unit: 'day',
displayFormats: {
day: 'dd',
},
},
ticks: {
display: true,
source: 'labels',
autoSkip: true,
fontColor: textColor,
maxRotation: 0,
callback: function(value, index, values) {
return new Date(value).toLocaleDateString([],
{ weekday: 'short' });
},
},
}],
yAxes: [{
Expand All @@ -331,8 +323,7 @@ class WeatherCardChart extends Polymer.Element {
fontColor: textColor,
callback: function(value, index, values) {
if (value > 0) {
return '+' + value;
}
return '+' + value }
return value;
}
},
Expand Down Expand Up @@ -363,20 +354,23 @@ class WeatherCardChart extends Polymer.Element {
month: 'long',
day: 'numeric',
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
});
},
label: function(tooltipItems, data) {
var label = data.datasets[tooltipItems.datasetIndex].label || '';
if (data.datasets[2].label == label) {
return label + ': ' + tooltipItems.yLabel + ' mm';
return label + ': ' + (tooltipItems.yLabel ?
(tooltipItems.yLabel + ' ' + precipUnit) : ('0 ' + precipUnit));
}
return label + ': ' + tooltipItems.yLabel + ' ' + tempUnit;
},
}
},
layout: {
padding: {
top: '10.0',
top: '0.0',
bottom: '0.0',
right: '0.0',
left: '-6.0',
Expand Down

0 comments on commit 45c63f4

Please sign in to comment.