Introduce Candlechart container

This commit is contained in:
Matthias 2020-08-08 15:37:18 +02:00
parent 154e9fed3d
commit 9f121c9c32
3 changed files with 78 additions and 41 deletions

View File

@ -1,27 +1,6 @@
<template> <template>
<div class="container-fluid flex-column align-items-stretch d-flex"> <div class="row flex-grow-1 chart-wrapper">
<b-modal <v-chart v-if="hasData" theme="dark" autoresize :options="chartOptions" />
id="plotConfiguratorModal"
title="Plot Configurator"
ok-only
hide-backdrop
button-size="sm"
>
<PlotConfigurator :columns="datasetColumns" v-model="plotConfig" />
</b-modal>
<div class="row ml-auto">
<div class="col-mb-2 mr-2">
<b-checkbox v-model="useUTC" title="Use UTC for graph">useUtc</b-checkbox>
</div>
<div class="col-mb-2 mr-3">
<b-button @click="showConfigurator" size="sm" title="Plot configurator">
&#9881;
</b-button>
</div>
</div>
<div class="row flex-grow-1 chart-wrapper">
<v-chart v-if="hasData" theme="dark" autoresize :options="chartOptions" />
</div>
</div> </div>
</template> </template>
@ -29,12 +8,10 @@
import { Component, Vue, Prop, Watch } from 'vue-property-decorator'; import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import ECharts from 'vue-echarts'; import ECharts from 'vue-echarts';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { Trade, PairHistory, PlotConfig, EMPTY_PLOTCONFIG } from '@/store/types'; import { Trade, PairHistory, PlotConfig } from '@/store/types';
import randomColor from '@/shared/randomColor'; import randomColor from '@/shared/randomColor';
import { roundTimeframe } from '@/shared/timemath'; import { roundTimeframe } from '@/shared/timemath';
import { timestampms } from '@/shared/formatters'; import { timestampms } from '@/shared/formatters';
import PlotConfigurator from '@/components/ftbot/PlotConfigurator.vue';
import { loadCustomPlotConfig, loadPlotConfigName } from '@/shared/storage';
import 'echarts'; import 'echarts';
@ -47,7 +24,7 @@ const downColor = '#ec0000';
const downBorderColor = '#8A0000'; const downBorderColor = '#8A0000';
@Component({ @Component({
components: { 'v-chart': ECharts, PlotConfigurator }, components: { 'v-chart': ECharts },
}) })
export default class CandleChart extends Vue { export default class CandleChart extends Vue {
@Prop({ required: true }) readonly timeframe!: string; @Prop({ required: true }) readonly timeframe!: string;
@ -58,9 +35,9 @@ export default class CandleChart extends Vue {
@Prop({ required: true }) readonly dataset!: PairHistory; @Prop({ required: true }) readonly dataset!: PairHistory;
plotConfig: PlotConfig = { ...EMPTY_PLOTCONFIG }; @Prop({ default: true }) readonly useUTC!: boolean;
useUTC = true; @Prop({ required: true }) plotConfig!: PlotConfig;
// Only recalculate buy / sell data if necessary // Only recalculate buy / sell data if necessary
signalsCalculated = false; signalsCalculated = false;
@ -69,14 +46,6 @@ export default class CandleChart extends Vue {
sellData = [] as Array<number>[]; sellData = [] as Array<number>[];
mounted() {
this.plotConfig = loadCustomPlotConfig(loadPlotConfigName());
}
showConfigurator() {
this.$bvModal.show('plotConfiguratorModal');
}
@Watch('timeframe') @Watch('timeframe')
timeframeChanged() { timeframeChanged() {
this.signalsCalculated = false; this.signalsCalculated = false;

View File

@ -0,0 +1,68 @@
<template>
<div class="container-fluid flex-column align-items-stretch d-flex">
<b-modal
id="plotConfiguratorModal"
title="Plot Configurator"
ok-only
hide-backdrop
button-size="sm"
>
<PlotConfigurator :columns="datasetColumns" v-model="plotConfig" />
</b-modal>
<div class="row ml-auto">
<div class="col-mb-2 mr-2">
<b-checkbox v-model="useUTC" title="Use UTC for graph">useUtc</b-checkbox>
</div>
<div class="col-mb-2 mr-3">
<b-button @click="showConfigurator" size="sm" title="Plot configurator">
&#9881;
</b-button>
</div>
</div>
<CandleChart
:timeframe="timeframe"
:timeframems="timeframems"
:dataset="dataset"
:trades="trades"
:plotConfig="plotConfig"
>
</CandleChart>
</div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { Trade, PairHistory, EMPTY_PLOTCONFIG, PlotConfig } from '@/store/types';
import CandleChart from '@/components/ftbot/CandleChart.vue';
import PlotConfigurator from '@/components/ftbot/PlotConfigurator.vue';
import { loadCustomPlotConfig, loadPlotConfigName } from '../../shared/storage';
@Component({ components: { CandleChart, PlotConfigurator } })
export default class CandleChartContainer extends Vue {
@Prop({ required: true }) readonly timeframe!: string;
@Prop({ required: true }) readonly timeframems!: number;
@Prop({ required: false, default: [] }) readonly trades!: Array<Trade>;
@Prop({ required: true }) readonly dataset!: PairHistory;
useUTC = true;
plotConfig: PlotConfig = { ...EMPTY_PLOTCONFIG };
get datasetColumns() {
return this.dataset ? this.dataset.columns : [];
}
mounted() {
this.plotConfig = loadCustomPlotConfig(loadPlotConfigName());
}
showConfigurator() {
this.$bvModal.show('plotConfiguratorModal');
}
}
</script>
<style></style>

View File

@ -22,14 +22,14 @@
</div> </div>
<div class="row"> <div class="row">
<CandleChart <CandleChartContainer
:pair="pair" :pair="pair"
:timeframe="timeframe" :timeframe="timeframe"
:timeframems="timeframems" :timeframems="timeframems"
:dataset="dataset" :dataset="dataset"
:trades="trades" :trades="trades"
> >
</CandleChart> </CandleChartContainer>
</div> </div>
</div> </div>
</template> </template>
@ -37,7 +37,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator'; import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class'; import { namespace } from 'vuex-class';
import CandleChart from '@/components/ftbot/CandleChart.vue'; import CandleChartContainer from '@/components/ftbot/CandleChartContainer.vue';
import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue'; import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue';
import StrategyList from '@/components/ftbot/StrategyList.vue'; import StrategyList from '@/components/ftbot/StrategyList.vue';
import { AvailablePairPayload, PairCandlePayload, PairHistoryPayload } from '@/store/types'; import { AvailablePairPayload, PairCandlePayload, PairHistoryPayload } from '@/store/types';
@ -45,7 +45,7 @@ import { AvailablePairPayload, PairCandlePayload, PairHistoryPayload } from '@/s
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
@Component({ @Component({
components: { CandleChart, StrategyList, TimeRangeSelect }, components: { CandleChartContainer, StrategyList, TimeRangeSelect },
}) })
export default class Graphs extends Vue { export default class Graphs extends Vue {
pair = 'XRP/USDT'; pair = 'XRP/USDT';