mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-02-22 16:04:08 +01:00
With this change all components, which used data services before, now use abstract classes of service interfaces, mock services extend interface services, CoreModule contains code to inject a needed implementation of some service.
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { PeriodsService } from './periods.service';
|
|
import { ProfitChart, ProfitChartData } from '../data/profit-chart';
|
|
|
|
@Injectable()
|
|
export class ProfitChartService extends ProfitChartData {
|
|
|
|
private year = [
|
|
'2012',
|
|
'2013',
|
|
'2014',
|
|
'2015',
|
|
'2016',
|
|
'2017',
|
|
'2018',
|
|
];
|
|
|
|
private data = { };
|
|
|
|
constructor(private period: PeriodsService) {
|
|
super();
|
|
this.data = {
|
|
week: this.getDataForWeekPeriod(),
|
|
month: this.getDataForMonthPeriod(),
|
|
year: this.getDataForYearPeriod(),
|
|
};
|
|
}
|
|
|
|
private getDataForWeekPeriod(): ProfitChart {
|
|
const nPoint = this.period.getWeeks().length;
|
|
|
|
return {
|
|
chartLabel: this.period.getWeeks(),
|
|
data: [
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
],
|
|
};
|
|
}
|
|
|
|
private getDataForMonthPeriod(): ProfitChart {
|
|
const nPoint = this.period.getMonths().length;
|
|
|
|
return {
|
|
chartLabel: this.period.getMonths(),
|
|
data: [
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
],
|
|
};
|
|
}
|
|
|
|
private getDataForYearPeriod(): ProfitChart {
|
|
const nPoint = this.year.length;
|
|
|
|
return {
|
|
chartLabel: this.year,
|
|
data: [
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
this.getRandomData(nPoint),
|
|
],
|
|
};
|
|
}
|
|
|
|
private getRandomData(nPoints: number): number[] {
|
|
return Array.from(Array(nPoints)).map(() => {
|
|
return Math.round(Math.random() * 500);
|
|
});
|
|
}
|
|
|
|
getProfitChartData(period: string): ProfitChart {
|
|
return this.data[period];
|
|
}
|
|
}
|