2020-07-01 05:16:05 +00:00
|
|
|
<template>
|
2020-07-01 18:22:29 +00:00
|
|
|
<div v-if="columns">
|
|
|
|
<div class="col-mb-3 ml-2">
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-form-radio-group
|
|
|
|
class="w-100"
|
|
|
|
v-model="plotOption"
|
|
|
|
:options="plotOptions"
|
|
|
|
buttons
|
|
|
|
button-variant="outline-primary"
|
|
|
|
>
|
|
|
|
</b-form-radio-group>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
2020-08-01 18:43:14 +00:00
|
|
|
<div class="col-mb-3" v-if="plotOption == 'subplots'">
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<b-form-group label="Subplot" label-for="FieldSel">
|
|
|
|
<b-form-select id="FieldSel" :options="subplots" v-model="selSubPlot" :select-size="4">
|
2020-07-01 18:22:29 +00:00
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
</div>
|
|
|
|
<b-form-group v-if="plotOption == 'subplots'" label="New subplot" label-for="newSubplot">
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-input-group size="sm">
|
2020-07-01 18:39:03 +00:00
|
|
|
<b-form-input class="addPlot" id="newSubplot" v-model="newSubplotName"></b-form-input>
|
|
|
|
<b-input-group-append>
|
|
|
|
<b-button @click="addSubplot">+</b-button>
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-button @click="delSubplot" v-if="selSubPlot">-</b-button>
|
2020-07-01 18:39:03 +00:00
|
|
|
</b-input-group-append>
|
|
|
|
</b-input-group>
|
2020-07-01 18:22:29 +00:00
|
|
|
</b-form-group>
|
2020-07-01 18:39:03 +00:00
|
|
|
<hr />
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-form-group label="Used indicators" label-for="selectedIndicators">
|
|
|
|
<b-form-select
|
|
|
|
id="selectedIndicators"
|
|
|
|
:options="usedColumns"
|
|
|
|
v-model="selIndicator"
|
|
|
|
:select-size="4"
|
|
|
|
>
|
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
<b-form-group label="Add indicator" label-for="indicatorSelector">
|
|
|
|
<b-form-select
|
|
|
|
id="indicatorSelector"
|
|
|
|
:options="columns"
|
|
|
|
v-model="selAvailableIndicator"
|
|
|
|
:select-size="4"
|
|
|
|
>
|
|
|
|
</b-form-select>
|
2020-07-01 18:22:29 +00:00
|
|
|
</b-form-group>
|
2020-07-01 18:59:45 +00:00
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-form-group label="Choose type" label-for="plotTypeSelector">
|
2020-07-01 18:59:45 +00:00
|
|
|
<b-form-select id="plotTypeSelector" :options="availableGraphTypes" v-model="graphType">
|
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
2020-07-01 18:39:03 +00:00
|
|
|
<hr />
|
2020-07-01 18:22:29 +00:00
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-form-group label="Color" label-for="colsel" size="sm">
|
2020-07-01 18:39:03 +00:00
|
|
|
<b-input-group>
|
|
|
|
<b-input-group-prepend>
|
|
|
|
<div v-bind:style="{ 'background-color': selColor }" class="colorbox mr-2"></div>
|
|
|
|
</b-input-group-prepend>
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-form-input id="colsel" v-model="selColor" size="sm"> </b-form-input>
|
2020-07-01 18:39:03 +00:00
|
|
|
<b-input-group-append>
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-button variant="primary" @click="newColor" size="sm">↻</b-button>
|
2020-07-01 18:39:03 +00:00
|
|
|
</b-input-group-append>
|
|
|
|
</b-input-group>
|
2020-07-01 18:22:29 +00:00
|
|
|
</b-form-group>
|
2020-07-01 18:39:03 +00:00
|
|
|
<hr />
|
2020-08-24 18:05:07 +00:00
|
|
|
<b-form-group label="Plot config name" label-for="idPlotConfigName">
|
|
|
|
<b-form-input id="idPlotConfigName" :options="availableGraphTypes" v-model="plotConfigName">
|
|
|
|
</b-form-input>
|
|
|
|
</b-form-group>
|
2020-07-01 18:22:29 +00:00
|
|
|
<div class="row">
|
2020-07-11 15:50:59 +00:00
|
|
|
<b-button
|
2020-08-01 18:43:14 +00:00
|
|
|
class="ml-1"
|
2020-07-11 15:50:59 +00:00
|
|
|
variant="primary"
|
2020-08-01 18:43:14 +00:00
|
|
|
@click="addIndicator"
|
|
|
|
title="Add indicator to plot"
|
2020-07-11 15:50:59 +00:00
|
|
|
size="sm"
|
2020-08-01 18:43:14 +00:00
|
|
|
:disabled="!selAvailableIndicator"
|
2020-07-11 15:50:59 +00:00
|
|
|
>
|
|
|
|
Add
|
|
|
|
</b-button>
|
2020-08-01 18:43:14 +00:00
|
|
|
<b-button
|
|
|
|
class="ml-1"
|
|
|
|
variant="primary"
|
|
|
|
@click="removeIndicator"
|
|
|
|
title="Remove indicator to plot"
|
|
|
|
size="sm"
|
|
|
|
:disabled="!selIndicator"
|
|
|
|
>
|
|
|
|
Remove
|
|
|
|
</b-button>
|
|
|
|
<b-button class="ml-1" variant="primary" @click="loadPlotConfig" size="sm">Load</b-button>
|
|
|
|
<b-button class="ml-1" variant="primary" @click="loadPlotConfigFromStrategy" size="sm">
|
2020-07-28 18:39:58 +00:00
|
|
|
Load from strategy
|
|
|
|
</b-button>
|
|
|
|
|
2020-07-11 15:50:59 +00:00
|
|
|
<b-button
|
2020-08-01 18:43:14 +00:00
|
|
|
class="ml-1"
|
2020-07-11 15:50:59 +00:00
|
|
|
variant="primary"
|
|
|
|
@click="savePlotConfig"
|
|
|
|
size="sm"
|
|
|
|
data-toggle="tooltip"
|
|
|
|
title="Save configuration"
|
|
|
|
>Save</b-button
|
|
|
|
>
|
|
|
|
<b-button
|
2020-08-01 18:43:14 +00:00
|
|
|
class="ml-1"
|
2020-07-11 15:50:59 +00:00
|
|
|
id="showButton"
|
|
|
|
variant="primary"
|
|
|
|
@click="showConfig = !showConfig"
|
|
|
|
size="sm"
|
|
|
|
title="Show configuration for easy transfer to a strategy"
|
|
|
|
>Show</b-button
|
|
|
|
>
|
|
|
|
<b-button
|
2020-08-01 18:43:14 +00:00
|
|
|
class="ml-1"
|
2020-07-11 15:50:59 +00:00
|
|
|
variant="primary"
|
|
|
|
@click="loadConfigFromString"
|
|
|
|
size="sm"
|
|
|
|
v-if="showConfig"
|
|
|
|
title="Load configuration from text box below"
|
|
|
|
>Load from String</b-button
|
|
|
|
>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
2020-07-11 15:41:33 +00:00
|
|
|
<div class="col-mb-5 ml-2 mt-2" v-if="showConfig">
|
|
|
|
<b-textarea
|
|
|
|
id="TextArea"
|
|
|
|
class="textArea"
|
|
|
|
v-model="plotConfigJson"
|
|
|
|
size="sm"
|
|
|
|
:state="tempPlotConfigValid"
|
|
|
|
>
|
|
|
|
</b-textarea>
|
2020-07-01 18:22:29 +00:00
|
|
|
</div>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue, Prop, Emit } from 'vue-property-decorator';
|
|
|
|
import { namespace } from 'vuex-class';
|
2020-07-24 05:57:14 +00:00
|
|
|
import { PlotConfig, EMPTY_PLOTCONFIG } from '@/store/types';
|
|
|
|
import randomColor from '@/shared/randomColor';
|
|
|
|
import { loadCustomPlotConfig } from '@/shared/storage';
|
2020-07-01 05:16:05 +00:00
|
|
|
|
|
|
|
const ftbot = namespace('ftbot');
|
|
|
|
|
|
|
|
@Component({})
|
|
|
|
export default class PlotConfigurator extends Vue {
|
|
|
|
@Prop({ required: true }) value!: PlotConfig;
|
|
|
|
|
|
|
|
@Prop({ required: true }) columns!: Array<string>;
|
|
|
|
|
|
|
|
@Emit('input')
|
|
|
|
emitPlotConfig() {
|
|
|
|
return this.plotConfig;
|
|
|
|
}
|
|
|
|
|
2020-08-07 04:57:05 +00:00
|
|
|
@ftbot.Action getStrategyPlotConfig;
|
2020-07-28 18:39:58 +00:00
|
|
|
|
|
|
|
@ftbot.State strategyPlotConfig;
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
plotConfig: PlotConfig = EMPTY_PLOTCONFIG;
|
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
plotOptions = [
|
|
|
|
{ text: 'Main Plot', value: 'main_plot' },
|
|
|
|
{ text: 'Subplots', value: 'subplots' },
|
|
|
|
];
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
plotOption = 'main_plot';
|
|
|
|
|
2020-08-24 18:05:07 +00:00
|
|
|
plotConfigName = 'default';
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
newSubplotName = '';
|
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
selAvailableIndicator = '';
|
|
|
|
|
|
|
|
selIndicator = '';
|
2020-07-01 05:16:05 +00:00
|
|
|
|
2020-07-01 18:59:45 +00:00
|
|
|
graphType = 'line';
|
|
|
|
|
|
|
|
availableGraphTypes = ['line', 'bar', 'scatter'];
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
showConfig = false;
|
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
selSubPlot = '';
|
2020-07-01 05:16:05 +00:00
|
|
|
|
2020-07-11 15:41:33 +00:00
|
|
|
tempPlotConfig?: PlotConfig = undefined;
|
|
|
|
|
|
|
|
tempPlotConfigValid = true;
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
selColor = randomColor();
|
|
|
|
|
2020-08-24 18:05:07 +00:00
|
|
|
@ftbot.Mutation saveCustomPlotConfig;
|
|
|
|
|
|
|
|
@ftbot.Mutation updatePlotConfigName!: (plotConfigName: string) => void;
|
2020-07-01 05:16:05 +00:00
|
|
|
|
2020-08-08 13:25:58 +00:00
|
|
|
@ftbot.State('plotConfigName') usedPlotConfigName!: string;
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
get plotConfigJson() {
|
|
|
|
return JSON.stringify(this.plotConfig, null, 2);
|
|
|
|
}
|
|
|
|
|
2020-07-11 15:41:33 +00:00
|
|
|
set plotConfigJson(newValue: string) {
|
|
|
|
try {
|
|
|
|
this.tempPlotConfig = JSON.parse(newValue);
|
|
|
|
// TODO: Should Validate schema validity (should be PlotConfig type...)
|
|
|
|
this.tempPlotConfigValid = true;
|
|
|
|
} catch (err) {
|
|
|
|
this.tempPlotConfigValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
get subplots() {
|
|
|
|
// Subplot keys (for selection window)
|
|
|
|
return Object.keys(this.plotConfig.subplots);
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
get usedColumns() {
|
|
|
|
if (this.isMainPlot) {
|
|
|
|
return Object.keys(this.plotConfig.main_plot);
|
|
|
|
}
|
|
|
|
if (this.selSubPlot in this.plotConfig[this.plotOption]) {
|
|
|
|
return Object.keys(this.plotConfig[this.plotOption][this.selSubPlot]);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
get isMainPlot() {
|
|
|
|
return this.plotOption === 'main_plot';
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
mounted() {
|
|
|
|
this.plotConfig = this.value;
|
2020-08-08 13:25:58 +00:00
|
|
|
this.plotConfigName = this.usedPlotConfigName;
|
2020-07-01 05:16:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:22:29 +00:00
|
|
|
newColor() {
|
|
|
|
this.selColor = randomColor();
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:43:14 +00:00
|
|
|
addIndicator() {
|
2020-07-01 05:16:05 +00:00
|
|
|
console.log(this.plotConfig);
|
|
|
|
|
|
|
|
const { plotConfig } = this;
|
2020-08-01 18:43:14 +00:00
|
|
|
if (this.isMainPlot) {
|
|
|
|
console.log(`Adding ${this.selAvailableIndicator} to MainPlot`);
|
|
|
|
plotConfig[this.plotOption][this.selAvailableIndicator] = {
|
|
|
|
color: this.selColor,
|
|
|
|
type: this.graphType,
|
|
|
|
};
|
2020-07-01 05:16:05 +00:00
|
|
|
} else {
|
2020-08-01 18:43:14 +00:00
|
|
|
console.log(`Adding ${this.selAvailableIndicator} to ${this.selSubPlot}`);
|
|
|
|
plotConfig[this.plotOption][this.selSubPlot][this.selAvailableIndicator] = {
|
2020-07-01 18:59:45 +00:00
|
|
|
color: this.selColor,
|
|
|
|
type: this.graphType,
|
|
|
|
};
|
2020-07-01 05:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.plotConfig = { ...plotConfig };
|
2020-08-01 18:43:14 +00:00
|
|
|
this.selAvailableIndicator = '';
|
2020-07-01 05:16:05 +00:00
|
|
|
// Reset random color
|
2020-07-01 18:22:29 +00:00
|
|
|
this.newColor();
|
2020-08-01 18:43:14 +00:00
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
removeIndicator() {
|
2020-07-01 05:16:05 +00:00
|
|
|
console.log(this.plotConfig);
|
2020-08-01 18:43:14 +00:00
|
|
|
const { plotConfig } = this;
|
|
|
|
if (this.isMainPlot) {
|
|
|
|
console.log(`Removing ${this.selIndicator} from MainPlot`);
|
|
|
|
delete plotConfig[this.plotOption][this.selIndicator];
|
|
|
|
} else {
|
|
|
|
console.log(`Removing ${this.selIndicator} from ${this.selSubPlot}`);
|
|
|
|
delete plotConfig[this.plotOption][this.selSubPlot][this.selIndicator];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.plotConfig = { ...plotConfig };
|
|
|
|
console.log(this.plotConfig);
|
|
|
|
this.selIndicator = '';
|
2020-07-01 05:16:05 +00:00
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
addSubplot() {
|
|
|
|
this.plotConfig.subplots = {
|
|
|
|
...this.plotConfig.subplots,
|
|
|
|
[this.newSubplotName]: {},
|
|
|
|
};
|
2020-08-01 18:43:14 +00:00
|
|
|
this.selSubPlot = this.newSubplotName;
|
2020-07-01 05:16:05 +00:00
|
|
|
this.newSubplotName = '';
|
|
|
|
console.log(this.plotConfig);
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:22:29 +00:00
|
|
|
delSubplot() {
|
2020-08-01 18:43:14 +00:00
|
|
|
delete this.plotConfig.subplots[this.selSubPlot];
|
2020-07-01 18:22:29 +00:00
|
|
|
this.plotConfig.subplots = { ...this.plotConfig.subplots };
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
savePlotConfig() {
|
2020-08-24 18:05:07 +00:00
|
|
|
this.saveCustomPlotConfig({ [this.plotConfigName]: this.plotConfig });
|
2020-07-01 05:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadPlotConfig() {
|
2020-08-24 18:05:07 +00:00
|
|
|
this.plotConfig = loadCustomPlotConfig(this.plotConfigName);
|
2020-07-01 05:16:05 +00:00
|
|
|
console.log(this.plotConfig);
|
|
|
|
console.log('loading config');
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
2020-07-11 15:41:33 +00:00
|
|
|
|
|
|
|
loadConfigFromString() {
|
|
|
|
// this.plotConfig = JSON.parse();
|
|
|
|
if (this.tempPlotConfig !== undefined && this.tempPlotConfigValid) {
|
|
|
|
this.plotConfig = this.tempPlotConfig;
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 18:39:58 +00:00
|
|
|
|
|
|
|
async loadPlotConfigFromStrategy() {
|
2020-08-07 04:57:05 +00:00
|
|
|
await this.getStrategyPlotConfig();
|
2020-07-28 18:39:58 +00:00
|
|
|
this.plotConfig = this.strategyPlotConfig;
|
|
|
|
}
|
2020-07-01 05:16:05 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2020-07-01 18:22:29 +00:00
|
|
|
<style scoped>
|
|
|
|
.textArea {
|
|
|
|
min-height: 250px;
|
|
|
|
}
|
|
|
|
.colorbox {
|
2020-07-01 18:39:03 +00:00
|
|
|
border-radius: 50%;
|
2020-08-01 18:43:14 +00:00
|
|
|
margin-top: auto;
|
|
|
|
margin-bottom: auto;
|
2020-07-01 18:22:29 +00:00
|
|
|
height: 25px;
|
|
|
|
width: 25px;
|
2020-07-01 18:39:03 +00:00
|
|
|
vertical-align: center;
|
2020-07-01 18:22:29 +00:00
|
|
|
}
|
2020-08-01 18:43:14 +00:00
|
|
|
.form-group {
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
}
|
|
|
|
hr {
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
margin-top: 0.5rem;
|
|
|
|
}
|
2020-07-01 05:16:05 +00:00
|
|
|
</style>
|