Skip to content

Firefly III: a personal finances manager

Clean up some javascript, small fix for the test reporter

James Colee6cfe040b51a
diff --git a/.travis.yml b/.travis.yml
index 9620d44551..5eb9cd293a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,6 +18,6 @@ script:
- php vendor/bin/codecept run --coverage --coverage-xml
after_script:
- - cp tests/output/coverage.xml build/logs/clover.xml
+ - cp -v tests/_output/coverage.xml build/logs/clover.xml
- php vendor/bin/coveralls
- vendor/bin/test-reporter
\ No newline at end of file
diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js
index 4bf7cdf1a8..92d1067fa4 100644
--- a/public/assets/javascript/firefly/gcharts.js
+++ b/public/assets/javascript/firefly/gcharts.js
@@ -1,7 +1,8 @@
+var google = google || {};
google.load('visualization', '1.1', {'packages': ['corechart', 'bar', 'sankey', 'table']});
-function googleLineChart(URL, container, options) {
- if ($('#' + container).length == 1) {
+function googleChart(chartType, URL, container, options) {
+ if ($('#' + container).length === 1) {
$.getJSON(URL).success(function (data) {
/*
Get the data from the JSON
@@ -16,19 +17,45 @@ function googleLineChart(URL, container, options) {
groupingSymbol: '.',
prefix: currencyCode + ' '
});
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ for (var i = 1; i < gdata.getNumberOfColumns(); i++) {
money.format(gdata, i);
}
/*
Create a new google charts object.
*/
- var chart = new google.visualization.LineChart(document.getElementById(container));
+ var chart = false
+ var options = false;
+ if (chartType === 'line') {
+ chart = new google.visualization.LineChart(document.getElementById(container));
+ options = options || defaultLineChartOptions;
+ }
+ if (chartType === 'column') {
+ chart = new google.charts.Bar(document.getElementById(container));
+ options = options || defaultColumnChartOptions;
+ }
+ if (chartType === 'pie') {
+ chart = new google.visualization.PieChart(document.getElementById(container));
+ options = options || defaultPieChartOptions;
+ }
+ if (chartType === 'bar') {
+ chart = new google.charts.Bar(document.getElementById(container));
+ options = options || defaultBarChartOptions;
+ }
+ if (chartType === 'stackedColumn') {
+ chart = new google.visualization.ColumnChart(document.getElementById(container));
+ options = options || defaultStackedColumnChartOptions;
+ }
+ if (chartType === 'combo') {
+ chart = new google.visualization.ComboChart(document.getElementById(container));
+ options = options || defaultComboChartOptions;
+ }
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultLineChartOptions);
+ if (chart === false) {
+ alert('Cannot draw chart of type "' + chartType + '".');
+ } else {
+ chart.draw(gdata, options);
+ }
}).fail(function () {
$('#' + container).addClass('google-chart-error');
@@ -38,189 +65,27 @@ function googleLineChart(URL, container, options) {
}
}
-function googleBarChart(URL, container, options) {
- if ($('#' + container).length == 1) {
- $.getJSON(URL).success(function (data) {
- /*
- Get the data from the JSON
- */
- gdata = new google.visualization.DataTable(data);
-
- /*
- Format as money
- */
- var money = new google.visualization.NumberFormat({
- decimalSymbol: ',',
- groupingSymbol: '.',
- prefix: currencyCode + ' '
- });
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
- money.format(gdata, i);
- }
-
- /*
- Create a new google charts object.
- */
- var chart = new google.charts.Bar(document.getElementById(container));
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultBarChartOptions);
+function googleLineChart(URL, container, options) {
+ return googleChart('line', URL, container, options);
+}
- }).fail(function () {
- $('#' + container).addClass('google-chart-error');
- });
- } else {
- console.log('No container found called "' + container + '"');
- }
+function googleBarChart(URL, container, options) {
+ return googleChart('bar', URL, container, options);
}
function googleColumnChart(URL, container, options) {
- if ($('#' + container).length == 1) {
- $.getJSON(URL).success(function (data) {
- /*
- Get the data from the JSON
- */
- gdata = new google.visualization.DataTable(data);
-
- /*
- Format as money
- */
- var money = new google.visualization.NumberFormat({
- decimalSymbol: ',',
- groupingSymbol: '.',
- prefix: currencyCode + ' '
- });
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
- money.format(gdata, i);
- }
-
- /*
- Create a new google charts object.
- */
- var chart = new google.charts.Bar(document.getElementById(container));
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultColumnChartOptions);
-
- }).fail(function () {
- $('#' + container).addClass('google-chart-error');
- });
- } else {
- console.log('No container found called "' + container + '"');
- }
+ return googleChart('column', URL, container, options);
}
function googleStackedColumnChart(URL, container, options) {
- if ($('#' + container).length == 1) {
- $.getJSON(URL).success(function (data) {
- /*
- Get the data from the JSON
- */
- gdata = new google.visualization.DataTable(data);
-
- /*
- Format as money
- */
- var money = new google.visualization.NumberFormat({
- decimalSymbol: ',',
- groupingSymbol: '.',
- prefix: currencyCode + ' '
- });
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
- money.format(gdata, i);
- }
-
- /*
- Create a new google charts object.
- */
- var chart = new google.visualization.ColumnChart(document.getElementById(container));
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultStackedColumnChartOptions);
-
- }).fail(function () {
- $('#' + container).addClass('google-chart-error');
- });
- } else {
- console.log('No container found called "' + container + '"');
- }
+ return googleChart('stackedColumn', URL, container, options);
}
function googleComboChart(URL, container, options) {
- if ($('#' + container).length == 1) {
- $.getJSON(URL).success(function (data) {
- /*
- Get the data from the JSON
- */
- gdata = new google.visualization.DataTable(data);
-
- /*
- Format as money
- */
- var money = new google.visualization.NumberFormat({
- decimalSymbol: ',',
- groupingSymbol: '.',
- prefix: currencyCode + ' '
- });
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
- money.format(gdata, i);
- }
-
- /*
- Create a new google charts object.
- */
- var chart = new google.visualization.ComboChart(document.getElementById(container));
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultComboChartOptions);
-
- }).fail(function () {
- $('#' + container).addClass('google-chart-error');
- });
- } else {
- console.log('No container found called "' + container + '"');
- }
+ return googleChart('combo', URL, container, options);
}
function googlePieChart(URL, container, options) {
- if ($('#' + container).length == 1) {
- $.getJSON(URL).success(function (data) {
- /*
- Get the data from the JSON
- */
- gdata = new google.visualization.DataTable(data);
-
- /*
- Format as money
- */
- var money = new google.visualization.NumberFormat({
- decimalSymbol: ',',
- groupingSymbol: '.',
- prefix: currencyCode + ' '
- });
- for (i = 1; i < gdata.getNumberOfColumns(); i++) {
- money.format(gdata, i);
- }
-
- /*
- Create a new google charts object.
- */
- var chart = new google.visualization.PieChart(document.getElementById(container));
-
- /*
- Draw it:
- */
- chart.draw(gdata, options || defaultPieChartOptions);
-
- }).fail(function () {
- $('#' + container).addClass('google-chart-error');
- });
- } else {
- console.log('No container found called "' + container + '"');
- }
+ return googleChart('pie', URL, container, options);
}