diff --git a/src/main/java/de/deadlocker8/budgetmaster/charts/DefaultCharts.java b/src/main/java/de/deadlocker8/budgetmaster/charts/DefaultCharts.java index d9e88460df56e9f83e592faf7c00c2d2222faffb..b4327eea950b63122b0c434545089fddaf3f2204 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/charts/DefaultCharts.java +++ b/src/main/java/de/deadlocker8/budgetmaster/charts/DefaultCharts.java @@ -10,12 +10,17 @@ import java.util.List; public class DefaultCharts { - private static final Chart CHART_TEST = new Chart("charts.default.accountsum", getChartFromFile("charts/AccountSumPerDay.js"), ChartType.DEFAULT); + private static final Chart CHART_ACCOUNT_SUM_PER_DAY = new Chart("charts.default.accountSumPerDay", getChartFromFile("charts/AccountSumPerDay.js"), ChartType.DEFAULT); + private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BAR = new Chart("charts.default.incomesAndExpendituresPerMonthBar", getChartFromFile("charts/IncomesAndExpendituresPerMonthBar.js"), ChartType.DEFAULT); + private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_LINE = new Chart("charts.default.incomesAndExpendituresPerMonthLine", getChartFromFile("charts/IncomesAndExpendituresPerMonthLine.js"), ChartType.DEFAULT); + public static List<Chart> getDefaultCharts() { List<Chart> charts = new ArrayList<>(); - charts.add(CHART_TEST); + charts.add(CHART_ACCOUNT_SUM_PER_DAY); + charts.add(CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BAR); + charts.add(CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_LINE); charts.sort(Comparator.comparing(Chart::getName)); return charts; diff --git a/src/main/resources/charts/IncomesAndExpendituresPerMonthBar.js b/src/main/resources/charts/IncomesAndExpendituresPerMonthBar.js new file mode 100644 index 0000000000000000000000000000000000000000..78dd9897058ff5876c20f952649e297e089d1eba --- /dev/null +++ b/src/main/resources/charts/IncomesAndExpendituresPerMonthBar.js @@ -0,0 +1,95 @@ +/* This list will be dynamically filled with all the transactions between + * the start and and date you select on the "Show Chart" page + * and filtered according to your specified filter. + * An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki: + * https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts + */ +var transactionData = []; + +// Note: All variables starting with "localized" are only available inside default charts. +moment.locale(localizedLocale); + +var dates = []; +var incomes = []; +var expenditures = []; + +for(var i = 0; i < transactionData.length; i++) +{ + var transaction = transactionData[i]; + + // create new sums if month is not already in list + var date = moment(transaction.date).startOf('month').format('MMMM YY'); + if(!dates.includes(date)) + { + dates.push(date); + incomes.push(0); + expenditures.push(0); + } + + // add to income or expenditure sum + var amount = transaction.amount; + if(amount > 0) + { + var lastIndex = incomes.length - 1; + incomes[lastIndex] = incomes[lastIndex] + amount; + } else + { + var lastIndex = expenditures.length - 1; + expenditures[lastIndex] = expenditures[lastIndex] + Math.abs(amount); + } +} + +// convert all income sums to decimal +incomes.forEach(function(value, index) +{ + this[index] = value / 100; +}, incomes); + +// convert all expenditure sums to decimal +expenditures.forEach(function(value, index) +{ + this[index] = value / 100; +}, expenditures); + +// Prepare your chart settings here (mandatory) +var plotlyData = [ + { + x: dates, + y: incomes, + type: 'bar', + name: localizedData['traceName1'] + }, + { + x: dates, + y: expenditures, + type: 'bar', + name: localizedData['traceName2'] + } +]; + +// Add your Plotly layout settings here (optional) +var plotlyLayout = { + title: { + text: localizedTitle + }, + yaxis: { + title: localizedData['axisY'] + localizedCurrency, + rangemode: 'tozero', + tickformat: '.2f', + showline: true + }, + xaxis: { + tickformat: '%d.%m.%y' + } +}; + +// Add your Plotly configuration settings here (optional) +var plotlyConfig = { + showSendToCloud: false, + displaylogo: false, + showLink: false, + responsive: true +}; + +// Don't touch this line +Plotly.newPlot('chart-canvas', plotlyData, plotlyLayout, plotlyConfig); \ No newline at end of file diff --git a/src/main/resources/charts/IncomesAndExpendituresPerMonthLine.js b/src/main/resources/charts/IncomesAndExpendituresPerMonthLine.js new file mode 100644 index 0000000000000000000000000000000000000000..2574b8a89822d247ce8463549f68e7df8499f05d --- /dev/null +++ b/src/main/resources/charts/IncomesAndExpendituresPerMonthLine.js @@ -0,0 +1,95 @@ +/* This list will be dynamically filled with all the transactions between + * the start and and date you select on the "Show Chart" page + * and filtered according to your specified filter. + * An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki: + * https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts + */ +var transactionData = []; + +// Note: All variables starting with "localized" are only available inside default charts. +moment.locale(localizedLocale); + +var dates = []; +var incomes = []; +var expenditures = []; + +for(var i = 0; i < transactionData.length; i++) +{ + var transaction = transactionData[i]; + + // create new sums if month is not already in list + var date = moment(transaction.date).startOf('month').format('MMMM YY'); + if(!dates.includes(date)) + { + dates.push(date); + incomes.push(0); + expenditures.push(0); + } + + // add to income or expenditure sum + var amount = transaction.amount; + if(amount > 0) + { + var lastIndex = incomes.length - 1; + incomes[lastIndex] = incomes[lastIndex] + amount; + } else + { + var lastIndex = expenditures.length - 1; + expenditures[lastIndex] = expenditures[lastIndex] + Math.abs(amount); + } +} + +// convert all income sums to decimal +incomes.forEach(function(value, index) +{ + this[index] = value / 100; +}, incomes); + +// convert all expenditure sums to decimal +expenditures.forEach(function(value, index) +{ + this[index] = value / 100; +}, expenditures); + +// Prepare your chart settings here (mandatory) +var plotlyData = [ + { + x: dates, + y: incomes, + type: 'line', + name: localizedData['traceName1'] + }, + { + x: dates, + y: expenditures, + type: 'line', + name: localizedData['traceName2'] + } +]; + +// Add your Plotly layout settings here (optional) +var plotlyLayout = { + title: { + text: localizedTitle + }, + yaxis: { + title: localizedData['axisY'] + localizedCurrency, + rangemode: 'tozero', + tickformat: '.2f', + showline: true + }, + xaxis: { + tickformat: '%d.%m.%y' + } +}; + +// Add your Plotly configuration settings here (optional) +var plotlyConfig = { + showSendToCloud: false, + displaylogo: false, + showLink: false, + responsive: true +}; + +// Don't touch this line +Plotly.newPlot('chart-canvas', plotlyData, plotlyLayout, plotlyConfig); \ No newline at end of file diff --git a/src/main/resources/languages/_de.properties b/src/main/resources/languages/_de.properties index 4e0d0b0dc60225f27cb0e3576111c1b7510563ff..13e25359acdf50dc407c758c31dc42aa0b5adc64 100644 --- a/src/main/resources/languages/_de.properties +++ b/src/main/resources/languages/_de.properties @@ -1,3 +1,5 @@ +locale=de + # DEFAULT credits=Verwendete Schriftarten: Roboto<br>Verwendete Bibliotheken:<br>spring-boot-starter-parent 1.5.13<br>spring-boot-devtools 1.5.13<br>spring-boot-starter-web 1.5.13<br>spring-boot-starter-test 1.5.13<br>spring-boot-starter-data-jpa 1.5.13<br>spring-boot-starter-security 1.5.13<br>h2 1.4.197<br>joda-time 2.9.9<br>usertype.core 5.0.0.GA<br>maven-surefire-plugin 2.12<br>launch4j-maven-plugin 1.7.21<br>gson 2.8.1<br>jquery 3.3.1<br>materialize 1.0.0<br>fontawesome 5.0.10<br>Google Material Icons<br>Spectrum Colorpicker 1.8.0<br>SortableJS 1.8.1<br>jlibs 2.0.4 folder=Deadlocker/BudgetMaster @@ -328,7 +330,10 @@ hotkeys.search.key=s charts.default.accountSumPerDay=Kontostand pro Tag charts.default.accountSumPerDay.localization='{"axisY": "Summe in "'} charts.default.categories=Eingaben/Ausgaben nach Kategorien -charts.default.month=Eingaben/Ausgaben pro Monat +charts.default.incomesAndExpendituresPerMonthBar=Eingaben/Ausgaben pro Monat (Balkendiagramm) +charts.default.incomesAndExpendituresPerMonthBar.localization='{"axisY": "Summe in ", "traceName1": "Einnahmen", "traceName2": "Ausgaben"'} +charts.default.incomesAndExpendituresPerMonthLine=Eingaben/Ausgaben pro Monat (Liniendiagramm) +charts.default.incomesAndExpendituresPerMonthLine.localization='{"axisY": "Summe in ", "traceName1": "Einnahmen", "traceName2": "Ausgaben"'} charts.default.categoryBudget=Verbrauch nach Kategorien chart.new.label.name=Name diff --git a/src/main/resources/languages/_en.properties b/src/main/resources/languages/_en.properties index a6a9d46d97607f445de2408a6f04f5c97d94d78b..cadf523fd69791386eebcfe1a8f708b519c73716 100644 --- a/src/main/resources/languages/_en.properties +++ b/src/main/resources/languages/_en.properties @@ -1,3 +1,5 @@ +locale=en + # DEFAULT credits=Fonts used: Roboto<br>Libraries used:<br>spring-boot-starter-parent 1.5.13<br>spring-boot-devtools 1.5.13<br>spring-boot-starter-web 1.5.13<br>spring-boot-starter-test 1.5.13<br>spring-boot-starter-data-jpa 1.5.13<br>spring-boot-starter-security 1.5.13<br>h2 1.4.197<br>joda-time 2.9.9<br>usertype.core 5.0.0.GA<br>maven-surefire-plugin 2.12<br>launch4j-maven-plugin 1.7.21<br>gson 2.8.1<br>jquery 3.3.1<br>materialize 1.0.0<br>fontawesome 5.0.10<br>Google Material Icons<br>Spectrum Colorpicker 1.8.0<br>SortableJS 1.8.1<br>jlibs 2.0.4 folder=Deadlocker/BudgetMaster @@ -328,7 +330,10 @@ hotkeys.search.key=s charts.default.accountSumPerDay=Account sum per day charts.default.accountSumPerDay.localization='{"axisY": "Sum in "'} charts.default.categories=Incomes/Expenditures per category -charts.default.month=Income/Expenditures per month +charts.default.incomesAndExpendituresPerMonthBar=Incomes/Expenditures per month (Bar chart) +charts.default.incomesAndExpendituresPerMonthBar.localization='{"axisY": "Sum in ", "traceName1": "Incomes", "traceName2": "Expenditures"'} +charts.default.incomesAndExpendituresPerMonthLine=Incomes/Expenditures per month (Line chart) +charts.default.incomesAndExpendituresPerMonthLine.localization='{"axisY": "Sum in ", "traceName1": "Incomes", "traceName2": "Expenditures"'} charts.default.categoryBudget=Consumption by categories chart.new.label.name=Name