New charts (slight variations of previous charts)

This commit is contained in:
James Cole
2015-12-14 21:11:26 +01:00
parent cf4a8c6204
commit 29dc122ad3
2 changed files with 81 additions and 1 deletions

View File

@@ -49,6 +49,39 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
return $data;
}
/**
* Same as above but other translations.
*
* @param Collection $entries
*
* @return array
*/
public function multiYearInOut(Collection $entries)
{
$data = [
'count' => 2,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.income'),
'data' => []
],
[
'label' => trans('firefly.expenses'),
'data' => []
]
],
];
foreach ($entries as $entry) {
$data['labels'][] = $entry[0]->formatLocalized('%Y');
$data['datasets'][0]['data'][] = round($entry[1], 2);
$data['datasets'][1]['data'][] = round($entry[2], 2);
}
return $data;
}
/**
* @param string $income
* @param string $expense
@@ -80,4 +113,35 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
return $data;
}
/**
* @param string $income
* @param string $expense
* @param int $count
*
* @return array
*/
public function multiYearInOutSummarized($income, $expense, $count)
{
$data = [
'count' => 2,
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
'datasets' => [
[
'label' => trans('firefly.income'),
'data' => []
],
[
'label' => trans('firefly.expenses'),
'data' => []
]
],
];
$data['datasets'][0]['data'][] = round($income, 2);
$data['datasets'][1]['data'][] = round( $expense, 2);
$data['datasets'][0]['data'][] = round(($income / $count), 2);
$data['datasets'][1]['data'][] = round(( $expense / $count), 2);
return $data;
}
}

View File

@@ -12,12 +12,19 @@ use Illuminate\Support\Collection;
interface ReportChartGenerator
{
/**
* @param Collection $entries
*
* @return array
*/
public function yearInOut(Collection $entries);
/**
* @param Collection $entries
*
* @return array
*/
public function yearInOut(Collection $entries);
public function multiYearInOut(Collection $entries);
/**
* @param string $income
@@ -28,4 +35,13 @@ interface ReportChartGenerator
*/
public function yearInOutSummarized($income, $expense, $count);
/**
* @param string $income
* @param string $expense
* @param int $count
*
* @return array
*/
public function multiYearInOutSummarized($income, $expense, $count);
}