I am working on a component that uses an injected service to fetch static mock data. I want to enhance this by adding the capability to generate new data at various intervals and send this time series data to the component as it is created.
However, I'm struggling to find a way to achieve this.
The only thing I am certain of is that the data object for the component must remain immutable.
If anyone could point me in the right direction, I would greatly appreciate it. At one point, I considered using a service worker, but that seemed excessive for a simple mock-up. In the future, this service will interact with data sources over the internet using streams. But for now, I just need to simulate a stream of data flowing from the service to the component for UI development and prototyping purposes.
plotter.component.ts:
import { Component, OnInit } from '@angular/core';
import { MockDataService } from '../../services/mock-data/mock-data.service';
@Component({
selector: 'app-plotter',
templateUrl: './plotter.component.html',
styleUrls: ['./plotter.component.css']
})
export class PlotterComponent implements OnInit {
single: any[];
multi: any[];
// rt needs to be an immutable object array
// rt needs to be updated with data from MockDataService
rt: any[];
view: any[] = [700, 400];
// options
showXAxis = true;
showYAxis = true;
gradient = false;
showLegend = true;
showXAxisLabel = true;
xAxisLabel = 'Country';
showYAxisLabel = true;
yAxisLabel = 'Population';
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};
autoScale = true;
constructor(private mockDataService: MockDataService) {
this.single = mockDataService.getSingle();
this.multi = mockDataService.getMulti();
}
ngOnInit() {
}
onSelect(event) {
console.log(event);
}
}
mock-data.service.ts
import { Injectable } from '@angular/core';
import { single, multi } from '../../mock-data/plot-data';
@Injectable({
providedIn: 'root'
})
export class MockDataService {
constructor() { }
getSingle() {
return single;
}
getMulti() {
return multi;
}
// Generate sine wave data here
sineWave(pAmplitude, pFrequency) {
}
}