diff --git a/src/consts/statistics.js b/src/consts/statistics.js index dfb4dd42..22b10c32 100644 --- a/src/consts/statistics.js +++ b/src/consts/statistics.js @@ -1,11 +1,22 @@ import datetime from './datetime.js'; -const allChartTypes = { +const allCategoricalChartTypes = { Pie: 0, Bar: 1 }; -const defaultChartType = allChartTypes.Pie; +const allCategoricalChartTypesArray = [ + { + name: 'Pie Chart', + type: allCategoricalChartTypes.Pie + }, + { + name: 'Bar Chart', + type: allCategoricalChartTypes.Bar + } +]; + +const defaultCategoricalChartType = allCategoricalChartTypes.Pie; const allChartDataTypes = { ExpenseByAccount: { @@ -71,8 +82,9 @@ const allSortingTypesArray = [ const defaultSortingType = allSortingTypes.Amount.type; export default { - allChartTypes: allChartTypes, - defaultChartType: defaultChartType, + allCategoricalChartTypes: allCategoricalChartTypes, + allCategoricalChartTypesArray: allCategoricalChartTypesArray, + defaultCategoricalChartType: defaultCategoricalChartType, allChartDataTypes: allChartDataTypes, defaultChartDataType: defaultChartDataType, defaultDataRangeType: datetime.allDateRanges.ThisMonth.type, diff --git a/src/lib/i18n.js b/src/lib/i18n.js index a80c1b8f..80b9dcec 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -808,6 +808,21 @@ function getAllAccountTypes(translateFn) { return allAccountTypes; } +function getAllCategoricalChartTypes(translateFn) { + const allChartTypes = []; + + for (let i = 0; i < statistics.allCategoricalChartTypesArray.length; i++) { + const chartType = statistics.allCategoricalChartTypesArray[i]; + + allChartTypes.push({ + type: chartType.type, + displayName: translateFn(chartType.name) + }); + } + + return allChartTypes; +} + function getAllStatisticsChartDataTypes(translateFn) { const allChartDataTypes = []; @@ -1351,6 +1366,7 @@ export function i18nFunctions(i18nGlobal) { getAllTimezoneTypesUsedForStatistics: (currentTimezone) => getAllTimezoneTypesUsedForStatistics(currentTimezone, i18nGlobal.t), getAllAccountCategories: () => getAllAccountCategories(i18nGlobal.t), getAllAccountTypes: () => getAllAccountTypes(i18nGlobal.t), + getAllCategoricalChartTypes: () => getAllCategoricalChartTypes(i18nGlobal.t), getAllStatisticsChartDataTypes: () => getAllStatisticsChartDataTypes(i18nGlobal.t), getAllStatisticsSortingTypes: () => getAllStatisticsSortingTypes(i18nGlobal.t), getAllTransactionEditScopeTypes: () => getAllTransactionEditScopeTypes(i18nGlobal.t), diff --git a/src/lib/settings.js b/src/lib/settings.js index ecd3ed4a..5a3ac1c6 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -21,7 +21,7 @@ const defaultSettings = { showTotalAmountInTransactionListPage: true, showAccountBalance: true, statistics: { - defaultChartType: statisticsConstants.defaultChartType, + defaultChartType: statisticsConstants.defaultCategoricalChartType, defaultChartDataType: statisticsConstants.defaultChartDataType, defaultDataRangeType: statisticsConstants.defaultDataRangeType, defaultTimezoneType: timezoneConstants.defaultTimezoneTypesUsedForStatistics, diff --git a/src/stores/statistics.js b/src/stores/statistics.js index a6fa2214..8e6c4b71 100644 --- a/src/stores/statistics.js +++ b/src/stores/statistics.js @@ -28,16 +28,16 @@ export const useStatisticsStore = defineStore('statistics', { dateType: statisticsConstants.defaultDataRangeType, startTime: 0, endTime: 0, - chartType: statisticsConstants.defaultChartType, + chartType: statisticsConstants.defaultCategoricalChartType, chartDataType: statisticsConstants.defaultChartDataType, filterAccountIds: {}, filterCategoryIds: {} }, - transactionStatisticsData: {}, + transactionCategoryStatisticsData: {}, transactionStatisticsStateInvalid: true }), getters: { - transactionStatisticsChartDataCategory(state) { + categoricalAnalysisChartDataCategory(state) { if (state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.ExpenseByAccount.type || state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByAccount.type || state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalAssets.type || @@ -52,8 +52,8 @@ export const useStatisticsStore = defineStore('statistics', { return ''; } }, - transactionStatistics(state) { - const statistics = state.transactionStatisticsData; + transactionCategoryStatisticsDataWithCategoryAndAccountInfo(state) { + const statistics = state.transactionCategoryStatisticsData; const finalStatistics = { startTime: statistics.startTime, endTime: statistics.endTime, @@ -114,8 +114,8 @@ export const useStatisticsStore = defineStore('statistics', { return finalStatistics; }, - statisticsItemsByTransactionStatisticsData(state) { - if (!state.transactionStatistics || !state.transactionStatistics.items) { + transactionCategoryTotalAmountAnalysisData(state) { + if (!state.transactionCategoryStatisticsDataWithCategoryAndAccountInfo || !state.transactionCategoryStatisticsDataWithCategoryAndAccountInfo.items) { return null; } @@ -123,8 +123,8 @@ export const useStatisticsStore = defineStore('statistics', { let totalAmount = 0; let totalNonNegativeAmount = 0; - for (let i = 0; i < state.transactionStatistics.items.length; i++) { - const item = state.transactionStatistics.items[i]; + for (let i = 0; i < state.transactionCategoryStatisticsDataWithCategoryAndAccountInfo.items.length; i++) { + const item = state.transactionCategoryStatisticsDataWithCategoryAndAccountInfo.items[i]; if (!item.primaryAccount || !item.account || !item.primaryCategory || !item.category) { continue; @@ -247,7 +247,7 @@ export const useStatisticsStore = defineStore('statistics', { items: allDataItems } }, - statisticsItemsByAccountsData(state) { + accountTotalAmountAnalysisData(state) { const userStore = useUserStore(); const accountsStore = useAccountsStore(); const exchangeRatesStore = useExchangeRatesStore(); @@ -323,7 +323,7 @@ export const useStatisticsStore = defineStore('statistics', { items: allDataItems } }, - statisticsData(state) { + categoricalAnalysisData(state) { let combinedData = { items: [], totalAmount: 0 @@ -335,10 +335,10 @@ export const useStatisticsStore = defineStore('statistics', { state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByAccount.type || state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByPrimaryCategory.type || state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeBySecondaryCategory.type) { - combinedData = state.statisticsItemsByTransactionStatisticsData; + combinedData = state.transactionCategoryTotalAmountAnalysisData; } else if (state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalAssets.type || state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalLiabilities.type) { - combinedData = state.statisticsItemsByAccountsData; + combinedData = state.accountTotalAmountAnalysisData; } const allStatisticsItems = []; @@ -410,11 +410,11 @@ export const useStatisticsStore = defineStore('statistics', { this.transactionStatisticsFilter.dateType = statisticsConstants.defaultDataRangeType; this.transactionStatisticsFilter.startTime = 0; this.transactionStatisticsFilter.endTime = 0; - this.transactionStatisticsFilter.chartType = statisticsConstants.defaultChartType; + this.transactionStatisticsFilter.chartType = statisticsConstants.defaultCategoricalChartType; this.transactionStatisticsFilter.chartDataType = statisticsConstants.defaultChartDataType; this.transactionStatisticsFilter.filterAccountIds = {}; this.transactionStatisticsFilter.filterCategoryIds = {}; - this.transactionStatisticsData = {}; + this.transactionCategoryStatisticsData = {}; this.transactionStatisticsStateInvalid = true; }, initTransactionStatisticsFilter(filter) { @@ -424,8 +424,8 @@ export const useStatisticsStore = defineStore('statistics', { let defaultChartType = settingsStore.appSettings.statistics.defaultChartType; - if (defaultChartType !== statisticsConstants.allChartTypes.Pie && defaultChartType !== statisticsConstants.allChartTypes.Bar) { - defaultChartType = statisticsConstants.defaultChartType; + if (defaultChartType !== statisticsConstants.allCategoricalChartTypes.Pie && defaultChartType !== statisticsConstants.allCategoricalChartTypes.Bar) { + defaultChartType = statisticsConstants.defaultCategoricalChartType; } let defaultChartDataType = settingsStore.appSettings.statistics.defaultChartDataType; @@ -481,7 +481,7 @@ export const useStatisticsStore = defineStore('statistics', { if (filter && isNumber(filter.chartType)) { this.transactionStatisticsFilter.chartType = filter.chartType; } else { - this.transactionStatisticsFilter.chartType = statisticsConstants.defaultChartType; + this.transactionStatisticsFilter.chartType = statisticsConstants.defaultCategoricalChartType; } if (filter && isNumber(filter.chartDataType)) { @@ -578,7 +578,7 @@ export const useStatisticsStore = defineStore('statistics', { return querys.join('&'); }, - loadTransactionStatistics({ force }) { + loadCategoricalAnalysis({ force }) { const self = this; const settingsStore = useSettingsStore(); @@ -599,12 +599,12 @@ export const useStatisticsStore = defineStore('statistics', { self.updateTransactionStatisticsInvalidState(false); } - if (force && data.result && isEquals(self.transactionStatisticsData, data.result)) { + if (force && data.result && isEquals(self.transactionCategoryStatisticsData, data.result)) { reject({ message: 'Data is up to date' }); return; } - self.transactionStatisticsData = data.result; + self.transactionCategoryStatisticsData = data.result; resolve(data.result); }).catch(error => { diff --git a/src/views/desktop/app/settings/tabs/AppStatisticsSettingTab.vue b/src/views/desktop/app/settings/tabs/AppStatisticsSettingTab.vue index a954508e..e15ec841 100644 --- a/src/views/desktop/app/settings/tabs/AppStatisticsSettingTab.vue +++ b/src/views/desktop/app/settings/tabs/AppStatisticsSettingTab.vue @@ -12,10 +12,7 @@ persistent-placeholder :label="$t('Default Chart Type')" :placeholder="$t('Default Chart Type')" - :items="[ - { type: allChartTypes.Pie, displayName: $t('Pie Chart') }, - { type: allChartTypes.Bar, displayName: $t('Bar Chart') } - ]" + :items="allCategoricalChartTypes" v-model="defaultChartType" /> @@ -99,8 +96,8 @@ export default { }, computed: { ...mapStores(useSettingsStore), - allChartTypes() { - return statisticsConstants.allChartTypes; + allCategoricalChartTypes() { + return this.$locale.getAllCategoricalChartTypes(); }, allChartDataTypes() { return this.$locale.getAllStatisticsChartDataTypes(); diff --git a/src/views/desktop/statistics/TransactionPage.vue b/src/views/desktop/statistics/TransactionPage.vue index 2b575d43..95a7f8ed 100644 --- a/src/views/desktop/statistics/TransactionPage.vue +++ b/src/views/desktop/statistics/TransactionPage.vue @@ -13,42 +13,26 @@