fix(图表): 多序列提示逻辑错误

This commit is contained in:
wisonic-s 2024-04-22 22:43:51 +08:00
parent c6503e2e62
commit bba924fbf7

View File

@ -46,11 +46,6 @@ const initSeriesTooltip = () => {
if (!showSeriesTooltipFormatter.value) { if (!showSeriesTooltipFormatter.value) {
return return
} }
if (!props.chart.customAttr.tooltip.seriesTooltipFormatter.length) {
state.tooltipForm.seriesTooltipFormatter = deepCopy(
props.chart.customAttr.tooltip.seriesTooltipFormatter
)
}
const formatter = state.tooltipForm.seriesTooltipFormatter const formatter = state.tooltipForm.seriesTooltipFormatter
const seriesAxisMap = formatter.reduce((pre, next) => { const seriesAxisMap = formatter.reduce((pre, next) => {
next.seriesId = next.seriesId ?? next.id next.seriesId = next.seriesId ?? next.id
@ -104,7 +99,9 @@ const quotaAxis = computed(() => {
return return
} }
const axis = props.chart[prop] const axis = props.chart[prop]
axis?.forEach(item => result.push(item)) axis?.forEach(item => {
result.push({ ...item, seriesId: `${item.id}-${prop}` })
})
}) })
return result return result
}) })
@ -164,6 +161,9 @@ watch(
watch( watch(
[quotaData, () => props.chart.type], [quotaData, () => props.chart.type],
newVal => { newVal => {
if (!newVal?.[0]?.length) {
return
}
initSeriesTooltip() initSeriesTooltip()
}, },
{ deep: false } { deep: false }
@ -201,11 +201,6 @@ const init = () => {
if (customAttr.tooltip) { if (customAttr.tooltip) {
state.tooltipForm = defaultsDeep(customAttr.tooltip, cloneDeep(DEFAULT_TOOLTIP)) state.tooltipForm = defaultsDeep(customAttr.tooltip, cloneDeep(DEFAULT_TOOLTIP))
formatterSelector.value?.blur() formatterSelector.value?.blur()
if (!props.chart.customAttr.tooltip.seriesTooltipFormatter.length) {
state.tooltipForm.seriesTooltipFormatter = deepCopy(
props.chart.customAttr.tooltip.seriesTooltipFormatter
)
}
// //
const formatter = state.tooltipForm.seriesTooltipFormatter const formatter = state.tooltipForm.seriesTooltipFormatter
if (!formatter.length) { if (!formatter.length) {
@ -283,21 +278,21 @@ const addAxis = (form: AxisEditForm) => {
ele.chartShowName = axisMap[ele.id].chartShowName ele.chartShowName = axisMap[ele.id].chartShowName
} else { } else {
// //
if (dupAxis.findIndex(i => i.id === ele.id) !== -1) {
return
}
const tmp = cloneDeep(axisMap[ele.id]) const tmp = cloneDeep(axisMap[ele.id])
tmp.show = true tmp.show = true
dupAxis.push(tmp) dupAxis.push(tmp)
} }
} }
}) })
const dupAxisDistinct = uniqWith(dupAxis, isEqual) || []
state.tooltipForm.seriesTooltipFormatter = state.tooltipForm.seriesTooltipFormatter =
state.tooltipForm.seriesTooltipFormatter.concat(dupAxisDistinct) state.tooltipForm.seriesTooltipFormatter.concat(dupAxis)
state.tooltipForm.seriesTooltipFormatter = partition( state.tooltipForm.seriesTooltipFormatter = partition(
state.tooltipForm.seriesTooltipFormatter, state.tooltipForm.seriesTooltipFormatter,
ele => quotaAxis.value.findIndex(item => item.id === ele.id) !== -1 ele => quotaAxis.value.findIndex(item => item.id === ele.id) !== -1
).flat() ).flat()
state.tooltipForm.seriesTooltipFormatter =
uniqWith(state.tooltipForm.seriesTooltipFormatter, isEqual) || []
} }
const removeAxis = (form: AxisEditForm) => { const removeAxis = (form: AxisEditForm) => {
const { axis, axisType } = form const { axis, axisType } = form
@ -327,7 +322,7 @@ const removeAxis = (form: AxisEditForm) => {
// //
ele.show = false ele.show = false
ele.seriesId = ele.id ele.seriesId = ele.id
ele.summary = 'sum' ele.summary = axisMap[ele.seriesId].summary
} }
}) })
state.tooltipForm.seriesTooltipFormatter = partition( state.tooltipForm.seriesTooltipFormatter = partition(