firefly-iii/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php

49 lines
1.1 KiB
PHP
Raw Normal View History

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;
/**
* Class ChartJsPiggyBankChartGenerator
2015-06-27 13:52:06 -05:00
*
* @package FireflyIII\Generator\Chart\PiggyBank
*/
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:
$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
}