From 217c15a746f6b86c81d1fe11b72a53186b2100d1 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 28 Jan 2021 00:34:37 +0800 Subject: [PATCH] modify bar chart style --- src/filters/percent.js | 11 ++ src/mobile-main.js | 4 + src/views/mobile/statistics/Transaction.vue | 152 +++++++++++++++++++- 3 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 src/filters/percent.js diff --git a/src/filters/percent.js b/src/filters/percent.js new file mode 100644 index 00000000..75f18175 --- /dev/null +++ b/src/filters/percent.js @@ -0,0 +1,11 @@ +export default function (value, precision, lowPrecisionValue) { + const ratio = Math.pow(10, precision); + const normalizedValue = Math.floor(value * ratio); + + if (value > 0 && normalizedValue < 1 && lowPrecisionValue) { + return lowPrecisionValue + '%'; + } + + const result = normalizedValue / ratio; + return result + '%'; +} diff --git a/src/mobile-main.js b/src/mobile-main.js index 7a4f73d8..82324651 100644 --- a/src/mobile-main.js +++ b/src/mobile-main.js @@ -18,6 +18,7 @@ import Framework7Actions from 'framework7/components/actions/actions'; import Framework7Sheet from 'framework7/components/sheet/sheet'; import Framework7Toast from 'framework7/components/toast/toast'; import Framework7Preloader from 'framework7/components/preloader/preloader'; +import Framework7Progressbar from 'framework7/components/progressbar/progressbar'; import Framework7Sortable from 'framework7/components/sortable/sortable'; import Framework7Swipeout from 'framework7/components/swipeout/swipeout'; import Framework7Accordion from 'framework7/components/accordion/accordion'; @@ -73,6 +74,7 @@ import webauthn from './lib/webauthn.js'; import utils from './lib/utils.js'; import stores from './store/index.js'; import localizedFilter from './filters/localized.js'; +import percentFilter from './filters/percent.js'; import itemFieldContentFilter from './filters/itemFieldContent.js'; import currencyFilter from './filters/currency.js'; import iconFilter from './filters/icon.js'; @@ -106,6 +108,7 @@ Framework7.use(Framework7Actions); Framework7.use(Framework7Sheet); Framework7.use(Framework7Toast); Framework7.use(Framework7Preloader); +Framework7.use(Framework7Progressbar); Framework7.use(Framework7Sortable); Framework7.use(Framework7Swipeout); Framework7.use(Framework7Accordion); @@ -288,6 +291,7 @@ Vue.prototype.$hideLoading = function () { Vue.prototype.$user = userstate; Vue.filter('localized', (value, options) => localizedFilter({ i18n }, value, options)); +Vue.filter('percent', (value, precision, lowPrecisionValue) => percentFilter(value, precision, lowPrecisionValue)); Vue.filter('itemFieldContent', (value, fieldName, defaultValue, translate) => itemFieldContentFilter({ i18n }, value, fieldName, defaultValue, translate)); Vue.filter('currency', (value, currencyCode) => currencyFilter({ i18n }, value, currencyCode)); Vue.filter('icon', (value, iconType) => iconFilter(value, iconType)); diff --git a/src/views/mobile/statistics/Transaction.vue b/src/views/mobile/statistics/Transaction.vue index f1d9b5d3..56c13c44 100644 --- a/src/views/mobile/statistics/Transaction.vue +++ b/src/views/mobile/statistics/Transaction.vue @@ -21,12 +21,117 @@ - + + + + + +
+
+ +
+
+ +
+ Category Name 1 + 33.33 +
+ +
+ 0.00 USD +
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+ Category Name 2 + 33.33 +
+ +
+ 0.00 USD +
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+ Category Name 3 + 33.33 +
+ +
+ 0.00 USD +
+ +
+
+ +
+
+
+
+ + +
+
+ + + + +
+
+ +
+ {{ data.name }} + {{ data.percent | percent(2, '<0.01') }} +
+ +
+ {{ data.totalAmount | currency(defaultCurrency) }} +
+ +
+
+ +
+
+
+
+
+
+ @@ -168,6 +273,8 @@ export default { } else { data = { name: item.account.name, + type: 'account', + id: item.account.id, icon: item.account.icon || self.$constants.icons.defaultAccountIcon.icon, color: item.account.color || self.$constants.colors.defaultAccountColor, totalAmount: item.amountInDefaultCurrency @@ -187,7 +294,9 @@ export default { } else { data = { name: item.primaryCategory.name, - icon: item.account.icon || self.$constants.icons.defaultCategoryIcon.icon, + type: 'category', + id: item.primaryCategory.id, + icon: item.primaryCategory.icon || self.$constants.icons.defaultCategoryIcon.icon, color: item.primaryCategory.color || self.$constants.colors.defaultCategoryColor, totalAmount: item.amountInDefaultCurrency } @@ -206,7 +315,9 @@ export default { } else { data = { name: item.category.name, - icon: item.account.icon || self.$constants.icons.defaultCategoryIcon.icon, + type: 'category', + id: item.category.id, + icon: item.category.icon || self.$constants.icons.defaultCategoryIcon.icon, color: item.category.color || self.$constants.colors.defaultCategoryColor, totalAmount: item.amountInDefaultCurrency } @@ -232,7 +343,7 @@ export default { } allStatisticsData.sort(function (data1, data2) { - return data1.totalAmount - data2.totalAmount; + return data2.totalAmount - data1.totalAmount; }); return allStatisticsData; @@ -546,6 +657,39 @@ export default {