refactor(图表): 多系列标签字体颜色适配主题

This commit is contained in:
wisonic 2024-07-22 18:52:14 +08:00
parent 727ed4e8e1
commit f61d87baf1
4 changed files with 27 additions and 11 deletions

View File

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

View File

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

View File

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

View File

@ -904,9 +904,22 @@ const onMiscChange = val => {
}
}
const onLabelChange = val => {
view.value.customAttr.label = val
renderChart(view.value)
const onLabelChange = (chartForm: ChartEditorForm<ChartLabelAttr>, prop: string) => {
const { data, requestData, render } = chartForm
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) => {