diff --git a/src/app/app.html b/src/app/app.html index 05085a5..f2f6c60 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -16,10 +16,10 @@ Einstellungen - - - - + + + + @@ -27,7 +27,7 @@ - + diff --git a/src/app/app.ts b/src/app/app.ts index e82070b..19a876f 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,4 +1,4 @@ -import { Component, signal } from '@angular/core'; +import {Component, signal, ViewChild} from '@angular/core'; import {RouterLink, RouterOutlet} from '@angular/router'; import {MatToolbar} from '@angular/material/toolbar'; import {MatIcon} from '@angular/material/icon'; @@ -6,7 +6,7 @@ import {MatButton, MatIconButton} from '@angular/material/button'; import {MatDrawer, MatDrawerContainer, MatDrawerContent} from '@angular/material/sidenav'; import {StationList} from './station-list/station-list'; import {WettterOverview} from './components/wettter-overview/wettter-overview'; -import {TemperatureComponent} from './components/diagrams/temperature/temperature'; +import {TemperatureComponent, TimeResolution} from './components/diagrams/temperature/temperature'; import {Diagrams} from './components/diagrams/diagrams'; @Component({ @@ -17,4 +17,11 @@ import {Diagrams} from './components/diagrams/diagrams'; }) export class App { protected readonly title = signal('WetterHub'); + @ViewChild('diagrams') diagrams?: Diagrams + + onChangeTimeInterval(timeResolution: TimeResolution) { + if(this.diagrams) { + this.diagrams.updateTimeResolution(timeResolution); + } + } } diff --git a/src/app/components/diagrams/diagrams.ts b/src/app/components/diagrams/diagrams.ts index 33fb4b6..5110632 100644 --- a/src/app/components/diagrams/diagrams.ts +++ b/src/app/components/diagrams/diagrams.ts @@ -47,12 +47,28 @@ export class Diagrams { return map[this.timeResolution]?.toISOString(); } + get measurementResolution() { + const map: Record = { + '24h': 'hourly', + '7d': 'daily', + '30d': 'daily', + '1Y': 'monthly', + 'All': 'yearly' + }; + return map[this.timeResolution] + } + + public updateTimeResolution(timeResolution: TimeResolution) { + this.timeResolution = timeResolution; + this.fetchMeasurements() + } + fetchMeasurements() { const stationIds = this.activeStations.map(s => s.id); const now = new Date().toISOString(); this.api.getMeasurementsMeasurementsGet( - stationIds, undefined, this.timeIntervalStart, now, this.resolution + stationIds, undefined, this.timeIntervalStart, now, this.measurementResolution ).subscribe(data => { this.measurements = data; this.buildCharts();