Skip to content
Snippets Groups Projects
Commit 2e382373 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#585 - added new field "displayType" to chart class:

allows to categorize a default chart into display types (e.g. bar, pie, ...)
parent 48aabf0d
Branches
Tags
No related merge requests found
...@@ -26,12 +26,15 @@ public class Chart ...@@ -26,12 +26,15 @@ public class Chart
@Expose @Expose
private int version; private int version;
public Chart(String name, String script, ChartType type, int version) private ChartDisplayType displayType;
public Chart(String name, String script, ChartType type, int version, ChartDisplayType displayType)
{ {
this.name = name; this.name = name;
this.script = script; this.script = script;
this.type = type; this.type = type;
this.version = version; this.version = version;
this.displayType = displayType;
} }
public Chart() public Chart()
...@@ -88,6 +91,16 @@ public class Chart ...@@ -88,6 +91,16 @@ public class Chart
this.version = version; this.version = version;
} }
public ChartDisplayType getDisplayType()
{
return displayType;
}
public void setDisplayType(ChartDisplayType displayType)
{
this.displayType = displayType;
}
@Override @Override
public String toString() public String toString()
{ {
...@@ -97,6 +110,7 @@ public class Chart ...@@ -97,6 +110,7 @@ public class Chart
", script='" + script + '\'' + ", script='" + script + '\'' +
", type=" + type + ", type=" + type +
", version=" + version + ", version=" + version +
", displayType=" + displayType +
'}'; '}';
} }
...@@ -106,16 +120,12 @@ public class Chart ...@@ -106,16 +120,12 @@ public class Chart
if(this == o) return true; if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false; if(o == null || getClass() != o.getClass()) return false;
Chart chart = (Chart) o; Chart chart = (Chart) o;
return version == chart.version && return version == chart.version && Objects.equals(ID, chart.ID) && Objects.equals(name, chart.name) && Objects.equals(script, chart.script) && type == chart.type && displayType == chart.displayType;
Objects.equals(ID, chart.ID) &&
Objects.equals(name, chart.name) &&
Objects.equals(script, chart.script) &&
type == chart.type;
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hash(ID, name, script, type, version); return Objects.hash(ID, name, script, type, version, displayType);
} }
} }
\ No newline at end of file
package de.deadlocker8.budgetmaster.charts;
public enum ChartDisplayType
{
PIE,
BAR,
LINE,
CUSTOM
}
...@@ -71,6 +71,7 @@ public class ChartService implements Resettable, AccessAllEntities<Chart> ...@@ -71,6 +71,7 @@ public class ChartService implements Resettable, AccessAllEntities<Chart>
LOGGER.debug(MessageFormat.format("Update default chart ''{0}'' from version {1} to {2}", chart.getName(), currentChart.getVersion(), chart.getVersion())); LOGGER.debug(MessageFormat.format("Update default chart ''{0}'' from version {1} to {2}", chart.getName(), currentChart.getVersion(), chart.getVersion()));
currentChart.setVersion(chart.getVersion()); currentChart.setVersion(chart.getVersion());
currentChart.setScript(chart.getScript()); currentChart.setScript(chart.getScript());
currentChart.setDisplayType(chart.getDisplayType());
chartRepository.save(currentChart); chartRepository.save(currentChart);
} }
} }
......
...@@ -16,39 +16,39 @@ public class DefaultCharts ...@@ -16,39 +16,39 @@ public class DefaultCharts
public static final Chart CHART_DEFAULT = new Chart(null, public static final Chart CHART_DEFAULT = new Chart(null,
getChartFromFile("charts/Default.js"), getChartFromFile("charts/Default.js"),
ChartType.CUSTOM, -1); ChartType.CUSTOM, -1, ChartDisplayType.CUSTOM);
private static final Chart CHART_ACCOUNT_SUM_PER_DAY = new Chart("charts.default.accountSumPerDay", private static final Chart CHART_ACCOUNT_SUM_PER_DAY = new Chart("charts.default.accountSumPerDay",
getChartFromFile("charts/AccountSumPerDay.js"), getChartFromFile("charts/AccountSumPerDay.js"),
ChartType.DEFAULT, 7); ChartType.DEFAULT, 8, ChartDisplayType.LINE);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BAR = new Chart("charts.default.incomesAndExpendituresPerMonthBar", private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BAR = new Chart("charts.default.incomesAndExpendituresPerMonthBar",
getChartFromFile("charts/IncomesAndExpendituresPerMonthBar.js"), getChartFromFile("charts/IncomesAndExpendituresPerMonthBar.js"),
ChartType.DEFAULT, 7); ChartType.DEFAULT, 8, ChartDisplayType.BAR);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_LINE = new Chart("charts.default.incomesAndExpendituresPerMonthLine", private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_LINE = new Chart("charts.default.incomesAndExpendituresPerMonthLine",
getChartFromFile("charts/IncomesAndExpendituresPerMonthLine.js"), getChartFromFile("charts/IncomesAndExpendituresPerMonthLine.js"),
ChartType.DEFAULT, 7); ChartType.DEFAULT, 8, ChartDisplayType.LINE);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_BY_CATEGORY_BAR = new Chart("charts.default.incomesAndExpendituresByCategoryBar", private static final Chart CHART_INCOMES_AND_EXPENDITURES_BY_CATEGORY_BAR = new Chart("charts.default.incomesAndExpendituresByCategoryBar",
getChartFromFile("charts/IncomesAndExpendituresByCategoryBar.js"), getChartFromFile("charts/IncomesAndExpendituresByCategoryBar.js"),
ChartType.DEFAULT, 2); ChartType.DEFAULT, 3, ChartDisplayType.BAR);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_BY_CATEGORY_PIE = new Chart("charts.default.incomesAndExpendituresByCategoryPie", private static final Chart CHART_INCOMES_AND_EXPENDITURES_BY_CATEGORY_PIE = new Chart("charts.default.incomesAndExpendituresByCategoryPie",
getChartFromFile("charts/IncomesAndExpendituresByCategoryPie.js"), getChartFromFile("charts/IncomesAndExpendituresByCategoryPie.js"),
ChartType.DEFAULT, 3); ChartType.DEFAULT, 4, ChartDisplayType.PIE);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BY_CATEGORIES = new Chart("charts.default.incomesAndExpendituresPerMonthByCategories", private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_MONTH_BY_CATEGORIES = new Chart("charts.default.incomesAndExpendituresPerMonthByCategories",
getChartFromFile("charts/IncomesAndExpendituresPerMonthByCategories.js"), getChartFromFile("charts/IncomesAndExpendituresPerMonthByCategories.js"),
ChartType.DEFAULT, 17); ChartType.DEFAULT, 18, ChartDisplayType.BAR);
private static final Chart CHART_REST_PER_MONTH = new Chart("charts.default.restPerMonth", private static final Chart CHART_REST_PER_MONTH = new Chart("charts.default.restPerMonth",
getChartFromFile("charts/RestPerMonth.js"), getChartFromFile("charts/RestPerMonth.js"),
ChartType.DEFAULT, 3); ChartType.DEFAULT, 4, ChartDisplayType.BAR);
private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_YEAR_BAR = new Chart("charts.default.incomesAndExpendituresPerYearBar", private static final Chart CHART_INCOMES_AND_EXPENDITURES_PER_YEAR_BAR = new Chart("charts.default.incomesAndExpendituresPerYearBar",
getChartFromFile("charts/IncomesAndExpendituresPerYearBar.js"), getChartFromFile("charts/IncomesAndExpendituresPerYearBar.js"),
ChartType.DEFAULT, 2); ChartType.DEFAULT, 3, ChartDisplayType.BAR);
private DefaultCharts() private DefaultCharts()
{ {
......
package de.deadlocker8.budgetmaster.database.model.converter; package de.deadlocker8.budgetmaster.database.model.converter;
import de.deadlocker8.budgetmaster.charts.Chart; import de.deadlocker8.budgetmaster.charts.Chart;
import de.deadlocker8.budgetmaster.charts.ChartDisplayType;
import de.deadlocker8.budgetmaster.database.model.Converter; import de.deadlocker8.budgetmaster.database.model.Converter;
import de.deadlocker8.budgetmaster.database.model.v5.BackupChart_v5; import de.deadlocker8.budgetmaster.database.model.v5.BackupChart_v5;
...@@ -19,6 +20,7 @@ public class ChartConverter implements Converter<Chart, BackupChart_v5> ...@@ -19,6 +20,7 @@ public class ChartConverter implements Converter<Chart, BackupChart_v5>
chart.setType(backupChart.getType()); chart.setType(backupChart.getType());
chart.setVersion(backupChart.getVersion()); chart.setVersion(backupChart.getVersion());
chart.setScript(backupChart.getScript()); chart.setScript(backupChart.getScript());
chart.setDisplayType(ChartDisplayType.CUSTOM);
return chart; return chart;
} }
......
...@@ -9,10 +9,7 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; ...@@ -9,10 +9,7 @@ import de.deadlocker8.budgetmaster.accounts.AccountType;
import de.deadlocker8.budgetmaster.categories.Category; import de.deadlocker8.budgetmaster.categories.Category;
import de.deadlocker8.budgetmaster.categories.CategoryService; import de.deadlocker8.budgetmaster.categories.CategoryService;
import de.deadlocker8.budgetmaster.categories.CategoryType; import de.deadlocker8.budgetmaster.categories.CategoryType;
import de.deadlocker8.budgetmaster.charts.Chart; import de.deadlocker8.budgetmaster.charts.*;
import de.deadlocker8.budgetmaster.charts.ChartRepository;
import de.deadlocker8.budgetmaster.charts.ChartService;
import de.deadlocker8.budgetmaster.charts.ChartType;
import de.deadlocker8.budgetmaster.database.DatabaseParser; import de.deadlocker8.budgetmaster.database.DatabaseParser;
import de.deadlocker8.budgetmaster.database.DatabaseService; import de.deadlocker8.budgetmaster.database.DatabaseService;
import de.deadlocker8.budgetmaster.database.InternalDatabase; import de.deadlocker8.budgetmaster.database.InternalDatabase;
...@@ -244,6 +241,7 @@ class DatabaseExportTest ...@@ -244,6 +241,7 @@ class DatabaseExportTest
chart.setType(ChartType.CUSTOM); chart.setType(ChartType.CUSTOM);
chart.setVersion(7); chart.setVersion(7);
chart.setScript("/* This list will be dynamically filled with all the transactions between\r\n* the start and and date you select on the \"Show Chart\" page\r\n* and filtered according to your specified filter.\r\n* An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki:\r\n* https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts\r\n*/\r\nvar transactionData \u003d [];\r\n\r\n// Prepare your chart settings here (mandatory)\r\nvar plotlyData \u003d [{\r\n x: [],\r\n y: [],\r\n type: \u0027bar\u0027\r\n}];\r\n\r\n// Add your Plotly layout settings here (optional)\r\nvar plotlyLayout \u003d {};\r\n\r\n// Add your Plotly configuration settings here (optional)\r\nvar plotlyConfig \u003d {\r\n showSendToCloud: false,\r\n displaylogo: false,\r\n showLink: false,\r\n responsive: true\r\n};\r\n\r\n// Don\u0027t touch this line\r\nPlotly.newPlot(\"containerID\", plotlyData, plotlyLayout, plotlyConfig);\r\n"); chart.setScript("/* This list will be dynamically filled with all the transactions between\r\n* the start and and date you select on the \"Show Chart\" page\r\n* and filtered according to your specified filter.\r\n* An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki:\r\n* https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts\r\n*/\r\nvar transactionData \u003d [];\r\n\r\n// Prepare your chart settings here (mandatory)\r\nvar plotlyData \u003d [{\r\n x: [],\r\n y: [],\r\n type: \u0027bar\u0027\r\n}];\r\n\r\n// Add your Plotly layout settings here (optional)\r\nvar plotlyLayout \u003d {};\r\n\r\n// Add your Plotly configuration settings here (optional)\r\nvar plotlyConfig \u003d {\r\n showSendToCloud: false,\r\n displaylogo: false,\r\n showLink: false,\r\n responsive: true\r\n};\r\n\r\n// Don\u0027t touch this line\r\nPlotly.newPlot(\"containerID\", plotlyData, plotlyLayout, plotlyConfig);\r\n");
chart.setDisplayType(ChartDisplayType.CUSTOM);
ChartRepository chartRepositoryMock = Mockito.mock(ChartRepository.class); ChartRepository chartRepositoryMock = Mockito.mock(ChartRepository.class);
Mockito.when(chartRepositoryMock.findAllByType(Mockito.any())).thenReturn(List.of(chart)); Mockito.when(chartRepositoryMock.findAllByType(Mockito.any())).thenReturn(List.of(chart));
......
...@@ -5,6 +5,7 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; ...@@ -5,6 +5,7 @@ import de.deadlocker8.budgetmaster.accounts.AccountType;
import de.deadlocker8.budgetmaster.categories.Category; import de.deadlocker8.budgetmaster.categories.Category;
import de.deadlocker8.budgetmaster.categories.CategoryType; import de.deadlocker8.budgetmaster.categories.CategoryType;
import de.deadlocker8.budgetmaster.charts.Chart; import de.deadlocker8.budgetmaster.charts.Chart;
import de.deadlocker8.budgetmaster.charts.ChartDisplayType;
import de.deadlocker8.budgetmaster.charts.ChartType; import de.deadlocker8.budgetmaster.charts.ChartType;
import de.deadlocker8.budgetmaster.database.DatabaseParser_v7; import de.deadlocker8.budgetmaster.database.DatabaseParser_v7;
import de.deadlocker8.budgetmaster.database.InternalDatabase; import de.deadlocker8.budgetmaster.database.InternalDatabase;
...@@ -66,7 +67,7 @@ class DatabaseParser_v7_convertToInternalTest ...@@ -66,7 +67,7 @@ class DatabaseParser_v7_convertToInternalTest
DatabaseParser_v7 importer = new DatabaseParser_v7(json); DatabaseParser_v7 importer = new DatabaseParser_v7(json);
InternalDatabase database = importer.parseDatabaseFromJSON().convertToInternal(); InternalDatabase database = importer.parseDatabaseFromJSON().convertToInternal();
final Chart chart = new Chart("The best chart", "/* This list will be dynamically filled with all the transactions between\r\n* the start and and date you select on the \"Show Chart\" page\r\n* and filtered according to your specified filter.\r\n* An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki:\r\n* https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts\r\n*/\r\nvar transactionData \u003d [];\r\n\r\n// Prepare your chart settings here (mandatory)\r\nvar plotlyData \u003d [{\r\n x: [],\r\n y: [],\r\n type: \u0027bar\u0027\r\n}];\r\n\r\n// Add your Plotly layout settings here (optional)\r\nvar plotlyLayout \u003d {};\r\n\r\n// Add your Plotly configuration settings here (optional)\r\nvar plotlyConfig \u003d {\r\n showSendToCloud: false,\r\n displaylogo: false,\r\n showLink: false,\r\n responsive: true\r\n};\r\n\r\n// Don\u0027t touch this line\r\nPlotly.newPlot(\"containerID\", plotlyData, plotlyLayout, plotlyConfig);\r\n", ChartType.CUSTOM, 7); final Chart chart = new Chart("The best chart", "/* This list will be dynamically filled with all the transactions between\r\n* the start and and date you select on the \"Show Chart\" page\r\n* and filtered according to your specified filter.\r\n* An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki:\r\n* https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts\r\n*/\r\nvar transactionData \u003d [];\r\n\r\n// Prepare your chart settings here (mandatory)\r\nvar plotlyData \u003d [{\r\n x: [],\r\n y: [],\r\n type: \u0027bar\u0027\r\n}];\r\n\r\n// Add your Plotly layout settings here (optional)\r\nvar plotlyLayout \u003d {};\r\n\r\n// Add your Plotly configuration settings here (optional)\r\nvar plotlyConfig \u003d {\r\n showSendToCloud: false,\r\n displaylogo: false,\r\n showLink: false,\r\n responsive: true\r\n};\r\n\r\n// Don\u0027t touch this line\r\nPlotly.newPlot(\"containerID\", plotlyData, plotlyLayout, plotlyConfig);\r\n", ChartType.CUSTOM, 7, ChartDisplayType.CUSTOM);
chart.setID(9); chart.setID(9);
assertThat(database.getCharts()).hasSize(1) assertThat(database.getCharts()).hasSize(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment