comptes/src/components/tags_comparison.vue

74 lines
1.4 KiB
Vue

<template>
<div class="container">
<pie :chart-data="chartdata" :options="options" v-if="spendings[0] !== 0"></pie>
</div>
</template>
<script>
import pie from './charjs_donut'
import { mapGetters } from 'vuex'
import { total } from '../libs/data_processing'
export default {
name: 'postesComparison',
components: {
'pie': pie
},
data () {
return {
selected_tags: [
'virements',
'cash',
'autoroute',
'essence',
'courses',
'sans tags'
],
options: {
responsive: true,
maintainAspectRatio: false
}
}
},
computed: {
...mapGetters('datas', [
'tag_filter_rows'
]),
chartdata () {
return {
labels: this.selected_tags,
datasets: [
{
label: "Dépenses",
data: this.spendings
}
]
}
},
spendings () {
var tagsSpendings = this.selected_tags.map(tag => {
if (tag) {
return total(this.tag_filter_rows([tag]))
} else {
return 0
}
})
tagsSpendings[tagsSpendings.length - 1] = total(this.tag_filter_rows([])) - tagsSpendings.reduce((sum, a) => sum + a, 0)
return tagsSpendings
}
},
methods: {
}
}
</script>
<style scope>
.container {
position: relative;
height: 40vh;
width: 80vw;
}
</style>