mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 14:58:40 +00:00
Final chart. First version.
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Config;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Preferences;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GooglePiggyBankChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||||
|
*/
|
||||||
|
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function history(Collection $set)
|
||||||
|
{
|
||||||
|
|
||||||
|
// language:
|
||||||
|
$language = Preferences::get('language', 'en')->data;
|
||||||
|
$format = Config::get('firefly.month.' . $language);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'count' => 1,
|
||||||
|
'labels' => [],
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => 'Diff',
|
||||||
|
'data' => []
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$sum = '0';
|
||||||
|
bcscale(2);
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$date = new Carbon($entry->date);
|
||||||
|
$sum = bcadd($sum, $entry->sum);
|
||||||
|
$data['labels'][] = $date->formatLocalized($format);
|
||||||
|
$data['datasets'][0]['data'][] = round($sum, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@@ -47,7 +47,7 @@ class PiggyBankController extends Controller
|
|||||||
$cache->addProperty('piggy-history');
|
$cache->addProperty('piggy-history');
|
||||||
$cache->addProperty($piggyBank->id);
|
$cache->addProperty($piggyBank->id);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
//return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Collection $set */
|
/** @var Collection $set */
|
||||||
|
@@ -104,8 +104,8 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
//$this->app->bind('FireflyIII\Generator\Chart\Category\CategoryChartGenerator', 'FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator');
|
//$this->app->bind('FireflyIII\Generator\Chart\Category\CategoryChartGenerator', 'FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator');
|
||||||
$this->app->bind('FireflyIII\Generator\Chart\Category\CategoryChartGenerator', 'FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator');
|
$this->app->bind('FireflyIII\Generator\Chart\Category\CategoryChartGenerator', 'FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator');
|
||||||
|
|
||||||
$this->app->bind('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator', 'FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator');
|
|
||||||
//$this->app->bind('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator', 'FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator');
|
//$this->app->bind('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator', 'FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator', 'FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator');
|
||||||
|
|
||||||
//$this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGenerator', 'FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator');
|
//$this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGenerator', 'FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator');
|
||||||
$this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGenerator', 'FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator');
|
$this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGenerator', 'FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator');
|
||||||
|
@@ -12,7 +12,12 @@
|
|||||||
<h3 class="box-title">{{ 'events'|_ }}</h3>
|
<h3 class="box-title">{{ 'events'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div id="piggy-bank-history"></div>
|
{% if Config.get('firefly.chart') == 'google' %}
|
||||||
|
<div id="piggy-bank-history"></div>
|
||||||
|
{% endif %}
|
||||||
|
{% if Config.get('firefly.chart') == 'chartjs' %}
|
||||||
|
<canvas id="piggy-bank-history" style="width:100%;height:400px;"></canvas>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user