Added chart value formatting
This commit is contained in:
parent
781d6c3f42
commit
48aa6da181
@ -11,6 +11,7 @@
|
|||||||
[yAxis]="true"
|
[yAxis]="true"
|
||||||
[yScaleMin]="0"
|
[yScaleMin]="0"
|
||||||
[yScaleMax]="100"
|
[yScaleMax]="100"
|
||||||
|
[yAxisTickFormatting]="percentFormat"
|
||||||
legendTitle="Charge"
|
legendTitle="Charge"
|
||||||
[legend]="!app.mobile"
|
[legend]="!app.mobile"
|
||||||
[roundDomains]="true"
|
[roundDomains]="true"
|
||||||
@ -23,6 +24,7 @@
|
|||||||
[yAxis]="true"
|
[yAxis]="true"
|
||||||
[yScaleMin]="0"
|
[yScaleMin]="0"
|
||||||
[yScaleMax]="80"
|
[yScaleMax]="80"
|
||||||
|
[yAxisTickFormatting]="tempFormat"
|
||||||
legendTitle="Temperature"
|
legendTitle="Temperature"
|
||||||
[legend]="!app.mobile"
|
[legend]="!app.mobile"
|
||||||
[roundDomains]="true"
|
[roundDomains]="true"
|
||||||
|
@ -27,7 +27,11 @@ export class BatteryComponent implements OnInit {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
round(num: number) {
|
percentFormat(val) {
|
||||||
return Math.round(num * 10) / 10;
|
return `${val} %`
|
||||||
|
}
|
||||||
|
|
||||||
|
tempFormat(val) {
|
||||||
|
return `${val} °C`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,6 @@ export class BatteryService {
|
|||||||
batteries = [];
|
batteries = [];
|
||||||
last: Date;
|
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() {
|
get icon() {
|
||||||
if (!this.batteries.length) return 'battery_alert';
|
if (!this.batteries.length) return 'battery_alert';
|
||||||
if (!this.last) return 'battery_warn';
|
if (!this.last) return 'battery_warn';
|
||||||
@ -54,4 +40,18 @@ export class BatteryService {
|
|||||||
|
|
||||||
return temp;
|
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}))}));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user