Open source personal finance application
feat (Chart): highlight selected period in charts
ilkomeda9b8ff0c3b2
diff --git a/components/chart/MobileStatLines.vue b/components/chart/MobileStatLines.vueindex 03762b0c..69352e5c 100644--- a/components/chart/MobileStatLines.vue+++ b/components/chart/MobileStatLines.vue@@ -38,7 +38,7 @@ export default {<template lang="pug">.chart.chart__content(v-if="!isEmptyStat")- LazyStatChartLines(+ LazyChartStatChartLines(v-if="!isEmptyStat":isShowIncomes="activeTabStat === 'incomes' || activeTabStat === 'details' || activeTabStat === 'history'":isShowExpenses="activeTabStat === 'expenses' || activeTabStat === 'details' || activeTabStat === 'history'"diff --git a/components/stat/StatChartBalance.vue b/components/chart/StatChartBalance.vuesimilarity index 97%rename from components/stat/StatChartBalance.vuerename to components/chart/StatChartBalance.vueindex 3e407f16..1efab9b4 100644--- a/components/stat/StatChartBalance.vue+++ b/components/chart/StatChartBalance.vue@@ -57,8 +57,8 @@ export default {chart: {backgroundColor: 'transparent',- with: '100%',- height: '40%',+ with: 'auto',+ height: '300',spacing: [5, 0, 0, 0],type: 'column',panning: true,@@ -82,7 +82,7 @@ export default {return baseAmountFormat(amount, ' ', fixed)},- generateData (periodName, oldSeries) {+ generateData (periodName) {const trns = this.$store.state.trns.itemsconst allTrnsIds = Object.keys(trns)@@ -187,6 +187,8 @@ $border = var(--c-bg-1).chartz-index 3position relative+ width 100%+ // height 300pxbackground var(--c-bg-2)anim()@@ -207,6 +209,5 @@ $border = var(--c-bg-1)background var(--c-bg-1)&__content- padding 30px 60px-+ padding 30px 40px</style>diff --git a/components/stat/StatChartLines.vue b/components/chart/StatChartLines.vuesimilarity index 78%rename from components/stat/StatChartLines.vuerename to components/chart/StatChartLines.vueindex 01a0aa58..770d570c 100644--- a/components/stat/StatChartLines.vue+++ b/components/chart/StatChartLines.vue@@ -1,5 +1,5 @@<script>-import { computed, useContext } from '@nuxtjs/composition-api'+import { ref, computed, watch, nextTick, useContext } from '@nuxtjs/composition-api'import { Chart } from 'highcharts-vue'import chartOptions from '~/components/stat/chartOptions'import useChart from '~/components/chart/useChart'@@ -45,7 +45,7 @@ export default {},setup () {- const { store } = useContext()+ const { store, app: { $day } } = useContext()const { isShowDataLabels } = useChart()const { filterPeriodNameAllReplacedToYear } = useFilter()@@ -59,7 +59,51 @@ export default {return type})+ const chartObj = ref({})+ const chartCallback = (v) => { chartObj.value = v }++ const onClickChart = (event) => {+ const chart = chartObj.value+ if (!chart)+ return++ const nEvent = chart.pointer.normalize(event)+ const value = chart.series[0].searchPoint(nEvent, true) || chart.series[0].searchPoint(nEvent, false) || chart.series[1].searchPoint(nEvent, true)++ if (value) {+ if (store.state.filter.period === 'all')+ store.dispatch('filter/setPeriod', 'year')+ if (value.date)+ store.dispatch('filter/setDate', parseInt(value.date))+ }+ }++ watch(() => store.state.filter.date, async (date) => {+ await nextTick()+ const chart = chartObj.value+ 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).format(format)++ const index = chart.xAxis && chart?.xAxis[0].categories.indexOf(name)+ chart.xAxis[0].update({+ plotBands: [{+ color: 'var(--c-bg-7)',+ from: index + 0.5,+ to: index - 0.5+ }]+ })+ }, { immediate: true })+return {+ onClickChart,+ chartCallback,isShowDataLabels,filterPeriodNameAllReplacedToYear,chartType@@ -71,7 +115,6 @@ export default {const periodName = this.filterPeriodNameAllReplacedToYearconst chartPeriods = this.$store.state.chart.periodsconst trns = this.$store.state.trns.items- const vm = this// diff periods from oldest trn and todayconst oldestTrnDate = this.$day(trns[this.$store.getters['trns/firstCreatedTrnId']].date).endOf(periodName)@@ -185,12 +228,7 @@ export default {xAxis: {...chartOptions.xAxis,- categories: data.categories,- plotBands: [{- color: 'var(--c-bg-5)',- from: data.categories.length - 1.5,- to: data.categories.length - 0.5- }]+ categories: data.categories},yAxis: {@@ -212,26 +250,7 @@ export default {chart: {...chartOptions.chart,- height: '180',-- events: {- click (e) {- const value = this.series[0].searchPoint(e, false) || this.series[1].searchPoint(e, false)- if (value) {- this.xAxis[0].update({- plotBands: [{- color: 'var(--c-bg-5)',- from: value.index + 0.5,- to: value.index - 0.5- }]- })- if (vm.$store.state.filter.period === 'all')- vm.$store.dispatch('filter/setPeriod', 'year')-- vm.$store.dispatch('filter/setDate', parseInt(value.date))- }- }- }+ height: '180'},plotOptions: {@@ -241,24 +260,6 @@ export default {dataLabels: {...chartOptions.plotOptions.series.dataLabels,enabled: this.isShowDataLabels- },- cursor: 'pointer',- point: {- events: {- click () {- this.series.xAxis.update({- plotBands: [{- color: 'var(--c-bg-5)',- from: this.index + 0.5,- to: this.index - 0.5- }]- })- if (vm.$store.state.filter.period === 'all')- vm.$store.dispatch('filter/setPeriod', 'year')-- vm.$store.dispatch('filter/setDate', parseInt(this.date))- }- }}}}@@ -269,8 +270,8 @@ export default {</script><template lang="pug">-.chart- Chart(:options="chartData")+.chart(@click="onClickChart")+ Chart(:options="chartData" :callback="chartCallback")</template><style lang="stylus" scoped>diff --git a/components/stat/Dashboard.vue b/components/stat/Dashboard.vueindex 418a2507..0c307397 100644--- a/components/stat/Dashboard.vue+++ b/components/stat/Dashboard.vue@@ -208,7 +208,7 @@ export default {).statChartLines(v-if="filter.categoryId")- StatChartLines(+ LazyChartStatChartLines(v-if="filter.categoryId && $store.getters['trns/hasTrns']":categoryId="filter.categoryId":chartColor="$store.state.categories.items[filter.categoryId].color"