2021-12-19 19:06:25 +00:00
|
|
|
<template>
|
2023-04-22 09:55:18 +00:00
|
|
|
<e-charts
|
2022-04-19 18:07:59 +00:00
|
|
|
v-if="currencies"
|
|
|
|
:option="balanceChartOptions"
|
|
|
|
:theme="settingsStore.chartTheme"
|
|
|
|
autoresize
|
|
|
|
/>
|
2021-12-19 19:06:25 +00:00
|
|
|
</template>
|
|
|
|
|
2023-04-22 09:55:18 +00:00
|
|
|
<script setup lang="ts">
|
2021-12-19 19:06:25 +00:00
|
|
|
import ECharts from 'vue-echarts';
|
|
|
|
import { EChartsOption } from 'echarts';
|
|
|
|
|
|
|
|
import { use } from 'echarts/core';
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
|
|
import { PieChart } from 'echarts/charts';
|
|
|
|
import { LabelLayout } from 'echarts/features';
|
|
|
|
import {
|
|
|
|
DatasetComponent,
|
|
|
|
LegendComponent,
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
} from 'echarts/components';
|
|
|
|
|
2022-01-24 18:47:33 +00:00
|
|
|
import { BalanceRecords } from '@/types';
|
2022-01-06 08:11:36 +00:00
|
|
|
import { formatPriceCurrency } from '@/shared/formatters';
|
2023-04-22 09:55:18 +00:00
|
|
|
import { computed } from 'vue';
|
2022-04-19 18:07:59 +00:00
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
2021-12-19 19:06:25 +00:00
|
|
|
|
|
|
|
use([
|
|
|
|
PieChart,
|
|
|
|
CanvasRenderer,
|
|
|
|
DatasetComponent,
|
|
|
|
LegendComponent,
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
LabelLayout,
|
|
|
|
]);
|
|
|
|
|
2023-04-22 09:55:18 +00:00
|
|
|
const props = defineProps({
|
|
|
|
currencies: { required: true, type: Array as () => BalanceRecords[] },
|
|
|
|
showTitle: { required: false, type: Boolean },
|
|
|
|
});
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
|
|
|
|
const balanceChartOptions = computed((): EChartsOption => {
|
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
text: 'Balance',
|
|
|
|
show: props.showTitle,
|
|
|
|
},
|
|
|
|
center: ['50%', '50%'],
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
dataset: {
|
|
|
|
dimensions: ['balance', 'currency', 'est_stake', 'free', 'used', 'stake'],
|
|
|
|
source: props.currencies,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'item',
|
|
|
|
formatter: (params) => {
|
|
|
|
return `${formatPriceCurrency(params.value.balance, params.value.currency, 8)}<br />${
|
|
|
|
params.percent
|
|
|
|
}% (${formatPriceCurrency(params.value.est_stake, params.value.stake)})`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// legend: {
|
|
|
|
// orient: 'vertical',
|
|
|
|
// right: 10,
|
|
|
|
// top: 20,
|
|
|
|
// bottom: 20,
|
|
|
|
// },
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: 'pie',
|
|
|
|
radius: ['40%', '70%'],
|
2021-12-19 19:06:25 +00:00
|
|
|
|
2023-04-22 09:55:18 +00:00
|
|
|
encode: {
|
|
|
|
value: 'est_stake',
|
|
|
|
itemName: 'currency',
|
|
|
|
tooltip: ['balance', 'currency'],
|
2022-01-06 08:11:36 +00:00
|
|
|
},
|
2023-04-22 09:55:18 +00:00
|
|
|
label: {
|
|
|
|
formatter: '{b} - {d}%',
|
2022-04-16 18:29:53 +00:00
|
|
|
},
|
|
|
|
tooltip: {
|
2023-04-22 09:55:18 +00:00
|
|
|
show: true,
|
2021-12-19 19:06:25 +00:00
|
|
|
},
|
2023-04-22 09:55:18 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-04-16 18:29:53 +00:00
|
|
|
});
|
2021-12-19 19:06:25 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.echarts {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
min-height: 240px;
|
|
|
|
}
|
|
|
|
</style>
|