Added timestamps to grid

This commit is contained in:
Zakary Timson 2019-06-16 16:03:15 -04:00
parent 0c05a191c5
commit 7545dd8069
3 changed files with 14 additions and 1 deletions

View File

@ -33,6 +33,8 @@
[yScaleMin]="0"
[yScaleMax]="30"
[yAxisTickFormatting]="voltFormat"
[xAxis]="true"
[xAxisTickFormatting]="dateFormat"
[roundDomains]="true"
></ngx-charts-area-chart>
</div>

View File

@ -21,6 +21,16 @@ export class BatteryComponent implements OnInit {
ngOnInit() { }
dateFormat(date: Date) {
let hours = date.getHours();
if(hours > 12) hours -= 12;
let minutes: any = date.getMinutes();
if(minutes < 10) minutes = '0' + minutes;
return `${hours}:${minutes} ${date.getHours() > 12 ? 'PM' : 'AM'}`;
}
voltFormat(val) {
return `${val} V`
}

View File

@ -48,9 +48,10 @@ export class BatteryService {
this.relayMode = data.config.relayMode ? data.config.relayMode.toString() : 'null';
this.batteries = Object.keys(data.modules).map(key => {
let last = data.modules[key].length - 1;
console.log(data.modules[key][last]);
return {
charge: data.modules[key][last].charge,
chargeHistory: data.modules[key].map((val, i) => ({name: i, value: val.charge})),
chargeHistory: data.modules[key].map((val, i) => ({name: val.timestamp.toDate(), value: val.charge})),
name: key,
temp: data.modules[key][last].temp,
tempHistory: data.modules[key].map((val, i) => ({name: i, value: val.temp}))