Added chart value formatting
This commit is contained in:
		@@ -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"
 | 
			
		||||
 
 | 
			
		||||
@@ -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`
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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}))}));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user