2018-08-08 16:45:31 +03:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { of as observableOf, Observable } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ProfitBarAnimationChartService {
|
|
|
|
|
|
|
|
|
|
private data: any;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.data = {
|
|
|
|
|
firstLine: this.getDataForFirstLine(),
|
|
|
|
|
secondLine: this.getDataForSecondLine(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDataForFirstLine(): number[] {
|
|
|
|
|
return this.createEmptyArray(100)
|
|
|
|
|
.map((_, index) => {
|
|
|
|
|
const oneFifth = index / 5;
|
|
|
|
|
|
|
|
|
|
return (Math.sin(oneFifth) * (oneFifth - 10) + index / 6) * 5;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDataForSecondLine(): number[] {
|
|
|
|
|
return this.createEmptyArray(100)
|
|
|
|
|
.map((_, index) => {
|
|
|
|
|
const oneFifth = index / 5;
|
|
|
|
|
|
|
|
|
|
return (Math.cos(oneFifth) * (oneFifth - 10) + index / 6) * 5;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createEmptyArray(nPoints: number) {
|
|
|
|
|
return Array.from(Array(nPoints));
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 16:17:20 +03:00
|
|
|
getChartData(): Observable<{ firstLine: number[]; secondLine: number[]; }> {
|
2018-08-08 16:45:31 +03:00
|
|
|
return observableOf(this.data);
|
|
|
|
|
}
|
|
|
|
|
}
|