2015-06-27 13:52:06 -05:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2015-06-27 13:52:06 -05:00
|
|
|
namespace FireflyIII\Generator\Chart\PiggyBank;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-01 00:22:48 -05:00
|
|
|
* Class ChartJsPiggyBankChartGenerator
|
2015-06-27 13:52:06 -05:00
|
|
|
*
|
|
|
|
* @package FireflyIII\Generator\Chart\PiggyBank
|
|
|
|
*/
|
2016-01-28 14:50:20 -06:00
|
|
|
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGeneratorInterface
|
2015-06-27 13:52:06 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Collection $set
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-02-18 00:21:48 -06:00
|
|
|
public function history(Collection $set): array
|
2015-06-27 13:52:06 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
// language:
|
2016-01-27 11:31:44 -06:00
|
|
|
$format = (string)trans('config.month_and_day');
|
2015-06-27 13:52:06 -05:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'count' => 1,
|
|
|
|
'labels' => [],
|
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => 'Diff',
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
|
|
|
],
|
2015-06-27 13:52:06 -05:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$sum = '0';
|
2016-05-01 00:09:58 -05:00
|
|
|
foreach ($set as $key => $value) {
|
|
|
|
$date = new Carbon($key);
|
|
|
|
$sum = bcadd($sum, $value);
|
2015-06-27 13:52:06 -05:00
|
|
|
$data['labels'][] = $date->formatLocalized($format);
|
|
|
|
$data['datasets'][0]['data'][] = round($sum, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2015-06-28 01:24:12 -05:00
|
|
|
}
|