2021-03-23 14:32:39 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div>
|
2021-03-24 13:32:29 +08:00
|
|
|
|
<div style="width: 100%">
|
2021-03-23 14:32:39 +08:00
|
|
|
|
<el-popover
|
2021-05-31 16:20:28 +08:00
|
|
|
|
v-model="isSetting"
|
2021-03-23 14:32:39 +08:00
|
|
|
|
placement="right"
|
|
|
|
|
width="400"
|
|
|
|
|
trigger="click"
|
|
|
|
|
>
|
|
|
|
|
<el-col>
|
2021-05-14 18:21:03 +08:00
|
|
|
|
<el-form v-show="chart.type && !chart.type.includes('gauge')" ref="labelForm" :model="labelForm" label-width="80px" size="mini">
|
2021-05-31 16:20:28 +08:00
|
|
|
|
<!-- <el-form-item :label="$t('chart.show')" class="form-item">-->
|
|
|
|
|
<!-- <el-checkbox v-model="labelForm.show" @change="changeLabelAttr">{{ $t('chart.show') }}</el-checkbox>-->
|
|
|
|
|
<!-- </el-form-item>-->
|
2021-07-02 11:19:23 +08:00
|
|
|
|
<el-form-item :label="$t('chart.pie_label_line_show')" class="form-item">
|
|
|
|
|
<el-checkbox v-model="labelForm.labelLine.show" @change="changeLabelAttr">{{ $t('chart.pie_label_line_show') }}</el-checkbox>
|
|
|
|
|
</el-form-item>
|
2021-03-23 14:32:39 +08:00
|
|
|
|
<el-form-item :label="$t('chart.text_fontsize')" class="form-item">
|
|
|
|
|
<el-select v-model="labelForm.fontSize" :placeholder="$t('chart.text_fontsize')" size="mini" @change="changeLabelAttr">
|
|
|
|
|
<el-option v-for="option in fontSize" :key="option.value" :label="option.name" :value="option.value" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('chart.text_color')" class="form-item">
|
2021-03-24 13:32:29 +08:00
|
|
|
|
<colorPicker v-model="labelForm.color" style="margin-top: 6px;cursor: pointer;z-index: 999;border: solid 1px black" @change="changeLabelAttr" />
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('chart.label_position')" class="form-item">
|
2021-07-02 11:19:23 +08:00
|
|
|
|
<el-select v-model="labelForm.position" :placeholder="$t('chart.label_position')" @change="changeLabelAttr">
|
|
|
|
|
<el-option v-for="option in labelPosition" :key="option.value" :label="option.name" :value="option.value" />
|
|
|
|
|
</el-select>
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</el-form-item>
|
2021-04-02 11:36:01 +08:00
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
|
<span slot="label">
|
|
|
|
|
<span class="span-box">
|
|
|
|
|
<span>{{ $t('chart.content_formatter') }}</span>
|
|
|
|
|
<el-tooltip class="item" effect="dark" placement="bottom">
|
|
|
|
|
<div slot="content">
|
2021-07-06 16:32:38 +08:00
|
|
|
|
字符串模板 模板变量有:<br>{a}:系列名。<br>{b}:数据名。<br>{c}:数据值。<br>{d}:百分比(用于饼图等)。
|
2021-04-02 11:36:01 +08:00
|
|
|
|
</div>
|
|
|
|
|
<i class="el-icon-info" style="cursor: pointer;" />
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2021-03-24 13:32:29 +08:00
|
|
|
|
<el-input v-model="labelForm.formatter" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" @blur="changeLabelAttr" />
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2021-05-14 18:21:03 +08:00
|
|
|
|
|
|
|
|
|
<el-form v-show="chart.type && chart.type.includes('gauge')" ref="labelForm" :model="labelForm" label-width="80px" size="mini">
|
|
|
|
|
<el-form-item :label="$t('chart.show')" class="form-item">
|
|
|
|
|
<el-checkbox v-model="labelForm.show" @change="changeLabelAttr">{{ $t('chart.show') }}</el-checkbox>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('chart.text_fontsize')" class="form-item">
|
|
|
|
|
<el-select v-model="labelForm.fontSize" :placeholder="$t('chart.text_fontsize')" size="mini" @change="changeLabelAttr">
|
|
|
|
|
<el-option v-for="option in fontSize" :key="option.value" :label="option.name" :value="option.value" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('chart.text_color')" class="form-item">
|
|
|
|
|
<colorPicker v-model="labelForm.color" style="margin-top: 6px;cursor: pointer;z-index: 999;border: solid 1px black" @change="changeLabelAttr" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item class="form-item">
|
|
|
|
|
<span slot="label">
|
|
|
|
|
<span class="span-box">
|
|
|
|
|
<span>{{ $t('chart.content_formatter') }}</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
<el-input v-model="labelForm.gaugeFormatter" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" @blur="changeLabelAttr" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
|
2021-05-31 16:20:28 +08:00
|
|
|
|
<el-button slot="reference" size="mini" class="shape-item" :disabled="!labelForm.show">
|
|
|
|
|
{{ $t('chart.label') }}<i class="el-icon-setting el-icon--right" />
|
|
|
|
|
<el-switch
|
|
|
|
|
v-model="labelForm.show"
|
|
|
|
|
class="switch-style"
|
|
|
|
|
@click.stop.native
|
|
|
|
|
@change="changeLabelAttr"
|
|
|
|
|
/>
|
|
|
|
|
</el-button>
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</el-popover>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { DEFAULT_LABEL } from '../../chart/chart'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'LabelSelector',
|
|
|
|
|
props: {
|
|
|
|
|
chart: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
labelForm: JSON.parse(JSON.stringify(DEFAULT_LABEL)),
|
2021-05-31 16:20:28 +08:00
|
|
|
|
fontSize: [],
|
2021-07-02 11:19:23 +08:00
|
|
|
|
isSetting: false,
|
|
|
|
|
labelPosition: [
|
|
|
|
|
{ name: this.$t('chart.inside'), value: 'inside' },
|
|
|
|
|
{ name: this.$t('chart.outside'), value: 'outside' },
|
|
|
|
|
{ name: this.$t('chart.center'), value: 'center' },
|
|
|
|
|
{ name: this.$t('chart.text_pos_top'), value: 'top' },
|
|
|
|
|
{ name: this.$t('chart.text_pos_bottom'), value: 'bottom' },
|
|
|
|
|
{ name: this.$t('chart.text_pos_left'), value: 'left' },
|
|
|
|
|
{ name: this.$t('chart.text_pos_right'), value: 'right' }
|
|
|
|
|
]
|
2021-03-23 14:32:39 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
'chart': {
|
|
|
|
|
handler: function() {
|
|
|
|
|
const chart = JSON.parse(JSON.stringify(this.chart))
|
|
|
|
|
if (chart.customAttr) {
|
2021-05-05 22:14:23 +08:00
|
|
|
|
let customAttr = null
|
|
|
|
|
if (Object.prototype.toString.call(chart.customAttr) === '[object Object]') {
|
|
|
|
|
customAttr = JSON.parse(JSON.stringify(chart.customAttr))
|
|
|
|
|
} else {
|
|
|
|
|
customAttr = JSON.parse(chart.customAttr)
|
|
|
|
|
}
|
2021-03-23 14:32:39 +08:00
|
|
|
|
if (customAttr.label) {
|
|
|
|
|
this.labelForm = customAttr.label
|
2021-07-02 11:19:23 +08:00
|
|
|
|
if (!this.labelForm.labelLine) {
|
|
|
|
|
this.labelForm.labelLine = JSON.parse(JSON.stringify(DEFAULT_LABEL.labelLine))
|
|
|
|
|
}
|
2021-03-23 14:32:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.init()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
init() {
|
|
|
|
|
const arr = []
|
|
|
|
|
for (let i = 10; i <= 20; i = i + 2) {
|
|
|
|
|
arr.push({
|
|
|
|
|
name: i + '',
|
|
|
|
|
value: i + ''
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.fontSize = arr
|
|
|
|
|
},
|
|
|
|
|
changeLabelAttr() {
|
2021-05-31 16:20:28 +08:00
|
|
|
|
if (!this.labelForm.show) {
|
|
|
|
|
this.isSetting = false
|
|
|
|
|
}
|
2021-03-23 14:32:39 +08:00
|
|
|
|
this.$emit('onLabelChange', this.labelForm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-03-26 12:14:18 +08:00
|
|
|
|
<style scoped>
|
2021-03-24 13:32:29 +08:00
|
|
|
|
.shape-item{
|
|
|
|
|
padding: 6px;
|
|
|
|
|
border: none;
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
2021-03-23 14:32:39 +08:00
|
|
|
|
.form-item-slider>>>.el-form-item__label{
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 38px;
|
|
|
|
|
}
|
|
|
|
|
.form-item>>>.el-form-item__label{
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
.el-select-dropdown__item{
|
|
|
|
|
padding: 0 20px;
|
|
|
|
|
}
|
|
|
|
|
span{
|
|
|
|
|
font-size: 12px
|
|
|
|
|
}
|
|
|
|
|
.el-form-item{
|
|
|
|
|
margin-bottom: 6px;
|
|
|
|
|
}
|
2021-05-31 16:20:28 +08:00
|
|
|
|
|
|
|
|
|
.switch-style{
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 10px;
|
|
|
|
|
margin-top: -4px;
|
|
|
|
|
}
|
2021-03-23 14:32:39 +08:00
|
|
|
|
</style>
|