From ac092994c05fd322009b2107aeb80b2099e62788 Mon Sep 17 00:00:00 2001 From: Eddy Harrington Date: Thu, 1 Apr 2021 13:02:02 -0700 Subject: [PATCH] Fix report charts rounding issues --- static/js/reports.js | 8 ++++---- templates/budgetcreated.html | 2 +- tendie_budgets.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/static/js/reports.js b/static/js/reports.js index e403f07..865b19a 100644 --- a/static/js/reports.js +++ b/static/js/reports.js @@ -44,7 +44,7 @@ function loadBudgetCharts(budgets) { labels: ['Spent', 'Remaining'], datasets: [{ label: budgets[i].name, - data: [budgets[i].spent, budgets[i].remaining], + data: [(Math.round(budgets[i].spent * 100) / 100), (Math.round(budgets[i].remaining * 100) / 100)], backgroundColor: [ 'rgba(240, 173, 78, 1)', 'rgba(2, 184, 117, 1)' @@ -102,7 +102,7 @@ function loadMonthlySpendingChart(monthlySpendingChart) { let amounts = [] for (i = 0; i < monthlySpendingChart.length; i++) { months[i] = monthlySpendingChart[i].name; - amounts[i] = monthlySpendingChart[i].amount; + amounts[i] = (Math.round(monthlySpendingChart[i].amount * 100) / 100); } // Draw the chart @@ -202,7 +202,7 @@ function loadSpendingTrendsChart(spendingTrends_chart) { borderColor: "rgba(2, 184, 117, 1)", borderWidth: 2, data: [{ - x: spendingTrends_chart[i].totalSpent, + x: (Math.round(spendingTrends_chart[i].totalSpent * 100) / 100), y: spendingTrends_chart[i].totalCount, r: spendingTrends_chart[i].proportionalAmount }] @@ -288,7 +288,7 @@ function loadPayersSpendingChart(payersSpending) { continue; } else { - payerAmounts.push(payersSpending[i].amount) + payerAmounts.push((Math.round(payersSpending[i].amount * 100) / 100)) } } diff --git a/templates/budgetcreated.html b/templates/budgetcreated.html index 13b5230..4b551e3 100644 --- a/templates/budgetcreated.html +++ b/templates/budgetcreated.html @@ -34,7 +34,7 @@
Budget Details
{% set amount = (results["amount"] * category["percent"]) %} {{ category["name"] }} - {{ ((category["percent"] * 100) | string)[:-2] }}% + {{ (category['percent'] * 100) | round | int }}% {{ amount | usd }} {% endfor %} diff --git a/tendie_budgets.py b/tendie_budgets.py index c7f56c5..163d905 100644 --- a/tendie_budgets.py +++ b/tendie_budgets.py @@ -282,7 +282,7 @@ def getUpdatableBudget(budget, userID): # Mark the category as checked/True if it exists in the budget that the user wants to update if category["name"] == budgetCategory["name"]: # Convert the percentage (decimal) into a whole integer to be consistent with UX - amount = int(budgetCategory["amount"] * 100) + amount = round(budgetCategory["amount"] * 100) budget["categories"].append( {"name": category["name"], "amount": amount, "checked": True}) break