Files
firefly-iii/public/js/ff/reports/default/year.js

137 lines
4.5 KiB
JavaScript
Raw Normal View History

2015-12-12 17:51:07 +01:00
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
2016-06-27 16:11:49 +02:00
var chartDrawn;
var budgetChart;
$(function () {
"use strict";
2016-06-27 16:11:49 +02:00
chartDrawn = false;
drawChart();
// click open the top X income list:
$('#showIncomes').click(showIncomes);
// click open the top X expense list:
$('#showExpenses').click(showExpenses);
});
2015-05-08 17:13:49 +02:00
function drawChart() {
2015-05-24 20:41:14 +02:00
"use strict";
2016-02-18 10:04:53 +01:00
lineChart('chart/report/net-worth/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'net-worth');
2015-12-14 20:37:38 +01:00
columnChart('chart/report/in-out/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-chart');
columnChart('chart/report/in-out-sum/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-sum-chart');
2016-04-24 20:00:20 +02:00
2016-06-16 20:52:30 +02:00
$('.budget-chart-activate').on('click', clickBudgetChart);
2015-03-10 17:26:31 +01:00
}
2015-05-16 07:28:58 +02:00
2016-06-16 20:52:30 +02:00
function clickBudgetChart(e) {
"use strict";
var link = $(e.target);
var budgetId = link.data('budget');
2016-06-27 16:11:49 +02:00
var URL = 'chart/budget/period/' + budgetId + '/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds;
var container = 'budget_chart';
// if chart drawn is false, draw the first one, then
// set to true
if (chartDrawn == false) {
// do new chart:
$.getJSON(URL).done(function (data) {
console.log('Will draw new columnChart(' + URL + ')');
var ctx = document.getElementById(container).getContext("2d");
var newData = {};
newData.datasets = [];
for (var i = 0; i < data.count; i++) {
newData.labels = data.labels;
var dataset = data.datasets[i];
dataset.backgroundColor = fillColors[i];
newData.datasets.push(dataset);
}
// completely new chart.
budgetChart = new Chart(ctx, {
type: 'bar',
data: data,
options: defaultColumnOptions
});
}).fail(function () {
$('#' + container).addClass('general-chart-error');
});
console.log('URL for column chart : ' + URL);
chartDrawn = true;
} else {
console.log('Will now handle remove data and add new!');
$.getJSON(URL).done(function (data) {
console.log('Will draw updated columnChart(' + URL + ')');
var newData = {};
newData.datasets = [];
for (var i = 0; i < data.count; i++) {
newData.labels = data.labels;
var dataset = data.datasets[i];
dataset.backgroundColor = fillColors[i];
newData.datasets.push(dataset);
}
// update the chart
console.log('Now update chart thing.');
budgetChart.data.datasets = newData.datasets;
budgetChart.update();
}).fail(function () {
$('#' + container).addClass('general-chart-error');
});
}
// if chart drawn is true, add new data to existing chart.
// console.log('Budget id is ' + budgetId);
// $('#budget_chart').empty();
// columnChart('chart/budget/period/' + budgetId + '/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'budget_chart');
2016-06-16 20:52:30 +02:00
return false;
}
2015-05-16 07:28:58 +02:00
function showIncomes() {
"use strict";
2015-05-17 18:03:16 +02:00
if (incomeRestShow) {
2015-05-16 07:28:58 +02:00
// hide everything, make button say "show"
$('#showIncomes').text(showTheRest);
$('.incomesCollapsed').removeClass('in').addClass('out');
// toggle:
incomeRestShow = false;
} else {
// show everything, make button say "hide".
$('#showIncomes').text(hideTheRest);
$('.incomesCollapsed').removeClass('out').addClass('in');
// toggle:
incomeRestShow = true;
}
return false;
}
function showExpenses() {
2015-05-24 20:41:14 +02:00
"use strict";
2015-05-17 18:03:16 +02:00
if (expenseRestShow) {
2015-05-16 07:28:58 +02:00
// hide everything, make button say "show"
$('#showExpenses').text(showTheRestExpense);
$('.expenseCollapsed').removeClass('in').addClass('out');
// toggle:
expenseRestShow = false;
} else {
// show everything, make button say "hide".
$('#showExpenses').text(hideTheRestExpense);
$('.expenseCollapsed').removeClass('out').addClass('in');
// toggle:
expenseRestShow = true;
}
return false;
}