Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
fix chart data
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Mar 25, 2024
1 parent 2ff611a commit 57fba6a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/balances/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Title,
Tooltip,
} from "chart.js";
import { isNegative, toSnapshot, type Dinero } from "dinero.js";
import { isNegative, type Dinero } from "dinero.js";
import { Bar } from "vue-chartjs";
ChartJS.register(
Expand All @@ -32,7 +32,7 @@ const chartData = computed(() => ({
labels: props.members.map((m) => m.name),
datasets: [
{
data: props.balances.map((v) => toSnapshot(v).amount),
data: props.balances.map(toFloat),
backgroundColor: props.balances.map((v) =>
isNegative(v) ? "rgba(255, 99, 132, 0.2)" : "rgba(75, 192, 192, 0.2)"
),
Expand Down
2 changes: 1 addition & 1 deletion components/new-expense/Infos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const amountCurrency = ref(
watchEffect(() => {
if (amount.value) {
amountValue.value = parseFloat(toDecimal(amount.value));
amountValue.value = toFloat(amount.value);
amountCurrency.value = toSnapshot(amount.value).currency;
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/new-expense/Participants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const updateSharesAmount = () => {
for (let i = 0; i < mIds.length; i++) {
const amount = shares[i];
model.value[mIds[i]].amount = amount;
floatSharesAmount.value.set(mIds[i], parseFloat(toDecimal(amount)));
floatSharesAmount.value.set(mIds[i], toFloat(amount));
}
};
updateSharesAmount();
Expand Down
2 changes: 1 addition & 1 deletion pages/[id].vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import {
ArrowPathIcon,
ArrowsRightLeftIcon,
CreditCardIcon,
ArrowPathIcon,
} from "@heroicons/vue/24/solid";
const route = useRoute();
Expand Down
4 changes: 4 additions & 0 deletions utils/dinero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function fromFloat(
return dinero({ amount, currency });
}

export function toFloat(amount: Dinero<number>): number {
return parseFloat(toDecimal(amount));
}

export function toString(amount: Dinero<number>): string {
return toDecimal(
amount,
Expand Down

0 comments on commit 57fba6a

Please sign in to comment.