11<template >
2- <StackedLineChart :data =" data" />
2+ <ChartPlaceholder v-if =" isEmpty" />
3+ <StackedLineChart v-else :data =" data" />
34</template >
45
56<script lang="ts" setup>
67import { StackedLineChartConfig } from ' ./stacked-line-chart/StackedLineChart.types' ;
78import StackedLineChart from ' ./stacked-line-chart/StackedLineChart.vue' ;
9+ import ChartPlaceholder from ' @components/feature/ChartPlaceholder.vue' ;
810import { useDataStore } from ' @store/state' ;
911import { totals } from ' @store/state/utils/budgets' ;
12+ import { sum } from ' @utils' ;
1013import { computed } from ' vue' ;
1114import { useI18n } from ' vue-i18n' ;
1215
1316const { t, locale } = useI18n ();
1417const { state } = useDataStore ();
1518
19+ const allIncomes = computed (() => state .years .flatMap ((v ) => totals (v .income )));
20+ const allExpenses = computed (() => state .years .flatMap ((v ) => totals (v .expenses )));
21+
22+ const isEmpty = computed (() => ! sum (allIncomes .value ) && ! sum (allExpenses .value ));
23+
1624const data = computed ((): StackedLineChartConfig => {
1725 const totalMonths = state .years .length * 12 ;
1826 const formatter = new Intl .NumberFormat (locale .value , {
@@ -32,13 +40,13 @@ const data = computed((): StackedLineChartConfig => {
3240 {
3341 name: t (' page.dashboard.income' ),
3442 trendName: t (' page.dashboard.incomeTrend' ),
35- data: state . years . flatMap (( v ) => totals ( v . income )) ,
43+ data: allIncomes . value ,
3644 color: ' var(--c-success-light-dimmed)'
3745 },
3846 {
3947 name: t (' page.dashboard.expenses' ),
4048 trendName: t (' page.dashboard.expensesTrend' ),
41- data: state . years . flatMap (( v ) => totals ( v . expenses )) ,
49+ data: allExpenses . value ,
4250 color: ' var(--c-danger-light-dimmed)'
4351 }
4452 ]
0 commit comments