From 44c6299c10a57f1c25859938df0684419d238c40 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 13 Aug 2022 15:35:31 +0200 Subject: [PATCH] Fix cum-profit chart not updating --- src/components/charts/CumProfitChart.vue | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/components/charts/CumProfitChart.vue b/src/components/charts/CumProfitChart.vue index 783ae58b..a6e098c2 100644 --- a/src/components/charts/CumProfitChart.vue +++ b/src/components/charts/CumProfitChart.vue @@ -18,7 +18,7 @@ import { } from 'echarts/components'; import { ClosedTrade, CumProfitData, CumProfitDataPerDate } from '@/types'; -import { defineComponent, ref, computed, watch } from 'vue'; +import { defineComponent, computed, ComputedRef } from 'vue'; import { useSettingsStore } from '@/stores/settings'; use([ @@ -49,12 +49,10 @@ export default defineComponent({ }, setup(props) { const settingsStore = useSettingsStore(); - const botList = ref([]); - const cumulativeData = ref<{ date: number; profit: any }[]>([]); + // const botList = ref([]); + // const cumulativeData = ref<{ date: number; profit: any }[]>([]); - const calcCumulativeData = () => { - console.log('trades'); - botList.value = []; + const cumulativeData: ComputedRef<{ date: number; profit: number }[]> = computed(() => { const res: CumProfitData[] = []; const resD: CumProfitDataPerDate = {}; const closedTrades = props.trades @@ -79,16 +77,12 @@ export default defineComponent({ resD[trade.close_timestamp][trade.botId] = profit; } } - // console.log(trade.close_date, profit); res.push({ date: trade.close_timestamp, profit, [trade.botId]: profit }); - if (!botList.value.includes(trade.botId)) { - botList.value.push(trade.botId); - } } } // console.log(resD); - cumulativeData.value = Object.entries(resD).map(([k, v]) => { + return Object.entries(resD).map(([k, v]) => { const obj = { date: parseInt(k, 10), profit: v.profit }; // TODO: The below could allow "lines" per bot" // this.botList.forEach((botId) => { @@ -96,10 +90,7 @@ export default defineComponent({ // }); return obj; }); - }; - watch([props.trades], calcCumulativeData); - // Initial call - calcCumulativeData(); + }); const chartOptions = computed((): EChartsOption => { const chartOptionsLoc: EChartsOption = {