Remove unnecessary computed property

This commit is contained in:
Matthias 2023-04-28 19:56:37 +02:00
parent e66078b798
commit 6d6cd66aba

View File

@ -99,10 +99,6 @@ const timeframe = computed(() => {
return props.dataset ? props.dataset.timeframe : ''; return props.dataset ? props.dataset.timeframe : '';
}); });
const datasetColumns = computed(() => {
return props.dataset ? props.dataset.columns : [];
});
const hasData = computed(() => { const hasData = computed(() => {
return props.dataset !== null && typeof props.dataset === 'object'; return props.dataset !== null && typeof props.dataset === 'object';
}); });
@ -122,25 +118,23 @@ function updateChart(initial = false) {
if (chartOptions.value?.title) { if (chartOptions.value?.title) {
chartOptions.value.title[0].text = chartTitle.value; chartOptions.value.title[0].text = chartTitle.value;
} }
const colDate = props.dataset.columns.findIndex((el) => el === '__date_ts'); const columns = props.dataset.columns;
const colOpen = props.dataset.columns.findIndex((el) => el === 'open');
const colHigh = props.dataset.columns.findIndex((el) => el === 'high'); const colDate = columns.findIndex((el) => el === '__date_ts');
const colLow = props.dataset.columns.findIndex((el) => el === 'low'); const colOpen = columns.findIndex((el) => el === 'open');
const colClose = props.dataset.columns.findIndex((el) => el === 'close'); const colHigh = columns.findIndex((el) => el === 'high');
const colVolume = props.dataset.columns.findIndex((el) => el === 'volume'); const colLow = columns.findIndex((el) => el === 'low');
const colEntryData = props.dataset.columns.findIndex( const colClose = columns.findIndex((el) => el === 'close');
const colVolume = columns.findIndex((el) => el === 'volume');
const colEntryData = columns.findIndex(
(el) => el === '_buy_signal_close' || el === '_enter_long_signal_close', (el) => el === '_buy_signal_close' || el === '_enter_long_signal_close',
); );
const colExitData = props.dataset.columns.findIndex( const colExitData = columns.findIndex(
(el) => el === '_sell_signal_close' || el === '_exit_long_signal_close', (el) => el === '_sell_signal_close' || el === '_exit_long_signal_close',
); );
const colShortEntryData = props.dataset.columns.findIndex( const colShortEntryData = columns.findIndex((el) => el === '_enter_short_signal_close');
(el) => el === '_enter_short_signal_close', const colShortExitData = columns.findIndex((el) => el === '_exit_short_signal_close');
);
const colShortExitData = props.dataset.columns.findIndex(
(el) => el === '_exit_short_signal_close',
);
const subplotCount = const subplotCount =
'subplots' in props.plotConfig ? Object.keys(props.plotConfig.subplots).length + 1 : 1; 'subplots' in props.plotConfig ? Object.keys(props.plotConfig.subplots).length + 1 : 1;
@ -165,12 +159,13 @@ function updateChart(initial = false) {
} }
} }
const dataset = props.heikinAshi const dataset = props.heikinAshi
? heikinashi(datasetColumns.value, props.dataset.data) ? heikinashi(columns, props.dataset.data)
: props.dataset.data.slice(); : props.dataset.data.slice();
// Add new rows to end to allow slight "scroll past" // Add new rows to end to allow slight "scroll past"
const newArray = Array(dataset.length > 0 ? dataset[dataset.length - 2].length : 0); const newArray = Array(dataset.length > 0 ? dataset[dataset.length - 2].length : 0);
newArray[colDate] = dataset[dataset.length - 1][colDate] + props.dataset.timeframe_ms * 3; newArray[colDate] = dataset[dataset.length - 1][colDate] + props.dataset.timeframe_ms * 3;
dataset.push(newArray); dataset.push(newArray);
const options: EChartsOption = { const options: EChartsOption = {
dataset: { dataset: {
source: dataset, source: dataset,
@ -317,7 +312,7 @@ function updateChart(initial = false) {
if ('main_plot' in props.plotConfig) { if ('main_plot' in props.plotConfig) {
Object.entries(props.plotConfig.main_plot).forEach(([key, value]) => { Object.entries(props.plotConfig.main_plot).forEach(([key, value]) => {
const col = props.dataset.columns.findIndex((el) => el === key); const col = columns.findIndex((el) => el === key);
if (col > 1) { if (col > 1) {
if (!Array.isArray(chartOptions.value?.legend) && chartOptions.value?.legend?.data) { if (!Array.isArray(chartOptions.value?.legend) && chartOptions.value?.legend?.data) {
chartOptions.value.legend.data.push(key); chartOptions.value.legend.data.push(key);
@ -398,7 +393,7 @@ function updateChart(initial = false) {
} }
Object.entries(value).forEach(([sk, sv]) => { Object.entries(value).forEach(([sk, sv]) => {
// entries per subplot // entries per subplot
const col = props.dataset.columns.findIndex((el) => el === sk); const col = columns.findIndex((el) => el === sk);
if (col > 0) { if (col > 0) {
if (!Array.isArray(chartOptions.value.legend) && chartOptions.value.legend?.data) { if (!Array.isArray(chartOptions.value.legend) && chartOptions.value.legend?.data) {
chartOptions.value.legend.data.push(sk); chartOptions.value.legend.data.push(sk);