mirror of
https://github.com/dataease/dataease.git
synced 2026-06-13 01:01:20 +08:00
fix(chart): separate mix chart tooltip formatters
This commit is contained in:
@@ -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<T>(
|
||||
formatterMap: Record<string, T>,
|
||||
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]
|
||||
}
|
||||
@@ -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<DualAxesOptions, DualAxes> {
|
||||
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<string, SeriesFormatter>
|
||||
const tooltip: DualAxesOptions['tooltip'] = {
|
||||
@@ -557,15 +558,16 @@ export class ColumnLineMix extends G2PlotChartView<DualAxesOptions, DualAxes> {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user