mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-16 10:58:32 -05:00
Switch to combined chart
This commit is contained in:
@@ -15,7 +15,7 @@ const routes: Routes = [
|
|||||||
component: WeatherCurrentComponent
|
component: WeatherCurrentComponent
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'weather-charts/:type',
|
path: 'weather-charts',
|
||||||
component: WeatherChartsComponent
|
component: WeatherChartsComponent
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,31 +34,13 @@
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<mat-list-item>
|
<a routerLink="/weather-charts" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" mat-list-item>
|
||||||
<mat-icon matListIcon class="nav-icon">
|
<mat-icon matListIcon class="nav-icon">
|
||||||
multiline_chart
|
multiline_chart
|
||||||
</mat-icon>
|
</mat-icon>
|
||||||
<span class="nav-caption">
|
<span class="nav-caption">
|
||||||
Weather Charts
|
Weather Charts
|
||||||
</span>
|
</span>
|
||||||
</mat-list-item>
|
|
||||||
|
|
||||||
<a routerLink="/weather-charts/temperature" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" mat-list-item>
|
|
||||||
<span class="nav-sub-item">
|
|
||||||
Temperature
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a routerLink="/weather-charts/humidity" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" mat-list-item>
|
|
||||||
<span class="nav-sub-item">
|
|
||||||
Humidity
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a routerLink="/weather-charts/pressure" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" mat-list-item>
|
|
||||||
<span class="nav-sub-item">
|
|
||||||
Pressure
|
|
||||||
</span>
|
|
||||||
</a>
|
</a>
|
||||||
</mat-nav-list>
|
</mat-nav-list>
|
||||||
</mat-sidenav>
|
</mat-sidenav>
|
||||||
|
|||||||
@@ -29,5 +29,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-sub-item {
|
.nav-sub-item {
|
||||||
padding-left: 40px !important;
|
padding-left: 40px !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#chart {
|
#chart {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50px;
|
top: 50px;
|
||||||
bottom: 0;
|
bottom: 50px;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { Chart } from 'angular-highcharts';
|
import { Chart } from 'angular-highcharts';
|
||||||
import { SeriesLineOptions } from 'highcharts';
|
import { SeriesLineOptions } from 'highcharts';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { WeatherValue } from '../../../models/weather/weather-value';
|
import { WeatherReadingGrouped } from '../../../models/weather/weather-reading-grouped';
|
||||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@@ -22,7 +22,6 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
public chart: Chart;
|
public chart: Chart;
|
||||||
|
|
||||||
private loading = true;
|
private loading = true;
|
||||||
private chartType: string;
|
|
||||||
|
|
||||||
public timeSpanItems: { [value: number]: string } = {};
|
public timeSpanItems: { [value: number]: string } = {};
|
||||||
public selectedTimeSpan: TimeSpan = TimeSpan.Last24Hours;
|
public selectedTimeSpan: TimeSpan = TimeSpan.Last24Hours;
|
||||||
@@ -38,22 +37,6 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
this.route.params.subscribe(params => {
|
this.route.params.subscribe(params => {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
const chartType = params.type;
|
|
||||||
|
|
||||||
switch (chartType) {
|
|
||||||
case 'temperature':
|
|
||||||
this.chartType = 'PressureTemperature';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'humidity':
|
|
||||||
this.chartType = 'Humidity';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'pressure':
|
|
||||||
this.chartType = 'Pressure';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loadChart();
|
this.loadChart();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -107,49 +90,92 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
const startString = moment(start).toISOString();
|
const startString = moment(start).toISOString();
|
||||||
const endString = moment(end).toISOString();
|
const endString = moment(end).toISOString();
|
||||||
|
|
||||||
const request = this.httpClient.get<WeatherValue[]>(`http://172.23.10.3/api/weather/readings/value-history?weatherValueType=${this.chartType}&start=${startString}&end=${endString}&bucketMinutes=5`);
|
const request = this.httpClient.get<WeatherReadingGrouped[]>(`http://172.23.10.3/api/weather/readings/history-grouped?start=${startString}&end=${endString}&bucketMinutes=5`);
|
||||||
|
|
||||||
request.subscribe(data => {
|
request.subscribe(data => {
|
||||||
const array = [];
|
const seriesData: Array<SeriesLineOptions> = [];
|
||||||
|
|
||||||
let divisor = 1;
|
seriesData.push({ name: 'Temperature', data: [], yAxis: 0, tooltip: { valueSuffix: '°F' } } as SeriesLineOptions);
|
||||||
|
seriesData.push({ name: 'Pressure', data: [], yAxis: 1, tooltip: { valueSuffix: '"' } } as SeriesLineOptions);
|
||||||
|
seriesData.push({ name: 'Humidity', data: [], yAxis: 2, tooltip: { valueSuffix: '%' } } as SeriesLineOptions);
|
||||||
|
seriesData.push({ name: 'Light', data: [], yAxis: 2, tooltip: { valueSuffix: '%' } } as SeriesLineOptions);
|
||||||
|
|
||||||
if (this.chartType === 'Pressure') {
|
data.forEach(dataElement => {
|
||||||
divisor = 100;
|
const date = Date.parse(dataElement.bucket);
|
||||||
}
|
seriesData[0].data.push([date, dataElement.averagePressureTemperature]);
|
||||||
|
seriesData[1].data.push([date, dataElement.averagePressure / 33.864]);
|
||||||
data.forEach(dataElement => array.push([Date.parse(dataElement.bucket), dataElement.averageValue / divisor]));
|
seriesData[2].data.push([date, dataElement.averageHumidity]);
|
||||||
|
seriesData[3].data.push([date, dataElement.averageLightLevel]);
|
||||||
|
});
|
||||||
|
|
||||||
this.chart = new Chart({
|
this.chart = new Chart({
|
||||||
chart: {
|
chart: {
|
||||||
type: 'line'
|
type: 'line'
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
text: 'Linechart'
|
text: ''
|
||||||
},
|
},
|
||||||
credits: {
|
credits: {
|
||||||
enabled: true
|
enabled: true
|
||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
},
|
dateTimeLabelFormats: {
|
||||||
yAxis: {
|
millisecond: '%H:%M:%S.%L',
|
||||||
labels: {
|
second: '%H:%M:%S',
|
||||||
format: '{value:.2f}'
|
minute: '%H:%M',
|
||||||
|
hour: '%l:%M %P',
|
||||||
|
day: '%b %e',
|
||||||
|
week: '%e. %b',
|
||||||
|
month: '%b \'%y',
|
||||||
|
year: '%Y'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
yAxis: [
|
||||||
|
{
|
||||||
|
labels: {
|
||||||
|
format: '{value:.2f}°F',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
text: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
labels: {
|
||||||
|
format: '{value:.2f}"'
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
text: ''
|
||||||
|
},
|
||||||
|
opposite: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visible: false,
|
||||||
|
min: 0,
|
||||||
|
max: 100
|
||||||
|
}
|
||||||
|
],
|
||||||
time: {
|
time: {
|
||||||
useUTC: false
|
useUTC: false
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
valueDecimals: 2
|
valueDecimals: 2,
|
||||||
|
shared: true,
|
||||||
|
dateTimeLabelFormats: {
|
||||||
|
day: '%A, %b %e, %Y',
|
||||||
|
hour: '%A, %b %e, %H:%M',
|
||||||
|
millisecond: '%A, %b %e, %H:%M:%S.%L',
|
||||||
|
minute: '%A, %b %e, %l:%M %P',
|
||||||
|
month: '%B %Y',
|
||||||
|
second: '%A, %b %e, %H:%M:%S',
|
||||||
|
week: 'Week from %A, %b %e, %Y',
|
||||||
|
year: '%Y'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
series: [
|
series: seriesData,
|
||||||
{
|
legend: {
|
||||||
name: 'Line 1',
|
enabled: true
|
||||||
data: array
|
}
|
||||||
} as SeriesLineOptions
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
Pressure
|
Pressure
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ (latestReading.Pressure / 100).toFixed(2) }} mbar
|
{{ (latestReading.Pressure / 33.864 / 100).toFixed(2) }}"
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export class WeatherReadingGrouped {
|
||||||
|
bucket: string;
|
||||||
|
averagePressureTemperature: number;
|
||||||
|
averagePressure: number;
|
||||||
|
averageLightLevel: number;
|
||||||
|
averageHumidity: number;
|
||||||
|
averageHumidityTemperature: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user