mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #914
This commit is contained in:
parent
02c2636b7d
commit
141225c980
@ -86,7 +86,9 @@ class HomeController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param Request $request
|
||||||
*
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function displayDebug(Request $request)
|
public function displayDebug(Request $request)
|
||||||
{
|
{
|
||||||
@ -193,6 +195,7 @@ class HomeController extends Controller
|
|||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$accounts = $repository->getAccountsById($frontPage->data);
|
$accounts = $repository->getAccountsById($frontPage->data);
|
||||||
$showDeps = Preferences::get('showDepositsFrontpage', false)->data;
|
$showDeps = Preferences::get('showDepositsFrontpage', false)->data;
|
||||||
|
$today = new Carbon;
|
||||||
|
|
||||||
// zero bills? Hide some elements from view.
|
// zero bills? Hide some elements from view.
|
||||||
/** @var BillRepositoryInterface $billRepository */
|
/** @var BillRepositoryInterface $billRepository */
|
||||||
@ -208,7 +211,7 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
return view(
|
return view(
|
||||||
'index',
|
'index',
|
||||||
compact('count', 'subTitle', 'transactions', 'showDeps', 'billCount')
|
compact('count', 'subTitle', 'transactions', 'showDeps', 'billCount','start','end','today')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
67
public/js/ff/charts.js
vendored
67
public/js/ff/charts.js
vendored
@ -20,6 +20,9 @@
|
|||||||
/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart */
|
/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart */
|
||||||
var allCharts = {};
|
var allCharts = {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Make some colours:
|
Make some colours:
|
||||||
*/
|
*/
|
||||||
@ -58,6 +61,43 @@ Chart.defaults.global.responsive = true;
|
|||||||
Chart.defaults.global.maintainAspectRatio = false;
|
Chart.defaults.global.maintainAspectRatio = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chart line thing
|
||||||
|
*/
|
||||||
|
const verticalLinePlugin = {
|
||||||
|
getLinePosition: function (chart, pointIndex) {
|
||||||
|
const meta = chart.getDatasetMeta(0); // first dataset is used to discover X coordinate of a point
|
||||||
|
const data = meta.data;
|
||||||
|
return data[pointIndex]._model.x;
|
||||||
|
},
|
||||||
|
renderVerticalLine: function (chartInstance, pointIndex) {
|
||||||
|
const lineLeftOffset = this.getLinePosition(chartInstance, pointIndex);
|
||||||
|
const scale = chartInstance.scales['y-axis-0'];
|
||||||
|
const context = chartInstance.chart.ctx;
|
||||||
|
|
||||||
|
// render vertical line
|
||||||
|
context.beginPath();
|
||||||
|
context.strokeStyle = fillColors[3];
|
||||||
|
context.moveTo(lineLeftOffset, scale.top);
|
||||||
|
context.lineTo(lineLeftOffset, scale.bottom);
|
||||||
|
context.stroke();
|
||||||
|
|
||||||
|
// write label
|
||||||
|
context.fillStyle = "#444444";
|
||||||
|
context.textAlign = 'left';
|
||||||
|
context.fillText(todayText, lineLeftOffset, scale.top * 3); // (scale.bottom - scale.top) / 2 + scale.top
|
||||||
|
},
|
||||||
|
|
||||||
|
afterDatasetsDraw: function (chart, easing) {
|
||||||
|
if (chart.config.lineAtIndex) {
|
||||||
|
chart.config.lineAtIndex.forEach(pointIndex => this.renderVerticalLine(chart, pointIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Chart.plugins.register(verticalLinePlugin);
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
@ -89,7 +129,17 @@ function lineChart(URI, container) {
|
|||||||
var options = $.extend(true, {}, defaultChartOptions);
|
var options = $.extend(true, {}, defaultChartOptions);
|
||||||
var chartType = 'line';
|
var chartType = 'line';
|
||||||
|
|
||||||
drawAChart(URI, container, chartType, options, colorData);
|
drawAChart(URI, container, chartType, options, colorData, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lineChartWithDay(URI, container, today) {
|
||||||
|
"use strict";
|
||||||
|
console.log('in lineChartWithDay');
|
||||||
|
var colorData = true;
|
||||||
|
var options = $.extend(true, {}, defaultChartOptions);
|
||||||
|
var chartType = 'line';
|
||||||
|
|
||||||
|
drawAChart(URI, container, chartType, options, colorData, today);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,8 +298,9 @@ function pieChart(URI, container) {
|
|||||||
* @param chartType
|
* @param chartType
|
||||||
* @param options
|
* @param options
|
||||||
* @param colorData
|
* @param colorData
|
||||||
|
* @param today
|
||||||
*/
|
*/
|
||||||
function drawAChart(URI, container, chartType, options, colorData) {
|
function drawAChart(URI, container, chartType, options, colorData, today) {
|
||||||
var containerObj = $('#' + container);
|
var containerObj = $('#' + container);
|
||||||
if (containerObj.length === 0) {
|
if (containerObj.length === 0) {
|
||||||
return;
|
return;
|
||||||
@ -286,11 +337,17 @@ function drawAChart(URI, container, chartType, options, colorData) {
|
|||||||
} else {
|
} else {
|
||||||
// new chart!
|
// new chart!
|
||||||
var ctx = document.getElementById(container).getContext("2d");
|
var ctx = document.getElementById(container).getContext("2d");
|
||||||
allCharts[container] = new Chart(ctx, {
|
var chartOpts = {
|
||||||
type: chartType,
|
type: chartType,
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options,
|
||||||
});
|
lineAtIndex: []
|
||||||
|
};
|
||||||
|
if(today >= 0) {
|
||||||
|
chartOpts.lineAtIndex.push(today-1);
|
||||||
|
console.log('push opt');
|
||||||
|
}
|
||||||
|
allCharts[container] = new Chart(ctx, chartOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
|
7
public/js/ff/index.js
vendored
7
public/js/ff/index.js
vendored
@ -29,7 +29,12 @@ $(function () {
|
|||||||
|
|
||||||
function drawChart() {
|
function drawChart() {
|
||||||
"use strict";
|
"use strict";
|
||||||
lineChart(accountFrontpageUri, 'accounts-chart');
|
if(today >= 0) {
|
||||||
|
lineChartWithDay(accountFrontpageUri, 'accounts-chart', today);
|
||||||
|
} else {
|
||||||
|
lineChart(accountFrontpageUri, 'accounts-chart');
|
||||||
|
}
|
||||||
|
|
||||||
if (billCount > 0) {
|
if (billCount > 0) {
|
||||||
pieChart('chart/bill/frontpage', 'bills-chart');
|
pieChart('chart/bill/frontpage', 'bills-chart');
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
// general stuff:
|
// general stuff:
|
||||||
|
'language_incomplete' => 'Incomplete translation',
|
||||||
'close' => 'Close',
|
'close' => 'Close',
|
||||||
'actions' => 'Actions',
|
'actions' => 'Actions',
|
||||||
'edit' => 'Edit',
|
'edit' => 'Edit',
|
||||||
'delete' => 'Delete',
|
'delete' => 'Delete',
|
||||||
'welcomeBack' => 'What\'s playing?',
|
'welcomeBack' => 'What\'s playing?',
|
||||||
'everything' => 'Everything',
|
'everything' => 'Everything',
|
||||||
|
'today' => 'today',
|
||||||
'customRange' => 'Custom range',
|
'customRange' => 'Custom range',
|
||||||
'apply' => 'Apply',
|
'apply' => 'Apply',
|
||||||
'select_date' => 'Select date..',
|
'select_date' => 'Select date..',
|
||||||
|
@ -142,6 +142,14 @@
|
|||||||
var accountRevenueUri = '{{ route('chart.account.revenue') }}';
|
var accountRevenueUri = '{{ route('chart.account.revenue') }}';
|
||||||
var accountExpenseUri = '{{ route('chart.account.expense') }}';
|
var accountExpenseUri = '{{ route('chart.account.expense') }}';
|
||||||
var piggyInfoUri = '{{ route('json.fp.piggy-banks') }}';
|
var piggyInfoUri = '{{ route('json.fp.piggy-banks') }}';
|
||||||
|
var todayText = ' {{ 'today'|_ }}';
|
||||||
|
|
||||||
|
<!-- render vertical line with text "today" -->
|
||||||
|
{% if start.lte(today) and end.gte(today) %}
|
||||||
|
var today = {{ today.day }};
|
||||||
|
{% else %}
|
||||||
|
var today = -1;
|
||||||
|
{% endif %}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user