From de50ed88d957354d41e8b83802a657fd1e509bca Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Jun 2022 23:09:26 +0200 Subject: [PATCH] Support not having an exit column --- src/components/charts/CandleChart.vue | 90 ++++++++++++++++----------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/src/components/charts/CandleChart.vue b/src/components/charts/CandleChart.vue index b41ffb6c..f5eeb7d3 100644 --- a/src/components/charts/CandleChart.vue +++ b/src/components/charts/CandleChart.vue @@ -280,7 +280,15 @@ export default defineComponent({ y: colBuyData, }, }, - { + ], + }; + + if (colSellData >= 0) { + if (!Array.isArray(chartOptions.value?.legend) && chartOptions.value?.legend?.data) { + chartOptions.value.legend.data.push('Long exit'); + } + if (Array.isArray(options.series)) { + options.series.push({ name: 'Long exit', type: 'scatter', symbol: 'diamond', @@ -294,47 +302,55 @@ export default defineComponent({ x: colDate, y: colSellData, }, - }, - ], - }; + }); + } + } if (hasShorts) { // Add short support if (!Array.isArray(chartOptions.value?.legend) && chartOptions.value?.legend?.data) { - chartOptions.value.legend.data.push('Short'); - chartOptions.value.legend.data.push('Short exit'); + if (colShortEntryData >= 0) { + chartOptions.value.legend.data.push('Short'); + } + if (colShortExitData >= 0) { + chartOptions.value.legend.data.push('Short exit'); + } } if (Array.isArray(options.series)) { - options.series.push({ - name: 'Short', - type: 'scatter', - symbol: 'pin', - symbolSize: 10, - xAxisIndex: 0, - yAxisIndex: 0, - itemStyle: { - color: shortEntrySignalColor, - }, - encode: { - x: colDate, - y: colShortEntryData, - }, - }); - options.series.push({ - name: 'Short exit', - type: 'scatter', - symbol: 'pin', - symbolSize: 8, - xAxisIndex: 0, - yAxisIndex: 0, - itemStyle: { - color: shortexitSignalColor, - }, - encode: { - x: colDate, - y: colShortExitData, - }, - }); + if (colShortEntryData >= 0) { + options.series.push({ + name: 'Short', + type: 'scatter', + symbol: 'pin', + symbolSize: 10, + xAxisIndex: 0, + yAxisIndex: 0, + itemStyle: { + color: shortEntrySignalColor, + }, + encode: { + x: colDate, + y: colShortEntryData, + }, + }); + } + if (colShortExitData >= 0) { + options.series.push({ + name: 'Short exit', + type: 'scatter', + symbol: 'pin', + symbolSize: 8, + xAxisIndex: 0, + yAxisIndex: 0, + itemStyle: { + color: shortexitSignalColor, + }, + encode: { + x: colDate, + y: colShortExitData, + }, + }); + } } } @@ -526,7 +542,7 @@ export default defineComponent({ animation: false, legend: { // Initial legend, further entries are pushed to the below list - data: ['Candles', 'Volume', 'Long', 'Long exit'], + data: ['Candles', 'Volume', 'Long'], right: '1%', }, tooltip: {