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">
|
|
|
|
<b-form-group label-cols="auto" label="Plot Section" label-for="FieldSel">
|
|
|
|
<b-form-radio v-model="plotOption" name="plot_section" value="main_plot">
|
|
|
|
Main Plot
|
|
|
|
</b-form-radio>
|
|
|
|
<b-form-radio v-model="plotOption" name="plot_section" value="subplots">
|
|
|
|
Subplots
|
|
|
|
</b-form-radio>
|
|
|
|
</b-form-group>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
2020-07-01 18:22:29 +00:00
|
|
|
<div class="col-mb-3 ml-2" v-if="plotOption == 'subplots'">
|
2020-07-01 18:59:45 +00:00
|
|
|
<b-form-group label="Target field" label-for="FieldSel">
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-form-select id="FieldSel" :options="subplots" v-model="selField" :select-size="4">
|
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
</div>
|
|
|
|
<b-form-group v-if="plotOption == 'subplots'" label="New subplot" label-for="newSubplot">
|
2020-07-01 18:39:03 +00:00
|
|
|
<b-input-group>
|
|
|
|
<b-form-input class="addPlot" id="newSubplot" v-model="newSubplotName"></b-form-input>
|
|
|
|
<b-input-group-append>
|
|
|
|
<b-button @click="addSubplot">+</b-button>
|
|
|
|
<b-button @click="delSubplot" v-if="selField">-</b-button>
|
|
|
|
</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-07-01 18:22:29 +00:00
|
|
|
|
|
|
|
<b-form-group label="Choose column" label-for="columnSelector">
|
|
|
|
<b-form-select id="columnSelector" :options="columns" v-model="selColumn"> </b-form-select>
|
|
|
|
</b-form-group>
|
2020-07-01 18:59:45 +00:00
|
|
|
|
|
|
|
<b-form-group label="Choose type" label-for="columnSelector">
|
|
|
|
<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
|
|
|
|
|
|
|
<b-form-group label="Color" label-for="colsel">
|
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>
|
|
|
|
<b-form-input id="colsel" v-model="selColor"> </b-form-input>
|
|
|
|
<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-07-01 18:22:29 +00:00
|
|
|
<div class="row">
|
2020-07-01 05:16:05 +00:00
|
|
|
<div class="col-mb-3 ml-2">
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-button variant="primary" @click="addBar" title="Add configuration to plot" size="sm">
|
|
|
|
Add
|
|
|
|
</b-button>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-mb-3 ml-2">
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-button variant="primary" @click="loadPlotConfig" size="sm">Load</b-button>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
|
|
|
<div class="col-mb-3 ml-2">
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-button
|
|
|
|
variant="primary"
|
|
|
|
@click="savePlotConfig"
|
|
|
|
size="sm"
|
|
|
|
data-toggle="tooltip"
|
|
|
|
title="Save configuration"
|
|
|
|
>Save</b-button
|
|
|
|
>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
|
|
|
<div class="col-mb-3 ml-2">
|
2020-07-01 18:22:29 +00:00
|
|
|
<b-button
|
|
|
|
id="showButton"
|
|
|
|
variant="primary"
|
|
|
|
@click="showConfig = !showConfig"
|
|
|
|
size="sm"
|
|
|
|
title="Show configuration for easy transfer to a strategy"
|
|
|
|
>Show</b-button
|
|
|
|
>
|
2020-07-01 05:16:05 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-01 18:22:29 +00:00
|
|
|
<div class="col-mb-5 ml-2" v-if="showConfig">
|
|
|
|
<b-textarea id="TextArea" class="textArea" v-model="plotConfigJson" size="sm"> </b-textarea>
|
|
|
|
</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';
|
|
|
|
import { PlotConfig, EMPTY_PLOTCONFIG } from '../../store/types';
|
|
|
|
import randomColor from '../../shared/randomColor';
|
|
|
|
import { loadCustomPlotConfig } from '../../shared/storage';
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
plotConfig: PlotConfig = EMPTY_PLOTCONFIG;
|
|
|
|
|
|
|
|
plotOption = 'main_plot';
|
|
|
|
|
|
|
|
newSubplotName = '';
|
|
|
|
|
|
|
|
selColumn = '';
|
|
|
|
|
2020-07-01 18:59:45 +00:00
|
|
|
graphType = 'line';
|
|
|
|
|
|
|
|
availableGraphTypes = ['line', 'bar', 'scatter'];
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
showConfig = false;
|
|
|
|
|
|
|
|
selField = '';
|
|
|
|
|
|
|
|
selColor = randomColor();
|
|
|
|
|
|
|
|
@ftbot.Mutation
|
|
|
|
saveCustomPlotConfig;
|
|
|
|
|
|
|
|
get plotConfigJson() {
|
|
|
|
return JSON.stringify(this.plotConfig, null, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
get subplots() {
|
|
|
|
// Subplot keys (for selection window)
|
|
|
|
return Object.keys(this.plotConfig.subplots);
|
|
|
|
}
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
console.log('mounted');
|
|
|
|
this.plotConfig = this.value;
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:22:29 +00:00
|
|
|
newColor() {
|
|
|
|
this.selColor = randomColor();
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
addBar() {
|
|
|
|
console.log(this.plotConfig);
|
|
|
|
|
|
|
|
const { plotConfig } = this;
|
|
|
|
if (this.plotOption === 'main_plot') {
|
|
|
|
console.log(`Adding ${this.selColumn} to MainPlot`);
|
|
|
|
console.log(plotConfig);
|
2020-07-01 18:59:45 +00:00
|
|
|
plotConfig[this.plotOption][this.selColumn] = { color: this.selColor, type: this.graphType };
|
2020-07-01 05:16:05 +00:00
|
|
|
} else {
|
|
|
|
console.log(`Adding ${this.selColumn} to ${this.selField}`);
|
2020-07-01 18:59:45 +00:00
|
|
|
plotConfig[this.plotOption][this.selField][this.selColumn] = {
|
|
|
|
color: this.selColor,
|
|
|
|
type: this.graphType,
|
|
|
|
};
|
2020-07-01 05:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.plotConfig = { ...plotConfig };
|
|
|
|
// Reset random color
|
2020-07-01 18:22:29 +00:00
|
|
|
this.newColor();
|
2020-07-01 05:16:05 +00:00
|
|
|
console.log(this.plotConfig);
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
addSubplot() {
|
|
|
|
this.plotConfig.subplots = {
|
|
|
|
...this.plotConfig.subplots,
|
|
|
|
[this.newSubplotName]: {},
|
|
|
|
};
|
|
|
|
this.selField = this.newSubplotName;
|
|
|
|
this.newSubplotName = '';
|
|
|
|
console.log(this.plotConfig);
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:22:29 +00:00
|
|
|
delSubplot() {
|
|
|
|
delete this.plotConfig.subplots[this.selField];
|
|
|
|
this.plotConfig.subplots = { ...this.plotConfig.subplots };
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:16:05 +00:00
|
|
|
savePlotConfig() {
|
|
|
|
this.saveCustomPlotConfig(this.plotConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPlotConfig() {
|
|
|
|
this.plotConfig = loadCustomPlotConfig();
|
|
|
|
console.log(this.plotConfig);
|
|
|
|
console.log('loading config');
|
|
|
|
this.emitPlotConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</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%;
|
|
|
|
margin-top: 15%;
|
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-07-01 05:16:05 +00:00
|
|
|
</style>
|