Open source personal finance application
fix: filter period date
ilkomebfefd2b6edfd
diff --git a/components/chart/StatChartLines.vue b/components/chart/StatChartLines.vueindex a109f2c5..e498c887 100644--- a/components/chart/StatChartLines.vue+++ b/components/chart/StatChartLines.vue@@ -68,41 +68,35 @@ export default {returnconst nEvent = await chart.pointer.normalize(event)- let value = chart.series[0].searchPoint(nEvent, true) || chart.series[1].searchPoint(nEvent, true) || chart.series[2].searchPoint(nEvent, true)+ let date = chart.series[0].searchPoint(nEvent, true)?.date || chart.series[1].searchPoint(nEvent, true)?.date || chart.series[2].searchPoint(nEvent, true)?.datesetTimeout(() => {- value = chart.series[0].searchPoint(nEvent, true) || chart.series[1].searchPoint(nEvent, true) || chart.series[2].searchPoint(nEvent, true)-- if (value) {+ 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')- if (value.date)- store.dispatch('filter/setDate', parseInt(value.date))+ store.dispatch('filter/setDate', parseInt(date))scrollTop()}}, 100)}- watch(() => store.state.filter.date, async (date) => {+ watch(() => store.state.filter.date, async () => {await nextTick()+const chart = chartObj.value+ console.log('chart', chart)if (!chartObj.value)return- let format = 'MM'- if (filterPeriodNameAllReplacedToYear.value === 'day') format = 'D.MM'- if (filterPeriodNameAllReplacedToYear.value === 'week') format = 'D MMM'- if (filterPeriodNameAllReplacedToYear.value === 'month') format = 'MMM'- if (filterPeriodNameAllReplacedToYear.value === 'year') format = 'YYYY'- const name = $day(date).startOf(filterPeriodNameAllReplacedToYear.value).format(format)- const index = chart.xAxis && chart?.xAxis[0].categories.indexOf(name)-- if (index !== -1) {+ const chartSeriesIdx = chart.series[0].options.data.findIndex(v => +v.date === +store.state.filter.date)+ console.log(chartSeriesIdx)+ if (chartSeriesIdx !== -1) {chart.xAxis[0].update({plotBands: [{color: 'var(--c-bg-7)',- from: index + 0.5,- to: index - 0.5+ from: chartSeriesIdx + 0.5,+ to: chartSeriesIdx - 0.5}]})}@@ -137,7 +131,7 @@ export default {for (let index = 0; index < periodsToShow; index++) {// count total period- const periodDate = this.$day().endOf(periodName).subtract(index, periodName).valueOf()+ const periodDate = this.$day().startOf(periodName).subtract(index, periodName).valueOf()const trnsIds = this.$store.getters['trns/getTrns']({date: periodDate,periodName,diff --git a/store/filter/actions.js b/store/filter/actions.jsindex 03ac3b71..1a23f12d 100644--- a/store/filter/actions.js+++ b/store/filter/actions.js@@ -36,7 +36,7 @@ export default {setPeriod ({ commit, dispatch }, period) {commit('setPeriod', period)- commit('setDate', dayjs().valueOf())+ commit('setDate', dayjs().startOf(period).valueOf())localforage.setItem('finapp.filter.period', period)dispatch('ui/saveUiView', null, { root: true })},diff --git a/store/filter/index.js b/store/filter/index.jsindex 1296abfb..7f4a99a1 100644--- a/store/filter/index.js+++ b/store/filter/index.js@@ -3,6 +3,6 @@ import dayjs from 'dayjs'export const state = () => ({categoryId: null,walletId: null,- date: dayjs().valueOf(),+ date: dayjs().startOf('month').valueOf(),period: 'month'})