style(图表-象限图): 样式中属性的交互优化

This commit is contained in:
jianneng-fit2cloud 2024-05-16 18:47:42 +08:00
parent 2087b9aaed
commit 29a6ced7dd
2 changed files with 241 additions and 136 deletions

View File

@ -3,13 +3,16 @@ import { computed, inject, onMounted, PropType, reactive, ref, watch } from 'vue
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { COLOR_PANEL, DEFAULT_QUADRANT_STYLE } from '@/views/chart/components/editor/util/chart' import { COLOR_PANEL, DEFAULT_QUADRANT_STYLE } from '@/views/chart/components/editor/util/chart'
import { useEmitt } from '@/hooks/web/useEmitt' import { useEmitt } from '@/hooks/web/useEmitt'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { deepCopy } from '@/utils/utils'
useEmitt({ useEmitt({
name: 'quadrant-default-baseline', name: 'quadrant-default-baseline',
callback: args => quadrantDefaultBaseline(args) callback: args => quadrantDefaultBaseline(args)
}) })
const quotaData = ref<Axis[]>(inject('quotaData')) const quotaData = ref<Axis[]>(inject('quotaData'))
const { t } = useI18n() const { t } = useI18n()
const dvMainStore = dvMainStoreWithOut()
const props = defineProps({ const props = defineProps({
chart: { chart: {
type: Object, type: Object,
@ -25,9 +28,29 @@ const props = defineProps({
}) })
const predefineColors = COLOR_PANEL const predefineColors = COLOR_PANEL
const regionStyle = []
const labels = []
const isDashboard = dvMainStore.dvInfo.type === 'dashboard'
for (let i = 0; i < 4; i++) {
regionStyle.push({
fill: isDashboard ? '#fdfcfc' : 'rgb(2,4,8,1)',
fillOpacity: 1
})
labels.push({
content: '',
style: {
fill: isDashboard ? 'rgb(2,4,8,1)' : '#fdfcfc',
fillOpacity: 0.5,
fontSize: 14
}
})
}
const state = reactive({ const state = reactive({
quadrantForm: JSON.parse(JSON.stringify(DEFAULT_QUADRANT_STYLE)) quadrantForm: {
...JSON.parse(JSON.stringify(DEFAULT_QUADRANT_STYLE)),
regionStyle,
labels
}
}) })
const toolTip = computed(() => { const toolTip = computed(() => {
return props.themes === 'dark' ? 'ndark' : 'dark' return props.themes === 'dark' ? 'ndark' : 'dark'
@ -84,19 +107,27 @@ const init = () => {
} }
if (customAttr.quadrant) { if (customAttr.quadrant) {
state.quadrantForm = customAttr.quadrant state.quadrantForm = customAttr.quadrant
} else {
changeStyle()
} }
} }
} }
const showProperty = prop => props.propertyInner?.includes(prop) const showProperty = prop => props.propertyInner?.includes(prop)
const tabActive = ref(1)
onMounted(() => { onMounted(() => {
init() init()
}) })
</script> </script>
<template> <template>
<el-form ref="quadrantForm" :model="state.quadrantForm" size="small" label-position="top"> <el-form
ref="quadrantForm"
class="quadrant"
:model="state.quadrantForm"
size="small"
label-position="top"
>
<template v-if="showProperty('lineStyle')"> <template v-if="showProperty('lineStyle')">
<label class="custom-form-item-label" :class="'custom-form-item-label--' + themes" <label class="custom-form-item-label" :class="'custom-form-item-label--' + themes"
>{{ t('chart.quadrant') }}{{ t('chart.split_line') }}</label >{{ t('chart.quadrant') }}{{ t('chart.split_line') }}</label
@ -113,12 +144,12 @@ onMounted(() => {
/> />
</el-form-item> </el-form-item>
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-left: 4px"> <el-form-item class="form-item" :class="'form-item-' + themes" style="padding-left: 4px">
<el-tooltip :content="t('chart.alpha')" :effect="toolTip" placement="top"> <el-tooltip :content="t('chart.not_alpha')" :effect="toolTip" placement="top">
<el-select <el-select
style="width: 53px" style="width: 53px"
:effect="props.themes" :effect="props.themes"
v-model="state.quadrantForm.lineStyle.opacity" v-model="state.quadrantForm.lineStyle.opacity"
:placeholder="t('chart.alpha')" :placeholder="t('chart.not_alpha')"
@change="changeStyle()" @change="changeStyle()"
> >
<el-option <el-option
@ -182,147 +213,226 @@ onMounted(() => {
</el-form-item> </el-form-item>
</div> </div>
</template> </template>
<div <el-tabs v-model="tabActive" class="quadrant-tab-header" :class="{ dark: themes === 'dark' }">
v-for="(l, index) in state.quadrantForm.labels" <el-tab-pane
:key="index" :name="index + 1"
style="flex-direction: row; justify-content: space-between" v-for="(l, index) in state.quadrantForm.labels"
> :key="index"
<el-divider :label="t('chart.quadrant') + (index + 1)"
class="m-divider" class="padding-tab"
v-if="index < state.quadrantForm.labels.length"
:class="'m-divider--' + themes"
/>
<label class="custom-form-item-label" :class="'custom-form-item-label--' + themes"
>{{ t('chart.quadrant') }}{{ index + 1 }}</label
> >
<template v-if="showProperty('regionStyle')"> <div style="flex-direction: row; justify-content: space-between">
<div style="display: flex"> <template v-if="showProperty('regionStyle')">
<label class="custom-form-item-label" :class="'custom-form-item-label--' + themes">{{ <div style="display: flex">
t('chart.backgroundColor') <label class="custom-form-item-label" :class="'custom-form-item-label--' + themes">{{
}}</label> t('chart.backgroundColor')
</div> }}</label>
<div style="display: flex"> </div>
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-right: 4px"> <div style="display: flex">
<el-color-picker <el-form-item
v-model="state.quadrantForm.regionStyle[index].fill" class="form-item"
class="color-picker-style" :class="'form-item-' + themes"
:predefine="predefineColors" style="padding-right: 4px"
@change="changeStyle()"
:effect="themes"
is-custom
/>
</el-form-item>
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-left: 4px">
<el-tooltip :content="t('chart.alpha')" :effect="toolTip" placement="top">
<el-select
style="width: 53px"
:effect="props.themes"
v-model="state.quadrantForm.regionStyle[index].fillOpacity"
:placeholder="t('chart.alpha')"
@change="changeStyle()"
> >
<el-option <el-color-picker
v-for="option in fillOpacityList" v-model="state.quadrantForm.regionStyle[index].fill"
:key="option.value" class="color-picker-style"
:label="option.name" :predefine="predefineColors"
:value="option.value" @change="changeStyle()"
:effect="themes"
is-custom
/> />
</el-select> </el-form-item>
</el-tooltip> <el-form-item
</el-form-item> class="form-item"
</div> :class="'form-item-' + themes"
</template> style="padding-left: 4px"
<template v-if="showProperty('label')">
<el-form-item class="form-item" :class="'form-item-' + themes" :label="t('chart.text')">
<el-input
:effect="props.themes"
v-model="l.content"
size="small"
maxlength="50"
@blur="changeStyle()"
/>
</el-form-item>
<label class="custom-form-item-label" :class="'custom-form-item-label--' + themes">
{{ t('chart.text') }}{{ t('chart.chart_style') }}</label
>
<div style="display: flex">
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-right: 4px">
<el-color-picker
v-model="l.style.fill"
class="color-picker-style"
:predefine="predefineColors"
@change="changeStyle()"
:effect="themes"
is-custom
/>
</el-form-item>
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-left: 4px">
<el-tooltip :content="t('chart.alpha')" :effect="toolTip" placement="top">
<el-select
style="width: 53px"
:effect="props.themes"
v-model="l.style.fillOpacity"
:placeholder="t('chart.alpha')"
@change="changeStyle()"
> >
<el-option <el-tooltip :content="t('chart.not_alpha')" :effect="toolTip" placement="top">
v-for="option in fillOpacityList" <el-select
:key="option.value" style="width: 53px"
:label="option.name" :effect="props.themes"
:value="option.value" v-model="state.quadrantForm.regionStyle[index].fillOpacity"
/> :placeholder="t('chart.not_alpha')"
</el-select> @change="changeStyle()"
</el-tooltip> >
</el-form-item> <el-option
<el-form-item class="form-item" :class="'form-item-' + themes" style="padding-left: 4px"> v-for="option in fillOpacityList"
<el-tooltip :content="t('chart.font_size')" :effect="toolTip" placement="top"> :key="option.value"
<el-select :label="option.name"
style="width: 108px" :value="option.value"
/>
</el-select>
</el-tooltip>
</el-form-item>
</div>
</template>
<template v-if="showProperty('label')">
<el-form-item class="form-item" :class="'form-item-' + themes" :label="t('chart.text')">
<el-input
:effect="props.themes" :effect="props.themes"
v-model="l.style.fontSize" v-model="l.content"
:placeholder="t('chart.axis_name_fontsize')" size="small"
@change="changeStyle()" maxlength="50"
@blur="changeStyle()"
/>
</el-form-item>
<label class="custom-form-item-label" :class="'custom-form-item-label--' + themes">
{{ t('chart.text') }}{{ t('chart.chart_style') }}</label
>
<div style="display: flex">
<el-form-item
class="form-item"
:class="'form-item-' + themes"
style="padding-right: 4px"
> >
<el-option <el-color-picker
v-for="option in fontSizeList" v-model="l.style.fill"
:key="option.value" class="color-picker-style"
:label="option.name" :predefine="predefineColors"
:value="option.value" @change="changeStyle()"
:effect="themes"
is-custom
/> />
</el-select> </el-form-item>
</el-tooltip> <el-form-item
</el-form-item> class="form-item"
:class="'form-item-' + themes"
style="padding-left: 4px"
>
<el-tooltip :content="t('chart.not_alpha')" :effect="toolTip" placement="top">
<el-select
style="width: 53px"
:effect="props.themes"
v-model="l.style.fillOpacity"
:placeholder="t('chart.not_alpha')"
@change="changeStyle()"
>
<el-option
v-for="option in fillOpacityList"
:key="option.value"
:label="option.name"
:value="option.value"
/>
</el-select>
</el-tooltip>
</el-form-item>
<el-form-item
class="form-item"
:class="'form-item-' + themes"
style="padding-left: 4px"
>
<el-tooltip :content="t('chart.font_size')" :effect="toolTip" placement="top">
<el-select
style="width: 108px"
:effect="props.themes"
v-model="l.style.fontSize"
:placeholder="t('chart.axis_name_fontsize')"
@change="changeStyle()"
>
<el-option
v-for="option in fontSizeList"
:key="option.value"
:label="option.name"
:value="option.value"
/>
</el-select>
</el-tooltip>
</el-form-item>
</div>
</template>
</div> </div>
</template> </el-tab-pane>
</div> </el-tabs>
</el-form> </el-form>
</template> </template>
<style lang="less" scoped> <style lang="less" scoped>
.custom-form-item-label { .quadrant {
margin-bottom: 4px; .custom-form-item-label {
line-height: 20px; margin-bottom: 4px;
color: #646a73; line-height: 20px;
font-size: 12px; color: #646a73;
font-style: normal; font-size: 12px;
font-weight: 400; font-style: normal;
padding: 2px 12px 0 0; font-weight: 400;
padding: 2px 12px 0 0;
&.custom-form-item-label--dark { &.custom-form-item-label--dark {
color: #a6a6a6; color: #a6a6a6;
}
} }
}
.form-item-checkbox { .form-item-checkbox {
margin-bottom: 10px !important; margin-bottom: 10px !important;
} }
.m-divider { .m-divider {
border-color: rgba(31, 35, 41, 0.15); border-color: rgba(31, 35, 41, 0.15);
margin: 0 0 16px; margin: 0 0 16px;
&.m-divider--dark { &.m-divider--dark {
border-color: rgba(235, 235, 235, 0.15); border-color: rgba(235, 235, 235, 0.15);
}
}
.quadrant-tab-header {
--ed-tabs-header-height: 34px;
--custom-tab-color: #646a73;
:deep(.ed-tabs__nav-wrap::after) {
background-color: unset;
}
&.dark {
--custom-tab-color: #a6a6a6;
}
height: 100%;
:deep(.ed-tabs__header) {
border-top: solid 1px @side-outline-border-color;
}
:deep(.ed-tabs__item) {
font-weight: 400;
font-size: 12px;
padding: 0 12px !important;
margin-right: 0 !important;
color: var(--custom-tab-color);
}
:deep(.is-active) {
font-weight: 500;
color: var(--ed-color-primary, #3370ff);
}
:deep(.ed-tabs__nav-scroll) {
padding-left: 0 !important;
}
:deep(.ed-tabs__header) {
margin: 0 !important;
}
:deep(.ed-tabs__content) {
height: calc(100% - 33px);
overflow-y: auto;
overflow-x: hidden;
}
}
.padding-tab {
padding: 0;
height: 100%;
width: 100%;
display: flex;
:deep(.ed-scrollbar) {
&.has-footer {
height: calc(100% - 81px);
}
}
:deep(.ed-footer) {
padding: 0;
height: 114px;
}
} }
} }
</style> </style>

View File

@ -7,10 +7,8 @@ import { flow, parseJson } from '../../../util'
import { valueFormatter } from '../../../formatter' import { valueFormatter } from '../../../formatter'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { isEmpty } from 'lodash-es' import { isEmpty } from 'lodash-es'
import { DEFAULT_QUADRANT_STYLE } from '@/views/chart/components/editor/util/chart'
const { t } = useI18n() const { t } = useI18n()
/** /**
* 象限图 * 象限图
*/ */
@ -396,9 +394,6 @@ export class Quadrant extends G2PlotChartView<ScatterOptions, G2Scatter> {
...chart.customStyle.yAxisExt.axisLine, ...chart.customStyle.yAxisExt.axisLine,
show: true show: true
} }
chart.customAttr.quadrant = {
...DEFAULT_QUADRANT_STYLE
}
return chart return chart
} }