Skip to content

Commit

Permalink
Fix report charts rounding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyharrington committed Apr 1, 2021
1 parent e22e9da commit ac09299
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions static/js/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}]
Expand Down Expand Up @@ -288,7 +288,7 @@ function loadPayersSpendingChart(payersSpending) {
continue;
}
else {
payerAmounts.push(payersSpending[i].amount)
payerAmounts.push((Math.round(payersSpending[i].amount * 100) / 100))
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/budgetcreated.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5 class="card-title">Budget Details</h5>
{% set amount = (results["amount"] * category["percent"]) %}
<tr>
<td>{{ category["name"] }}</td>
<td>{{ ((category["percent"] * 100) | string)[:-2] }}%</td>
<td>{{ (category['percent'] * 100) | round | int }}%</td>
<td>{{ amount | usd }}
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion tendie_budgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac09299

Please sign in to comment.