Implemented a forgotten chart.

This commit is contained in:
James Cole
2015-06-28 12:41:58 +02:00
parent a8d60388ba
commit 60254dafd7
7 changed files with 65 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
/** /**
* @codeCoverageIgnore
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end

View File

@@ -8,9 +8,11 @@
namespace FireflyIII\Generator\Chart\Bill; namespace FireflyIII\Generator\Chart\Bill;
use Config;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences;
/** /**
* Class ChartJsBillChartGenerator * Class ChartJsBillChartGenerator
@@ -79,5 +81,45 @@ class ChartJsBillChartGenerator implements BillChartGenerator
*/ */
public function single(Bill $bill, Collection $entries) public function single(Bill $bill, Collection $entries)
{ {
// language:
$language = Preferences::get('language', 'en')->data;
$format = Config::get('firefly.month.' . $language);
$data = [
'count' => 3,
'labels' => [],
'datasets' => [],
];
// dataset: max amount
// dataset: min amount
// dataset: actual amount
$minAmount = [];
$maxAmount = [];
$actualAmount = [];
foreach ($entries as $entry) {
$data['labels'][] = $entry->date->formatLocalized($format);
$minAmount[] = round($bill->amount_min, 2);
$maxAmount[] = round($bill->amount_max, 2);
$actualAmount[] = round($entry->amount, 2);
}
$data['datasets'][] = [
'label' => trans('firefly.minAmount'),
'data' => $minAmount,
];
$data['datasets'][] = [
'label' => trans('firefly.billEntry'),
'data' => $actualAmount,
];
$data['datasets'][] = [
'label' => trans('firefly.maxAmount'),
'data' => $maxAmount,
];
$data['count'] = count($data['datasets']);
return $data;
} }
} }

View File

@@ -44,6 +44,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
} }
/** /**
* @codeCoverageIgnore
* @param Collection $entries * @param Collection $entries
* *
* @return array * @return array

View File

@@ -57,7 +57,7 @@ class BillController extends Controller
$cache->addProperty('bills'); $cache->addProperty('bills');
$cache->addProperty('frontpage'); $cache->addProperty('frontpage');
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore // return Response::json($cache->get()); // @codeCoverageIgnore
} }
$bills = $repository->getActiveBills(); $bills = $repository->getActiveBills();

View File

@@ -1,6 +1,6 @@
/* global comboChart, billID */ /* global comboChart, billID */
$(document).ready(function () { $(function () {
"use strict"; "use strict";
if (typeof(comboChart) === 'function' && typeof(billID) !== 'undefined') { if (typeof(comboChart) === 'function' && typeof(billID) !== 'undefined') {
comboChart('chart/bill/' + billID, 'bill-overview'); comboChart('chart/bill/' + billID, 'bill-overview');

View File

@@ -100,7 +100,7 @@ var defaultColumnOptions = {
scaleLabel: "<%= '" + currencySymbol + " ' + Number(value).toFixed(2).replace('.', ',') %>", scaleLabel: "<%= '" + currencySymbol + " ' + Number(value).toFixed(2).replace('.', ',') %>",
tooltipFillColor: "rgba(0,0,0,0.5)", tooltipFillColor: "rgba(0,0,0,0.5)",
tooltipTemplate: "<%if (label){%><%=label%>: <%}%>" + currencySymbol + " <%= value %>", tooltipTemplate: "<%if (label){%><%=label%>: <%}%>" + currencySymbol + " <%= value %>",
multiTooltipTemplate: "<%=datasetLabel%>: "+currencySymbol+" <%= Number(value).toFixed(2).replace('.', ',') %>" multiTooltipTemplate: "<%=datasetLabel%>: " + currencySymbol + " <%= Number(value).toFixed(2).replace('.', ',') %>"
}; };
var defaultStackedColumnOptions = { var defaultStackedColumnOptions = {
@@ -113,7 +113,7 @@ var defaultStackedColumnOptions = {
responsive: true, responsive: true,
scaleLabel: "<%= '" + currencySymbol + " ' + Number(value).toFixed(2).replace('.', ',') %>", scaleLabel: "<%= '" + currencySymbol + " ' + Number(value).toFixed(2).replace('.', ',') %>",
tooltipFillColor: "rgba(0,0,0,0.5)", tooltipFillColor: "rgba(0,0,0,0.5)",
multiTooltipTemplate: "<%=datasetLabel%>: "+currencySymbol+" <%= Number(value).toFixed(2).replace('.', ',') %>" multiTooltipTemplate: "<%=datasetLabel%>: " + currencySymbol + " <%= Number(value).toFixed(2).replace('.', ',') %>"
}; };
@@ -265,7 +265,8 @@ function stackedColumnChart(URL, container, options) {
*/ */
function comboChart(URL, container, options) { function comboChart(URL, container, options) {
"use strict"; "use strict";
console.log('no impl for comboChart'); columnChart(URL, container, options);
} }
/** /**

View File

@@ -85,7 +85,13 @@
<h3 class="box-title">Chart</h3> <h3 class="box-title">Chart</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{% if Config.get('firefly.chart') == 'google' %}
<div id="bill-overview"></div> <div id="bill-overview"></div>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
<canvas id="bill-overview" style="width:100%;height:400px;"></canvas>
{% endif %}
</div> </div>
</div> </div>
</div> </div>