Open source personal finance application
feat(StatChart): add net income chart
ilkome0ab42ad09c66
diff --git a/components/stat/chart/Options.vue b/components/stat/chart/Options.vueindex 48dc3aa6..1ba594b8 100644--- a/components/stat/chart/Options.vue+++ b/components/stat/chart/Options.vue@@ -22,6 +22,11 @@ const { isShowDataLabels, toggleChartsView } = useChart()@click="toggleChart('expense')"): .mdi.mdi-arrow-up-thin-circle-outline+ .cursor-pointer.w-10.py-2.px-3.flex-center.rounded-md.hocus_bg-skin-item-main-hover(+ :class="{ 'text-skin-item-base-up': chartState.show.sum }"+ @click="toggleChart('sum')"+ ): .mdi.mdi-chart-gantt+.cursor-pointer.w-10.py-2.px-3.flex-center.rounded-md.hocus_bg-skin-item-main-hover(@click="toggleChartsView")diff --git a/components/stat/chart/View.vue b/components/stat/chart/View.vueindex 63efbbf9..3bf3adce 100644--- a/components/stat/chart/View.vue+++ b/components/stat/chart/View.vue@@ -16,6 +16,7 @@ export default defineComponent({categoryId: { type: String, default: null },isShowExpense: { type: Boolean, default: true },isShowIncome: { type: Boolean, default: true },+ isShowSum: { type: Boolean, default: false },},setup() {@@ -168,6 +169,8 @@ export default defineComponent({}let periods = 0++ // Incomelet periodsTotalIncome = 0for (const iterator of incomeData) {if (iterator.y !== 0) {@@ -175,6 +178,8 @@ export default defineComponent({periodsTotalIncome = periodsTotalIncome + iterator.y}}++ // Expenselet periodsExpense = 0let periodsTotalExpense = 0for (const iterator of expenseData) {@@ -184,6 +189,16 @@ export default defineComponent({}}+ // Sum+ let periodsSum = 0+ let periodsTotalSum = 0+ for (const iterator of totalData) {+ if (iterator.y !== 0) {+ periodsSum = periodsSum + 1+ periodsTotalSum = periodsTotalSum + iterator.y+ }+ }+const data = {series: [{// Income@@ -207,10 +222,22 @@ export default defineComponent({marker: {lineColor: 'var(--c-expense-1)',},+ }, {+ // Sum+ zIndex: 3,+ visible: periodsTotalIncome > 0 && periodsTotalExpense > 0 && this.isShowSum,+ type: this.chartType,+ name: this.$t('money.sum'),+ color: 'var(--c-font-2)',+ data: totalData,+ marker: {+ lineColor: 'var(--c-font-2)',+ },}],categories,averageIncome: periodsTotalIncome / periods,averageExpense: periodsTotalExpense / periodsExpense,+ averageSum: periodsTotalExpense / periodsExpense,}// Tooltip@@ -218,7 +245,7 @@ export default defineComponent({if (this.$store.state.ui.pc) {tooltip = {...chartConfig.tooltip,- formatter() {+ formatter(): string {return this.points.reduce((s, point) => {return `${s}<br/>${point.series.name}: ${formatAmount(point.y, baseCurrencyCode)} ${getCurrencySymbol(baseCurrencyCode)}`}, this.x)@@ -249,6 +276,17 @@ export default defineComponent({})}+ // Sum+ if (periodsTotalSum > 0 && this.isShowSum) {+ plotLines.push({+ opacity: 0.5,+ color: 'var(--c-font-4)',+ value: data.averageSum,+ width: '2',+ zIndex: 1,+ })+ }+return {...chartConfig,legend: false,diff --git a/components/stat/chart/Wrap.vue b/components/stat/chart/Wrap.vueindex 1a7a6838..9084150a 100644--- a/components/stat/chart/Wrap.vue+++ b/components/stat/chart/Wrap.vue@@ -23,5 +23,6 @@ const chartType = computed(() => {:chartType="chartType":isShowExpense="chartState.show.expense":isShowIncome="chartState.show.income"+ :isShowSum="chartState.show.sum")</template>diff --git a/components/stat/useStatChart.ts b/components/stat/useStatChart.tsindex 0b7e17f5..f12ff224 100644--- a/components/stat/useStatChart.ts+++ b/components/stat/useStatChart.ts@@ -4,6 +4,7 @@ const state = reactive({show: {income: true,expense: true,+ sum: false,},})