Skip to content

Commit 9cd9668

Browse files
committed
feat: show placeholder in all-time-chart if no data is available
1 parent 854e590 commit 9cd9668

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/app/pages/dashboard/all-time/AllTime.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ const cards = computed((): Card[] => {
110110
}
111111
112112
.chart {
113+
display: grid;
114+
place-items: center;
113115
flex: 1;
114116
}
115117

src/app/pages/dashboard/all-time/AllTimeChart.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
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>
67
import { StackedLineChartConfig } from './stacked-line-chart/StackedLineChart.types';
78
import StackedLineChart from './stacked-line-chart/StackedLineChart.vue';
9+
import ChartPlaceholder from '@components/feature/ChartPlaceholder.vue';
810
import { useDataStore } from '@store/state';
911
import { totals } from '@store/state/utils/budgets';
12+
import { sum } from '@utils';
1013
import { computed } from 'vue';
1114
import { useI18n } from 'vue-i18n';
1215
1316
const { t, locale } = useI18n();
1417
const { 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+
1624
const 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

Comments
 (0)