2021-06-23 18:33:56 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div v-if="addNew">
|
|
|
|
<b-form-group label="Add indicator" label-for="indicatorSelector">
|
|
|
|
<b-form-select
|
|
|
|
id="indicatorSelector"
|
|
|
|
v-model="selAvailableIndicator"
|
|
|
|
:options="columns"
|
|
|
|
:select-size="4"
|
|
|
|
>
|
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<b-form-group label="Type" label-for="plotTypeSelector">
|
|
|
|
<b-form-select
|
|
|
|
id="plotTypeSelector"
|
|
|
|
v-model="graphType"
|
|
|
|
size="sm"
|
|
|
|
:options="availableGraphTypes"
|
|
|
|
@change="emitIndicator()"
|
|
|
|
>
|
|
|
|
</b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
<hr />
|
|
|
|
<b-form-group label="Color" label-for="colsel" size="sm">
|
|
|
|
<b-input-group>
|
|
|
|
<b-input-group-prepend>
|
|
|
|
<div :style="{ 'background-color': selColor }" class="colorbox mr-2"></div>
|
2021-06-23 18:47:17 +00:00
|
|
|
<!-- <b-form-input
|
|
|
|
id="colsel"
|
|
|
|
v-model="selColor"
|
|
|
|
size="sm"
|
|
|
|
class="colorbox"
|
|
|
|
type="color"
|
|
|
|
:style="{ 'background-color': selColor }"
|
|
|
|
>
|
|
|
|
</b-form-input> -->
|
2021-06-23 18:33:56 +00:00
|
|
|
</b-input-group-prepend>
|
2021-06-23 18:47:17 +00:00
|
|
|
|
2021-06-23 18:33:56 +00:00
|
|
|
<b-form-input id="colsel" v-model="selColor" size="sm"> </b-form-input>
|
|
|
|
<b-input-group-append>
|
|
|
|
<b-button variant="primary" size="sm" @click="newColor">↻</b-button>
|
|
|
|
</b-input-group-append>
|
|
|
|
</b-input-group>
|
|
|
|
</b-form-group>
|
2021-12-11 16:20:57 +00:00
|
|
|
<div class="d-flex d-flex-columns">
|
2021-11-01 18:53:06 +00:00
|
|
|
<b-button
|
|
|
|
v-if="addNew"
|
|
|
|
class="flex-grow-1"
|
|
|
|
variant="primary"
|
|
|
|
title="Add "
|
|
|
|
size="sm"
|
|
|
|
@click="emitIndicator"
|
|
|
|
>
|
|
|
|
Save indicator
|
2021-06-23 18:33:56 +00:00
|
|
|
</b-button>
|
|
|
|
<b-button
|
|
|
|
v-if="addNew"
|
2021-11-01 18:53:06 +00:00
|
|
|
class="ml-1 flex-grow-1"
|
2021-06-23 18:33:56 +00:00
|
|
|
variant="primary"
|
|
|
|
title="Add "
|
|
|
|
size="sm"
|
|
|
|
@click="clickCancel"
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { ChartType, IndicatorConfig } from '@/types';
|
|
|
|
import randomColor from '@/shared/randomColor';
|
|
|
|
|
2022-04-20 05:11:23 +00:00
|
|
|
import { defineComponent, computed, ref, watch } from '@vue/composition-api';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'PlotIndicator',
|
|
|
|
props: {
|
|
|
|
value: { required: true, type: Object as () => Record<string, IndicatorConfig> },
|
|
|
|
columns: { required: true, type: Array as () => string[] },
|
|
|
|
addNew: { required: true, type: Boolean },
|
|
|
|
},
|
|
|
|
emits: ['input'],
|
|
|
|
setup(props, { emit }) {
|
|
|
|
const selColor = ref(randomColor());
|
|
|
|
const graphType = ref<ChartType>(ChartType.line);
|
|
|
|
const availableGraphTypes = ref(Object.keys(ChartType));
|
|
|
|
const selAvailableIndicator = ref('');
|
|
|
|
const cancelled = ref(false);
|
|
|
|
|
|
|
|
const newColor = () => {
|
|
|
|
selColor.value = randomColor();
|
|
|
|
};
|
2021-06-23 18:33:56 +00:00
|
|
|
|
2022-04-20 05:11:23 +00:00
|
|
|
const combinedIndicator = computed(() => {
|
|
|
|
if (cancelled.value || !selAvailableIndicator.value) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
[selAvailableIndicator.value]: {
|
2022-04-21 18:24:28 +00:00
|
|
|
color: selColor.value,
|
|
|
|
type: graphType.value,
|
2022-04-20 05:11:23 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const emitIndicator = () => {
|
|
|
|
emit('input', combinedIndicator.value);
|
|
|
|
};
|
2021-06-23 18:33:56 +00:00
|
|
|
|
2022-04-20 05:11:23 +00:00
|
|
|
const clickCancel = () => {
|
|
|
|
cancelled.value = true;
|
|
|
|
emitIndicator();
|
|
|
|
};
|
2021-06-23 18:33:56 +00:00
|
|
|
|
2022-04-20 05:11:23 +00:00
|
|
|
watch(
|
|
|
|
() => props.value,
|
|
|
|
() => {
|
|
|
|
[selAvailableIndicator.value] = Object.keys(props.value);
|
|
|
|
cancelled.value = false;
|
|
|
|
if (selAvailableIndicator.value && props.value) {
|
|
|
|
selColor.value = props.value[selAvailableIndicator.value].color || randomColor();
|
|
|
|
graphType.value = props.value[selAvailableIndicator.value].type || ChartType.line;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-06-23 18:33:56 +00:00
|
|
|
|
2022-04-20 05:11:23 +00:00
|
|
|
watch(selColor, () => {
|
|
|
|
if (!props.addNew) {
|
|
|
|
emitIndicator();
|
|
|
|
}
|
|
|
|
});
|
2021-06-23 18:33:56 +00:00
|
|
|
|
|
|
|
return {
|
2022-04-20 05:11:23 +00:00
|
|
|
selColor,
|
|
|
|
graphType,
|
|
|
|
availableGraphTypes,
|
|
|
|
selAvailableIndicator,
|
|
|
|
cancelled,
|
|
|
|
combinedIndicator,
|
|
|
|
newColor,
|
|
|
|
emitIndicator,
|
|
|
|
clickCancel,
|
2021-06-23 18:33:56 +00:00
|
|
|
};
|
2022-04-20 05:11:23 +00:00
|
|
|
},
|
|
|
|
});
|
2021-06-23 18:33:56 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.colorbox {
|
|
|
|
border-radius: 50%;
|
|
|
|
margin-top: auto;
|
|
|
|
margin-bottom: auto;
|
|
|
|
height: 25px;
|
|
|
|
width: 25px;
|
|
|
|
vertical-align: center;
|
|
|
|
}
|
|
|
|
</style>
|