comptes/src/components/tags_comparison.vue

86 lines
1.7 KiB
Vue
Raw Normal View History

<template>
<div class="container">
2018-12-03 10:53:01 +00:00
<pie :chart-data="chartdata" :options="options" v-if="spendings[0] !== 0"></pie>
</div>
</template>
<script>
import pie from './charjs_donut'
2018-12-03 10:53:01 +00:00
import { mapGetters } from 'vuex'
import { total } from '../libs/data_processing'
export default {
name: 'postesComparison',
components: {
'pie': pie
},
data () {
return {
2018-12-03 10:53:01 +00:00
selected_tags: [
'virements',
'cash',
'autoroute',
2019-01-21 11:10:22 +00:00
'train',
2018-12-03 10:53:01 +00:00
'essence',
'courses',
'sans tags'
],
options: {
responsive: true,
2018-12-04 17:57:21 +00:00
maintainAspectRatio: false,
legend: {
position: 'left'
}
}
}
},
computed: {
2018-12-03 10:53:01 +00:00
...mapGetters('datas', [
'tag_filter_rows'
]),
2018-12-04 17:57:21 +00:00
...mapGetters('config', [
'tag'
]),
2018-12-03 10:53:01 +00:00
chartdata () {
return {
labels: this.selected_tags,
datasets: [
{
2018-12-03 11:09:28 +00:00
label: 'Dépenses',
2018-12-04 17:57:21 +00:00
data: this.spendings,
backgroundColor: this.selected_tags.map(t => {
if (this.tag(t)) {
return this.tag(t).color
} else {
return '#A9A9A9'
}
})
2018-12-03 10:53:01 +00:00
}
]
}
},
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: 420px;
}
</style>