Skip to content

Commit

Permalink
Analytics page improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
isKONSTANTIN committed Jan 6, 2024
1 parent 02baf90 commit c7d469d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
4 changes: 4 additions & 0 deletions components/analytics/pie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ const buildChart = () => {
},
},
stroke: {
show: false
},
yaxis: {
labels: {
formatter: formatter
Expand Down
86 changes: 59 additions & 27 deletions components/analytics/tagsByMonths.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
<transactions-filter-div v-model="filter" :calendar-max-range="configs.maxTimeRangeDaysForMonths"/>

<ApexChart class="w-full max-h-36 mt-4"
type="area"
height="500px"
:options="chartOptions"
:series="chartSeries"
></ApexChart>
/>

<div class="flex justify-center w-full">
<div role="tablist" class="tabs tabs-boxed w-fit">
<a role="tab" class="tab px-6" @click="type = 'area'" :class="{ 'tab-active' : type === 'area' }"> {{ $t("analyticsPage.byMonthsSwitcher.area")}} </a>
<a role="tab" class="tab px-6" @click="type = 'bar'" :class="{ 'tab-active' : type === 'bar' }"> {{ $t("analyticsPage.byMonthsSwitcher.bar")}} </a>
<a role="tab" class="tab px-6" @click="type = 'radar'" :class="{ 'tab-active' : type === 'radar' }"> {{ $t("analyticsPage.byMonthsSwitcher.radar")}} </a>
</div>
</div>
</div>
</template>

Expand All @@ -23,37 +30,30 @@ const tagsMap = $transactionsTagsApi.getTagsMap();
const filter = ref();
const chartSeries = ref([]);
const chartOptions = ref({
chart: {
id: "tags-by-months",
foreColor: undefined
},
xaxis: {
categories: [],
},
yaxis : {
decimalsInFloat: 2
}
});
const type = ref('area');
const chartOptions = ref({});
const currenciesMap = $currenciesApi.getCurrenciesMap();
const configs = $serverConfigs.configs.analytics;
const buildChart = async () => {
const analytics = (await $analyticsApi.getAnalyticsByMonths(filter.value));
const sortedAnalytics = new Map(Array.from(analytics).sort(([a], [b]) => a.localeCompare(b)));
const analytics = ref({});
const fetch = async () => {
const analyticsRaw = await $analyticsApi.getAnalyticsByMonths(filter.value);
analytics.value = new Map(Array.from(analyticsRaw).sort(([a], [b]) => a.localeCompare(b)));
}
const buildChart = () => {
const xaxis = [];
const series = [];
const tags = {};
let decimals = Number.MAX_VALUE;
chartOptions.value.xaxis.categories = xaxis;
chartSeries.value = series;
let i = 0;
sortedAnalytics.forEach((v, k, m) => {
analytics.value.forEach((v, k, m) => {
const date = new Date(k).toLocaleString(locale.value, {year: 'numeric', month: 'numeric'})
xaxis.push(date);
Expand Down Expand Up @@ -88,11 +88,37 @@ const buildChart = async () => {
decimals = 2;
chartOptions.value = {
... chartOptions.value,
... {
yaxis: {
decimalsInFloat: decimals
}
chart: {
id: "tags-by-months-" + type.value,
type: type.value,
stacked: type.value === 'bar',
foreColor: undefined
},
plotOptions: {
horizontal: false,
columnWidth: '55%',
endingShape: 'rounded'
},
stroke: {
show: type.value !== 'bar',
curve: 'smooth',
lineCap: 'butt',
colors: undefined,
width: 2,
dashArray: 0,
},
fill: {
type: type.value === 'bar' ? "solid" : "gradient",
},
xaxis: {
categories: xaxis,
},
yaxis : {
decimalsInFloat: decimals
}
}
Expand All @@ -105,11 +131,17 @@ const buildChart = async () => {
});
}
watch(filter, () => {
watch([analytics, type], () => {
buildChart();
})
buildChart();
watch(filter, () => {
fetch();
})
fetch().then(() => {
buildChart();
})
</script>

Expand Down
6 changes: 6 additions & 0 deletions lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
},

"analyticsPage": {
"byMonthsSwitcher": {
"area": "Area",
"bar": "Bar",
"radar": "Radar"
},

"pie": {
"noData": "No data",
"selects": {
Expand Down
6 changes: 6 additions & 0 deletions lang/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
},

"analyticsPage": {
"byMonthsSwitcher": {
"area": "Линейная",
"bar": "Столбчатая",
"radar": "Паутинная"
},

"pie": {
"noData": "Нет данных",
"selects": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "finwave",
"version": "0.8.1",
"version": "0.9.0",
"private": true,
"scripts": {
"build": "nuxt build",
Expand Down

0 comments on commit c7d469d

Please sign in to comment.