-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add historical duration selection (#9)
Closes #10
- Loading branch information
1 parent
08a9123
commit 8c47a16
Showing
9 changed files
with
273 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type HistoricalStatsDuration = '1d' | '7d' | '30d' | ||
export function durationInDays(duration: HistoricalStatsDuration): number { | ||
switch (duration) { | ||
case '1d': return 1 | ||
case '7d': return 7 | ||
case '30d': return 30 | ||
} | ||
} | ||
export function durationInHours(duration: HistoricalStatsDuration): number { | ||
return durationInDays(duration) * 24 | ||
} | ||
export function getResolutionInMinutes(duration: HistoricalStatsDuration): number { | ||
switch (duration) { | ||
case '1d': return 15 | ||
case '7d': return 60 | ||
case '30d': return 60 * 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Injectable } from '@angular/core' | ||
import {BehaviorSubject, Observable} from 'rxjs' | ||
import {HistoricalStatsDuration} from './api/types/historical-stats-duration' | ||
import {distinctUntilChanged, shareReplay} from 'rxjs/operators' | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class HistoricalStatsDurationProvider { | ||
public get possibleDurations(): HistoricalStatsDuration[] { | ||
return ['1d', '7d', '30d'] | ||
} | ||
|
||
public get selectedDuration(): HistoricalStatsDuration { | ||
return this.selectedDurationRelay.getValue() | ||
} | ||
|
||
public set selectedDuration(duration: HistoricalStatsDuration) { | ||
this.selectedDurationRelay.next(duration) | ||
} | ||
|
||
public readonly selectedDuration$: Observable<HistoricalStatsDuration> | ||
private readonly selectedDurationRelay: BehaviorSubject<HistoricalStatsDuration> = new BehaviorSubject<HistoricalStatsDuration>('1d') | ||
|
||
public constructor() { | ||
this.selectedDuration$ = this.selectedDurationRelay.pipe(distinctUntilChanged(), shareReplay()) | ||
} | ||
} |
Oops, something went wrong.