Files
firefly-iii/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php

108 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2016-05-20 11:59:54 +02:00
/**
* ChartJsAccountChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-02-05 12:08:25 +01:00
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Account;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
/**
* Class ChartJsAccountChartGenerator
*
* @package FireflyIII\Generator\Chart\Account
*/
class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
{
2015-08-01 07:04:41 +02:00
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
2016-02-18 07:21:48 +01:00
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end): array
2015-08-01 07:04:41 +02:00
{
$data = [
2015-12-18 16:38:50 +01:00
'count' => 1,
'labels' => [], 'datasets' => [[
'label' => trans('firefly.spent'),
'data' => []]]];
2015-08-01 07:04:41 +02:00
foreach ($accounts as $account) {
2015-08-02 07:41:47 +02:00
if ($account->difference > 0) {
2015-08-01 07:04:41 +02:00
$data['labels'][] = $account->name;
2015-08-02 07:41:47 +02:00
$data['datasets'][0]['data'][] = $account->difference;
2015-08-01 07:04:41 +02:00
}
}
return $data;
}
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
2016-02-18 07:21:48 +01:00
public function frontpage(Collection $accounts, Carbon $start, Carbon $end): array
{
// language:
$format = (string)trans('config.month_and_day');
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
$current = clone $start;
while ($current <= $end) {
$data['labels'][] = $current->formatLocalized($format);
$current->addDay();
}
foreach ($accounts as $account) {
2016-05-13 17:22:24 +02:00
$data['datasets'][] = [
'label' => $account->name,
'fillColor' => 'rgba(220,220,220,0.2)',
'strokeColor' => 'rgba(220,220,220,1)',
'pointColor' => 'rgba(220,220,220,1)',
'pointStrokeColor' => '#fff',
'pointHighlightFill' => '#fff',
'pointHighlightStroke' => 'rgba(220,220,220,1)',
2016-05-13 17:22:24 +02:00
'data' => $account->balances,
];
}
2015-06-28 16:20:14 +02:00
$data['count'] = count($data['datasets']);
return $data;
}
/**
* @param Account $account
2016-05-13 17:22:24 +02:00
* @param array $labels
* @param array $dataSet
*
* @return array
*/
2016-05-13 17:22:24 +02:00
public function single(Account $account, array $labels, array $dataSet): array
{
2016-05-15 18:36:40 +02:00
$data = [
2015-06-27 17:38:16 +02:00
'count' => 1,
2016-05-13 17:22:24 +02:00
'labels' => $labels,
2015-06-27 17:38:16 +02:00
'datasets' => [
[
'label' => $account->name,
2016-05-13 17:22:24 +02:00
'data' => $dataSet,
],
2015-06-27 17:38:16 +02:00
],
];
2016-05-15 18:36:40 +02:00
2015-06-27 17:38:16 +02:00
return $data;
}
2015-08-16 20:26:11 +02:00
2015-06-28 08:24:12 +02:00
}