Added chart value formatting

This commit is contained in:
Zakary Timson 2018-11-16 12:39:38 -05:00
parent 781d6c3f42
commit 48aa6da181
3 changed files with 22 additions and 16 deletions

View File

@ -11,6 +11,7 @@
[yAxis]="true"
[yScaleMin]="0"
[yScaleMax]="100"
[yAxisTickFormatting]="percentFormat"
legendTitle="Charge"
[legend]="!app.mobile"
[roundDomains]="true"
@ -23,6 +24,7 @@
[yAxis]="true"
[yScaleMin]="0"
[yScaleMax]="80"
[yAxisTickFormatting]="tempFormat"
legendTitle="Temperature"
[legend]="!app.mobile"
[roundDomains]="true"

View File

@ -27,7 +27,11 @@ export class BatteryComponent implements OnInit {
}, 1000);
}
round(num: number) {
return Math.round(num * 10) / 10;
percentFormat(val) {
return `${val} %`
}
tempFormat(val) {
return `${val} °C`
}
}

View File

@ -13,20 +13,6 @@ export class BatteryService {
batteries = [];
last: Date;
constructor() {
this.firestore = firebaseApp.firestore();
this.firestore.settings({timestampsInSnapshots: true});
this.firestore.collection('Battery').doc('TEMP').onSnapshot(snap => {
this.last = new Date();
let data = snap.data();
this.batteries = Object.keys(data).map(key => ({name: key, history: data[key]}));
this.average = this.batteries.reduce((acc, battery) => acc + battery.history[0].percentage, 0) / this.batteries.length;
this.percentageData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: history.percentage * 100}))}));
this.temperatureData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: Math.round(history.temp * 10) / 10}))}));
});
}
get icon() {
if (!this.batteries.length) return 'battery_alert';
if (!this.last) return 'battery_warn';
@ -54,4 +40,18 @@ export class BatteryService {
return temp;
}
constructor() {
this.firestore = firebaseApp.firestore();
this.firestore.settings({timestampsInSnapshots: true});
this.firestore.collection('Battery').doc('TEMP').onSnapshot(snap => {
this.last = new Date();
let data = snap.data();
this.batteries = Object.keys(data).map(key => ({name: key, history: data[key]}));
this.average = this.batteries.reduce((acc, battery) => acc + battery.history[0].percentage, 0) / this.batteries.length;
this.percentageData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: history.percentage * 100}))}));
this.temperatureData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: Math.round(history.temp * 10) / 10}))}));
});
}
}