Charts "columnChart" and "stackedColumnChart" now support beforeDraw() which will check the data to see if the chart should be drawn. This cleans up the front page for new users and empty months.

This commit is contained in:
James Cole
2016-01-29 13:35:08 +01:00
parent 3d82afd4e6
commit 9ccb67db8a
2 changed files with 55 additions and 12 deletions

View File

@@ -34,14 +34,37 @@ function drawChart() {
"use strict";
areaChart('chart/account/frontpage', 'accounts-chart');
pieChart('chart/bill/frontpage', 'bills-chart');
stackedColumnChart('chart/budget/frontpage', 'budgets-chart');
columnChart('chart/category/frontpage', 'categories-chart');
columnChart('chart/account/expense', 'expense-accounts-chart');
stackedColumnChart('chart/budget/frontpage', 'budgets-chart', {beforeDraw: beforeDrawIsEmpty});
columnChart('chart/category/frontpage', 'categories-chart', {beforeDraw: beforeDrawIsEmpty});
columnChart('chart/account/expense', 'expense-accounts-chart', {beforeDraw: beforeDrawIsEmpty});
getBoxAmounts();
}
/**
* Removes a chart container if there is nothing for the chart to draw.
*
* @param data
* @param options
* @returns {boolean}
*/
function beforeDrawIsEmpty(data, options) {
"use strict";
// check if chart holds data.
if (data.labels.length === 0) {
// remove the chart container + parent
console.log(options.container + ' appears empty. Removed.');
$('#' + options.container).parent().parent().remove();
// return false so script stops.
return false;
}
return true;
}
function getBoxAmounts() {
"use strict";
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];