Merge pull request #11091 from dataease/pr@dev-v2@refactor_chart_series_label_font_color

refactor(图表): 多系列标签字体颜色适配主题
This commit is contained in:
wisonic-s 2024-07-22 18:56:37 +08:00 committed by GitHub
commit 3d29ca3ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 11 deletions

View File

@ -346,8 +346,8 @@ watch(
v-if="showProperties('label-selector')" v-if="showProperties('label-selector')"
v-model="chart.customAttr.label.show" v-model="chart.customAttr.label.show"
:change-model="chart.customAttr.label" :change-model="chart.customAttr.label"
@modelChange="val => onLabelChange(val, 'show')" @modelChange="val => onLabelChange({ data: val }, 'show')"
:title="$t('chart.label')" :title="t('chart.label')"
name="label" name="label"
> >
<label-selector <label-selector
@ -364,7 +364,7 @@ watch(
v-model="chart.customAttr.tooltip.show" v-model="chart.customAttr.tooltip.show"
:themes="themes" :themes="themes"
:change-model="chart.customAttr.tooltip" :change-model="chart.customAttr.tooltip"
:title="$t('chart.tooltip')" :title="t('chart.tooltip')"
:show-switch="propertyInnerAll['tooltip-selector'].includes('show')" :show-switch="propertyInnerAll['tooltip-selector'].includes('show')"
name="tooltip" name="tooltip"
@modelChange="val => onTooltipChange({ data: val }, 'show')" @modelChange="val => onTooltipChange({ data: val }, 'show')"

View File

@ -65,7 +65,7 @@ const onMiscChange = (val, prop) => {
} }
const onLabelChange = (val, prop) => { const onLabelChange = (val, prop) => {
batchOptChange('customAttr', 'label', val, prop) batchOptChange('customAttr', 'label', val.data, prop)
} }
const onTooltipChange = (val, prop) => { const onTooltipChange = (val, prop) => {
batchOptChange('customAttr', 'tooltip', val.data, prop) batchOptChange('customAttr', 'tooltip', val.data, prop)

View File

@ -84,6 +84,7 @@ const initSeriesLabel = () => {
curSeriesFormatter.value = {} curSeriesFormatter.value = {}
return return
} }
let initFlag = false
const axisMap = yAxis.value.reduce((pre, next) => { const axisMap = yAxis.value.reduce((pre, next) => {
let tmp = { let tmp = {
...next, ...next,
@ -101,14 +102,16 @@ const initSeriesLabel = () => {
fontSize: seriesAxisMap[next.id].fontSize, fontSize: seriesAxisMap[next.id].fontSize,
showExtremum: seriesAxisMap[next.id].showExtremum showExtremum: seriesAxisMap[next.id].showExtremum
} }
} else {
initFlag = true
} }
formatter.push(tmp) formatter.push(tmp)
pre[next.id] = tmp pre[next.id] = tmp
return pre return pre
}, {}) }, {})
// //
if (!props.chart.customAttr.label.seriesLabelFormatter?.length) { if (initFlag) {
changeLabelAttr('seriesLabelFormatter') changeLabelAttr('seriesLabelFormatter', false)
} }
if (!curSeriesFormatter.value || !axisMap[curSeriesFormatter.value.id]) { if (!curSeriesFormatter.value || !axisMap[curSeriesFormatter.value.id]) {
curSeriesFormatter.value = axisMap[formatter[0].id] curSeriesFormatter.value = axisMap[formatter[0].id]
@ -170,8 +173,8 @@ const state = reactive<{ labelForm: ChartLabelAttr | any }>({
}) })
const emit = defineEmits(['onLabelChange']) const emit = defineEmits(['onLabelChange'])
const changeLabelAttr = prop => { const changeLabelAttr = (prop: string, render = true) => {
emit('onLabelChange', state.labelForm, prop) emit('onLabelChange', { data: state.labelForm, render }, prop)
} }
const init = () => { const init = () => {

View File

@ -904,9 +904,22 @@ const onMiscChange = val => {
} }
} }
const onLabelChange = val => { const onLabelChange = (chartForm: ChartEditorForm<ChartLabelAttr>, prop: string) => {
view.value.customAttr.label = val const { data, requestData, render } = chartForm
renderChart(view.value) let labelObj = data
if (!data) {
labelObj = chartForm as unknown as ChartLabelAttr
}
if (prop) {
const val = get(labelObj, prop)
set(view.value.customAttr.label, prop, val)
} else {
view.value.customAttr.label = labelObj
}
// for compatibility
if (render !== false) {
renderChart(view.value)
}
} }
const onIndicatorChange = (val, prop) => { const onIndicatorChange = (val, prop) => {