diff --git a/src/components/ToolBar.vue b/src/components/ToolBar.vue index e3f6adc..91d6034 100644 --- a/src/components/ToolBar.vue +++ b/src/components/ToolBar.vue @@ -5,6 +5,12 @@
+
+ + +

Аналитика

+
+
diff --git a/src/components/analytics/AnalyticsView.vue b/src/components/analytics/AnalyticsView.vue index 8f0e760..55caa76 100644 --- a/src/components/analytics/AnalyticsView.vue +++ b/src/components/analytics/AnalyticsView.vue @@ -135,9 +135,9 @@ const prepareTableData = (categories) => { ...allDates.map((dateStr) => ({field: dateStr, header: dateStr})), ]; console.log(tableColumns.value[0].field); - + const sums = {} // 4. Формируем строки (для каждой категории) - return categories.map((category) => { + const rows = categories.map((category) => { // Начинаем со строки, где есть поле с именем категории const row = {category: category.categoryIcon + " " + category.categoryName}; @@ -146,20 +146,42 @@ const prepareTableData = (categories) => { const found = category.monthlySums.find((m) => m.date === dateStr); if (found.difference != 0) { if (found.difference > 0) { - row[dateStr] = found ? formatter.value.format(found.total) + "

(+ " + found.difference + "%)

" : 0; + row[dateStr] = found ? formatter.value.format(found.total) + "

(+ " + found.difference + "%)

" : 0; } else { - row[dateStr] = found ? formatter.value.format(found.total) + "

(" + found.difference + "%)

" : 0; + row[dateStr] = found ? formatter.value.format(found.total) + "

(" + found.difference + "%)

" : 0; } } else { - row[dateStr] = found ? formatter.value.format(found.total) : 0; } - - + if (!sums[dateStr]) { + sums[dateStr] = 0 + } + sums[dateStr] += found.total }); return row; }); + + + let previousSum = 0; + Object.keys(sums).forEach(key => { + + console.log(previousSum) + let difference = previousSum != 0 ? ((sums[key] - previousSum) / previousSum) * 100 : 0 + if (sums[key] != previousSum) { + previousSum = sums[key]; + } + let color = "" + if (difference > 0) { + color = "text-red-500" + } else color = "text-green-600" + sums[key] = formatter.value.format(sums[key]) + `

(` + difference.toFixed(0) + "%)

"; + + }); + + + rows.push(sums); + return rows; }; @@ -223,7 +245,7 @@ onMounted(async () => { - +