2016-10-25 18:53:54 +02:00
|
|
|
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
|
2015-12-04 06:56:59 +01:00
|
|
|
|
2016-06-27 16:11:49 +02:00
|
|
|
var chartDrawn;
|
|
|
|
var budgetChart;
|
2015-06-27 16:00:50 +02:00
|
|
|
$(function () {
|
|
|
|
"use strict";
|
2016-06-27 16:11:49 +02:00
|
|
|
chartDrawn = false;
|
2015-08-01 07:22:48 +02:00
|
|
|
drawChart();
|
2015-12-03 14:52:10 +01:00
|
|
|
|
2015-06-27 16:00:50 +02:00
|
|
|
});
|
2015-03-04 20:47:00 +01:00
|
|
|
|
|
|
|
|
2015-05-08 17:13:49 +02:00
|
|
|
function drawChart() {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2015-03-04 20:47:00 +01:00
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-16 07:28:58 +02:00
|
|
|
return false;
|
2015-12-03 14:52:10 +01:00
|
|
|
}
|