2020-08-17 18:39:14 +00:00
|
|
|
<template>
|
2021-05-24 14:24:46 +00:00
|
|
|
<v-chart v-if="dailyStats.data" :option="dailyChartOptions" :theme="getChartTheme" autoresize />
|
2020-08-17 18:39:14 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue, Prop } from 'vue-property-decorator';
|
2020-12-28 19:34:54 +00:00
|
|
|
import { Getter } from 'vuex-class';
|
2020-08-17 18:39:14 +00:00
|
|
|
import ECharts from 'vue-echarts';
|
2021-05-24 14:39:02 +00:00
|
|
|
import { EChartsOption } from 'echarts';
|
2020-10-04 17:24:21 +00:00
|
|
|
|
2021-05-24 15:45:20 +00:00
|
|
|
import { use } from 'echarts/core';
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
|
|
import { LineChart, BarChart } from 'echarts/charts';
|
|
|
|
import { TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components';
|
2020-08-17 18:39:14 +00:00
|
|
|
|
2020-08-29 09:23:39 +00:00
|
|
|
import { DailyReturnValue } from '@/types';
|
2020-08-17 18:39:14 +00:00
|
|
|
|
2021-05-24 15:45:20 +00:00
|
|
|
use([BarChart, LineChart, CanvasRenderer, TitleComponent, TooltipComponent, LegendComponent]);
|
|
|
|
|
2020-08-17 18:39:14 +00:00
|
|
|
// Define Column labels here to avoid typos
|
|
|
|
const CHART_ABS_PROFIT = 'Absolute profit';
|
|
|
|
const CHART_TRADE_COUNT = 'Trade Count';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
'v-chart': ECharts,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class DailyChart extends Vue {
|
2020-08-17 18:42:37 +00:00
|
|
|
@Prop({ required: true }) dailyStats!: DailyReturnValue;
|
2020-08-17 18:39:14 +00:00
|
|
|
|
2020-08-31 15:47:26 +00:00
|
|
|
@Prop({ default: true, type: Boolean }) showTitle!: boolean;
|
|
|
|
|
2020-12-28 19:34:54 +00:00
|
|
|
@Getter getChartTheme!: string;
|
|
|
|
|
2020-08-18 18:51:16 +00:00
|
|
|
get absoluteMin() {
|
|
|
|
return Number(
|
|
|
|
this.dailyStats.data.reduce(
|
|
|
|
(min, p) => (p.abs_profit < min ? p.abs_profit : min),
|
|
|
|
this.dailyStats.data[0].abs_profit,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get absoluteMax() {
|
|
|
|
return Number(
|
|
|
|
this.dailyStats.data.reduce(
|
|
|
|
(max, p) => (p.abs_profit > max ? p.abs_profit : max),
|
|
|
|
this.dailyStats.data[0].abs_profit,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-24 14:39:02 +00:00
|
|
|
get dailyChartOptions(): EChartsOption {
|
2020-08-17 18:39:14 +00:00
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
text: 'Daily profit',
|
2020-08-31 15:47:26 +00:00
|
|
|
show: this.showTitle,
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
|
|
|
dataset: {
|
|
|
|
dimensions: ['date', 'abs_profit', 'trade_count'],
|
|
|
|
source: this.dailyStats.data,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'line',
|
|
|
|
label: {
|
|
|
|
backgroundColor: '#6a7985',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
data: [CHART_ABS_PROFIT, CHART_TRADE_COUNT],
|
2020-08-19 17:27:59 +00:00
|
|
|
right: '5%',
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: 'category',
|
|
|
|
inverse: true,
|
|
|
|
},
|
2020-10-04 17:24:21 +00:00
|
|
|
visualMap: [
|
|
|
|
{
|
|
|
|
dimension: 1,
|
|
|
|
seriesIndex: 0,
|
|
|
|
show: false,
|
|
|
|
pieces: [
|
|
|
|
{
|
2021-04-10 07:14:21 +00:00
|
|
|
max: 0.0,
|
2021-04-10 11:47:25 +00:00
|
|
|
min: this.absoluteMin,
|
2020-10-04 17:24:21 +00:00
|
|
|
color: 'red',
|
|
|
|
},
|
|
|
|
{
|
2021-04-10 07:14:21 +00:00
|
|
|
min: 0.0,
|
2021-04-10 11:47:25 +00:00
|
|
|
max: this.absoluteMax,
|
2020-10-04 17:24:21 +00:00
|
|
|
color: 'green',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2020-08-17 18:39:14 +00:00
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_ABS_PROFIT,
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
2021-02-10 09:30:27 +00:00
|
|
|
nameGap: 50,
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_TRADE_COUNT,
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameGap: 30,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: 'line',
|
|
|
|
name: CHART_ABS_PROFIT,
|
2020-10-04 17:24:21 +00:00
|
|
|
// Color is induced by visualMap
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'bar',
|
|
|
|
name: CHART_TRADE_COUNT,
|
2020-10-04 17:24:21 +00:00
|
|
|
itemStyle: {
|
|
|
|
color: 'rgba(150,150,150,0.3)',
|
|
|
|
},
|
2020-08-17 18:39:14 +00:00
|
|
|
yAxisIndex: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2020-08-18 05:05:40 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.echarts {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|