Skip to content

Open source personal finance application

feat(Chart): show tooltip

ilkomead9fa8093638
diff --git a/components/stat/chart/View.vue b/components/stat/chart/View.vue
index 3b1ea23b..97282aa9 100644
--- a/components/stat/chart/View.vue
+++ b/components/stat/chart/View.vue
@@ -1,11 +1,12 @@
<script lang="ts">
import { Chart } from 'highcharts-vue'
-import chartOptions from '~/components/stat/chart/chartOptions'
-import useChart from '~/components/chart/useChart'
-import useFilter from '~/modules/filter/useFilter'
-import { getCategoriesIds, getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { getTotal } from '~/components/amount/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
+import { getTotal } from '~/components/amount/getTotal'
+import { getCategoriesIds, getTransferCategoriesIds } from '~/components/categories/getCategories'
+import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmount'
+import useFilter from '~/modules/filter/useFilter'
+import useChart from '~/components/chart/useChart'
+import chartOptions from '~/components/stat/chart/chartOptions'
export default defineComponent({
components: { Chart },
@@ -41,9 +42,9 @@ export default defineComponent({
return
const nEvent = await chart.pointer.normalize(event)
- let date = chart.series[0].searchPoint(nEvent, true)?.date || chart.series[1].searchPoint(nEvent, true)?.date || chart.series[2].searchPoint(nEvent, true)?.date
+ let date = chart.series[0]?.searchPoint(nEvent, true)?.date || chart.series[1]?.searchPoint(nEvent, true)?.date || chart.series[2]?.searchPoint(nEvent, true)?.date
setTimeout(() => {
- date = chart.series[0].searchPoint(nEvent, true)?.date || chart.series[1].searchPoint(nEvent, true)?.date || chart.series[2].searchPoint(nEvent, true)?.date
+ date = chart.series[0]?.searchPoint(nEvent, true)?.date || chart.series[1]?.searchPoint(nEvent, true)?.date || chart.series[2]?.searchPoint(nEvent, true)?.date
if (date) {
if ($store.state.filter.period === 'all')
$store.dispatch('filter/setPeriod', 'year')
@@ -183,8 +184,6 @@ export default defineComponent({
}
}
- const fakeLineDate = expenseData.map(i => ({ date: i.date, y: periodsTotalIncome / periods || periodsTotalExpense / periodsExpense }))
-
const data = {
series: [{
// Income
@@ -208,37 +207,24 @@ export default defineComponent({
marker: {
lineColor: 'var(--c-expense-1)',
},
- }, {
- // Fake data to make good hover on bar chart
- zIndex: 1,
- visible: true,
- type: 'line',
- name: '',
- color: 'transparent',
- data: fakeLineDate,
- marker: {
- enabled: false,
- symbol: 'circle',
- radius: 0,
- lineWidth: 0,
- states: {
- hover: {
- fillColor: 'transparent',
- lineColor: 'transparent',
- lineWidth: 0,
- },
- },
- },
- dataLabels: {
- enabled: false,
- },
}],
categories,
averageIncome: periodsTotalIncome / periods,
averageExpense: periodsTotalExpense / periodsExpense,
}
- const tooltip = this.$store.state.ui.pc ? { ...chartOptions.tooltip } : { enabled: false }
+ // Tooltip
+ let tooltip = { enabled: false }
+ if (this.$store.state.ui.pc) {
+ tooltip = {
+ ...chartOptions.tooltip,
+ formatter() {
+ return this.points.reduce((s, point) => {
+ return `${s}<br/>${point.series.name}: ${formatAmount(point.y, baseCurrencyCode)} ${getCurrencySymbol(baseCurrencyCode)}`
+ }, this.x)
+ },
+ }
+ }
const plotLines = []
// Expense
@@ -292,6 +278,9 @@ export default defineComponent({
dataLabels: {
...chartOptions.plotOptions.series.dataLabels,
enabled: this.isShowDataLabels,
+ formatter() {
+ return formatAmount(this.y, baseCurrencyCode)
+ },
},
},
},
diff --git a/components/stat/chart/chartOptions.js b/components/stat/chart/chartOptions.js
index 11becfd5..46feb4f7 100644
--- a/components/stat/chart/chartOptions.js
+++ b/components/stat/chart/chartOptions.js
@@ -34,7 +34,7 @@ export default {
},
column: {
- groupPadding: 0.2,
+ groupPadding: 0.3,
pointPadding: 0.1,
borderWidth: 0,
maxPointWidth: 10,
@@ -91,7 +91,7 @@ export default {
y: -8,
style: {
textOutline: 'var(--c-chart-lables-text-shaddow)',
- fontSize: '10px',
+ fontSize: '11px',
fontFamily: 'var(--font-secondary)',
fontWeight: 400,
textTransform: 'uppercase',
@@ -141,19 +141,14 @@ export default {
tooltip: {
shared: true,
- animation: false,
backgroundColor: 'var(--c-bg-3)',
borderColor: 'var(--c-bg-7)',
borderRadius: 8,
- padding: 0,
+ padding: 8,
shadow: false,
- useHTML: true,
- headerFormat: '',
- pointFormat: '',
- footerFormat: '',
style: {
color: 'var(--c-font-2)',
- fontSize: '12px',
+ fontSize: '14px',
fontFamily: 'var(--font-roboto)',
},
},
diff --git a/store/chart/index.js b/store/chart/index.js
index 4b5d30be..dafbfec5 100644
--- a/store/chart/index.js
+++ b/store/chart/index.js
@@ -4,22 +4,22 @@ export const state = () => ({
periods: {
day: {
groupedBy: 'month',
- showedPeriods: 14,
+ showedPeriods: 31,
grouped: false,
},
week: {
groupedBy: 'month',
- showedPeriods: 6,
+ showedPeriods: 12,
grouped: false,
},
month: {
groupedBy: 'year',
- showedPeriods: 6,
+ showedPeriods: 12,
grouped: false,
},
year: {
groupedBy: 'year',
- showedPeriods: 3,
+ showedPeriods: 6,
grouped: false,
},
},
diff --git a/store/ui/actions.js b/store/ui/actions.js
index 6dbeefc6..e4ad5ecb 100644
--- a/store/ui/actions.js
+++ b/store/ui/actions.js
@@ -40,7 +40,7 @@ export default {
*/
setAppDimensions({ commit }, { height, width }) {
let view = 'mobile'
- if (width >= 1300)
+ if (width >= 1024)
view = 'pc'
commit('setAppDimensions', {