Last active
December 5, 2022 21:04
-
-
Save kagklis/44dee8580a4e16324ac1965688512095 to your computer and use it in GitHub Desktop.
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
export const INIT_LENGTH = 500; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class DataService { | |
private dataLengthSubject = new BehaviorSubject<number>(INIT_LENGTH); | |
private dataLength$ = this.dataLengthSubject.asObservable(); | |
public data$: Observable<ChartData> = this.dataLength$.pipe( | |
debounceTime(1_000), | |
map((n: number) => this.generateData(n)) | |
); | |
private generateData(n: number): ChartData { | |
return { | |
labels: [...Array(n).keys()], // x-axis labels | |
datasets: [ | |
{ | |
label: 'QX', | |
data: [...Array(n).keys()], | |
backgroundColor: 'orange' | |
}, | |
{ | |
label: 'QY', | |
data: [...Array(n).keys()].reverse(), | |
backgroundColor: 'green' | |
} | |
] | |
}; | |
} | |
public updateDataLength(value: number): void { | |
this.dataLengthSubject.next(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment