diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix-tooltip.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix-tooltip.ts new file mode 100644 index 0000000000..b81585047d --- /dev/null +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix-tooltip.ts @@ -0,0 +1,31 @@ +type MixTooltipItem = { + name?: string + data?: { + quotaList?: Array<{ id?: string }> + valueExt?: unknown + } +} + +type MixTooltipAxisType = 'yAxis' | 'yAxisExt' + +function getMixTooltipAxisType(item: MixTooltipItem): MixTooltipAxisType { + if ( + item?.name === 'valueExt' || + Object.prototype.hasOwnProperty.call(item?.data ?? {}, 'valueExt') + ) { + return 'yAxisExt' + } + return 'yAxis' +} + +export function getMixTooltipFormatter( + formatterMap: Record, + item: MixTooltipItem +): T | undefined { + const fieldId = item?.data?.quotaList?.[0]?.id + if (!fieldId) { + return undefined + } + const axisType = getMixTooltipAxisType(item) + return formatterMap[`${fieldId}-${axisType}`] ?? formatterMap[fieldId] +} diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix.ts index 0012d92a88..015a3c85af 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/chart-mix.ts @@ -44,6 +44,7 @@ import { import type { Options } from '@antv/g2plot/esm' import { Group } from '@antv/g-canvas' import { extremumEvt } from '@/views/chart/components/js/extremumUitl' +import { getMixTooltipFormatter } from './chart-mix-tooltip' const { t } = useI18n() const DEFAULT_DATA = [] @@ -541,7 +542,7 @@ export class ColumnLineMix extends G2PlotChartView { const formatterMap = tooltipAttr.seriesTooltipFormatter ?.filter(i => i.show) .reduce((pre, next) => { - pre[next.id] = next + pre[next.seriesId ?? next.id] = next return pre }, {}) as Record const tooltip: DualAxesOptions['tooltip'] = { @@ -557,15 +558,16 @@ export class ColumnLineMix extends G2PlotChartView { return originalItems } const result = [] - originalItems - .filter(item => formatterMap[item.data.quotaList[0].id]) - .forEach(item => { - const formatter = formatterMap[item.data.quotaList[0].id] - const value = valueFormatter(parseFloat(item.value as string), formatter.formatterCfg) - const name = item.data.category + originalItems.forEach(item => { + const formatter = getMixTooltipFormatter(formatterMap, item) + if (!formatter) { + return + } + const value = valueFormatter(parseFloat(item.value as string), formatter.formatterCfg) + const name = item.data.category - result.push({ ...item, name, value }) - }) + result.push({ ...item, name, value }) + }) head.data.dynamicTooltipValue?.forEach(item => { const formatter = formatterMap[item.fieldId] if (formatter) {