Skip to content

Commit aa14b70

Browse files
committed
Make the tooltip in the report graphs nicer.
1 parent 3c9bb22 commit aa14b70

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

src/components/dashboard/balance-chart.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ const BalanceChart = ({ range } : { range: DateRange }) => {
4141
}
4242
}
4343
}
44+
},
45+
plugins: {
46+
tooltip: {
47+
callbacks: {
48+
title: (context: any) => {
49+
console.log(context)
50+
return context[0].dataset.label + ': ' + new Intl.DateTimeFormat(localStorage.getItem('language') || 'en')
51+
.format(context[0].parsed.x)
52+
},
53+
label: (context: any) => {
54+
const value = context.parsed.y.toFixed(2)
55+
return `${ (RestAPI.user() as any).defaultCurrency?.symbol }${ value }`
56+
}
57+
}
58+
}
4459
}
4560
}
4661
) }

src/components/dashboard/budget-balance.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ function BudgetBalance({ range } : Readonly<{ range : DateRange }>) {
6464
legend: {
6565
position: 'bottom',
6666
display: true
67+
},
68+
tooltip: {
69+
callbacks: {
70+
label: (context: any) => {
71+
const label = context.dataset.label || ''
72+
const value = context.parsed.y.toFixed(2)
73+
return `${label}: ${(RestAPI.user() as any).defaultCurrency?.symbol}${value}`
74+
}
75+
}
6776
}
6877
}
6978
}

src/components/dashboard/categories-balance.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ const CategoriesBalance = ({ range } : { range: DateRange }) => {
4949
}
5050
}
5151
}
52+
},
53+
plugins: {
54+
tooltip: {
55+
callbacks: {
56+
label: (context: any) => {
57+
const value = context.parsed.y.toFixed(2)
58+
return `${(RestAPI.user() as any).defaultCurrency?.symbol}${value}`
59+
}
60+
}
61+
}
5262
}
5363
}
5464
)

src/components/reports/budget-monthly/chart.component.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ const BudgetChart = ({ dataSet, currencySymbol = '' } : { dataSet: ChartData, cu
2222
plugins: {
2323
legend: {
2424
display: true
25+
},
26+
tooltip: {
27+
callbacks: {
28+
title: (context: any) => {
29+
const date = new Date(context[0].parsed.x)
30+
return date.toLocaleString(localStorage.getItem('language') || 'en', { month: 'long' })
31+
},
32+
label: (context: any) => {
33+
const value = context.parsed.y.toFixed(2)
34+
return `${context.dataset.label}: ${currencySymbol}${value}`
35+
}
36+
}
2537
}
2638
}
2739
}) }

src/components/reports/category-monthly/montly-categorized-chart.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ const CategoryGraph = ({ categories, year, currencySymbol }: CategoryGraphProps)
8989
callback: (value : any) => `${currencySymbol}${value}`
9090
}
9191
}
92+
},
93+
plugins: {
94+
tooltip: {
95+
callbacks: {
96+
title: (context: any) => {
97+
const date = new Date(context[0].parsed.x)
98+
return date.toLocaleString(localStorage.getItem('language') || 'en', { month: 'long' })
99+
},
100+
label: (context: any) => {
101+
const value = context.parsed.y.toFixed(2)
102+
return `${context.dataset.label}: ${currencySymbol}${value}`
103+
}
104+
}
105+
}
92106
}
93107
}) }/>
94108
)

src/components/reports/income-expense/year-balance-chart.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,17 @@ const YearBalanceChart = ({ year, currencySymbol, currency } : YearBalanceChartP
135135
},
136136
plugins: {
137137
tooltip: {
138-
mode: 'point'
138+
mode: 'point',
139+
callbacks: {
140+
title: (context: any) => {
141+
const date = new Date(context[0].parsed.x)
142+
return date.toLocaleString(localStorage.getItem('language') || 'en', { month: 'long' })
143+
},
144+
label: (context: any) => {
145+
const value = context.parsed.y.toFixed(2)
146+
return `${context.dataset.label}: ${currencySymbol}${value}`
147+
}
148+
}
139149
},
140150
legend: {
141151
position: 'bottom',

0 commit comments

Comments
 (0)