-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Transactions trend chart (#503)
- Loading branch information
Showing
7 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<template> | ||
<div class="transactions-chart-controls"> | ||
<app-chip | ||
v-for="(button, index) in buttons" | ||
:key="index" | ||
class="transactions-chart-controls__button" | ||
:variant="selectedIndex === index ? 'error' : 'secondary'" | ||
@click="select(index)"> | ||
{{ button.label }} | ||
</app-chip> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
const buttons = [ | ||
{ interval: 'day', limit: '7', label: '1W' }, | ||
{ interval: 'day', limit: '30', label: '1M' }, | ||
{ interval: 'day', limit: '90', label: '3M' }, | ||
{ interval: 'month', limit: '12', label: '1Y' }, | ||
{ interval: 'month', limit: '100', label: 'ALL' }, | ||
] | ||
const selectedIndex = ref(0) | ||
function select(value) { | ||
selectedIndex.value = value | ||
emit('selected', buttons[value]) | ||
} | ||
const emit = defineEmits(['selected']) | ||
</script> | ||
|
||
<style scoped> | ||
.transactions-chart-controls { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr; | ||
column-gap: 8px; | ||
@media (--desktop) { | ||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr; | ||
} | ||
&__button { | ||
display: inline-flex; | ||
justify-content: center; | ||
cursor: pointer; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<template> | ||
<app-panel> | ||
<template #heading> | ||
TOTAL TRANSACTIONS | ||
</template> | ||
<template #header> | ||
<transactions-chart-controls | ||
class="transactions-chart-panel__controls" | ||
@selected="loadTransactionsStatistics"/> | ||
</template> | ||
|
||
<div class="transactions-chart-panel__container"> | ||
<Line | ||
:options="chartOptions" | ||
:data="chartData"/> | ||
</div> | ||
|
||
<transactions-chart-controls | ||
class="transactions-chart-panel__controls--condensed" | ||
@selected="loadTransactionsStatistics"/> | ||
</app-panel> | ||
</template> | ||
|
||
<script setup> | ||
import { Line } from 'vue-chartjs' | ||
import { | ||
CategoryScale, | ||
Chart as ChartJS, | ||
Legend, | ||
LinearScale, | ||
LineElement, | ||
PointElement, | ||
Title, | ||
Tooltip, | ||
} from 'chart.js' | ||
import { storeToRefs } from 'pinia' | ||
import { DateTime } from 'luxon' | ||
import { useTransactionsStore } from '@/stores/transactions' | ||
import TransactionsChartControls from '@/components/TransactionsChartControls' | ||
const transactionsStore = useTransactionsStore() | ||
const { | ||
transactionsStatistics, | ||
} = storeToRefs(transactionsStore) | ||
const { fetchTransactionsStatistics } = transactionsStore | ||
ChartJS.register( | ||
CategoryScale, | ||
LinearScale, | ||
PointElement, | ||
LineElement, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
) | ||
ChartJS.defaults.font.family = 'Roboto Mono' | ||
const chartData = computed(() => { | ||
return { | ||
labels: labels.value, | ||
datasets: [{ | ||
data: stats.value, | ||
label: null, | ||
cubicInterpolationMode: 'monotone', | ||
tension: 0.4, | ||
borderColor: '#f5274e', | ||
backgroundColor: '#f5274e', | ||
pointRadius: 3, | ||
pointHitRadius: 20, | ||
}], | ||
} | ||
}) | ||
const chartOptions = { | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
tooltip: { | ||
tooltip: { | ||
position: 'top', | ||
}, | ||
callbacks: { | ||
title: function(context) { | ||
return context.label | ||
}, | ||
}, | ||
}, | ||
}, | ||
scales: { | ||
y: { | ||
border: { | ||
display: false, | ||
}, | ||
}, | ||
x: { | ||
grid: { | ||
color: function() { | ||
return 'transparent' | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
const selectedInterval = ref('') | ||
await useAsyncData(async() => { | ||
await fetchTransactionsStatistics() | ||
return true | ||
}) | ||
const stats = computed(() => { | ||
return transactionsStatistics.value?.map(stat => { | ||
return stat.count | ||
}) | ||
}) | ||
const labels = computed(() => { | ||
return transactionsStatistics.value?.map(stat => { | ||
return formatLabel(stat.startDate) | ||
}) | ||
}) | ||
function formatLabel(label) { | ||
const date = DateTime.fromISO(label) | ||
if (selectedInterval.value === 'month') { | ||
return date.toFormat('yyyy-MM') | ||
} | ||
return date.toFormat('MM-dd') | ||
} | ||
async function loadTransactionsStatistics({ interval, limit }) { | ||
selectedInterval.value = interval | ||
await fetchTransactionsStatistics(`?limit=${parseInt(limit) + 1}&interval_by=${interval}`) | ||
} | ||
</script> | ||
<style scoped> | ||
.transactions-chart-panel { | ||
&__container { | ||
position: relative; | ||
height: 250px; | ||
} | ||
&__controls { | ||
display: none; | ||
@media (--desktop) { | ||
display: grid; | ||
} | ||
} | ||
&__controls--condensed { | ||
margin-top: var(--space-4); | ||
@media (--desktop) { | ||
display: none; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters