Merge pull request #9163 from dataease/pr@dev-v2@chart-quadrant-tooltip-style

style(图表-象限图): 优化象限图的tooltip样式
This commit is contained in:
jianneng-fit2cloud 2024-04-17 14:16:38 +08:00 committed by GitHub
commit e24dd35618
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -123,7 +123,7 @@ export class Quadrant extends G2PlotChartView<ScatterOptions, G2Scatter> {
return return
} }
const { colorFieldObj, sizeFieldObj, xFieldObj, yFieldObj } = this.getFieldObject(chart) const { colorFieldObj, sizeFieldObj, xFieldObj, yFieldObj } = this.getFieldObject(chart)
if (!xFieldObj.id || !yFieldObj.id) { if (!xFieldObj.id || !yFieldObj.id || yFieldObj.id === xFieldObj.id) {
return return
} }
const data: any[] = [] const data: any[] = []
@ -316,14 +316,10 @@ export class Quadrant extends G2PlotChartView<ScatterOptions, G2Scatter> {
tooltip: false tooltip: false
} }
} }
xAxisTitle['show'] = true
yAxisTitle['show'] = true
yAxisExtTitle['show'] = true
tooltipAttr.seriesTooltipFormatter?.push(xAxisTitle)
const formatterMap = tooltipAttr.seriesTooltipFormatter const formatterMap = tooltipAttr.seriesTooltipFormatter
?.filter(i => i.show) ?.filter(i => i.show)
.reduce((pre, next) => { .reduce((pre, next) => {
pre[next['originName']] = next pre[next['seriesId']] = next
return pre return pre
}, {}) as Record<string, SeriesFormatter> }, {}) as Record<string, SeriesFormatter>
const tooltip: ScatterOptions['tooltip'] = { const tooltip: ScatterOptions['tooltip'] = {
@ -339,17 +335,21 @@ export class Quadrant extends G2PlotChartView<ScatterOptions, G2Scatter> {
originalItems originalItems
?.filter(i => i.name !== xAxisTitle['originName']) ?.filter(i => i.name !== xAxisTitle['originName'])
.forEach(item => { .forEach(item => {
const formatter = formatterMap[item.name] Object.keys(formatterMap).forEach(key => {
if (formatter) { if (formatterMap[key]['originName'] === item.name) {
const value = const formatter = formatterMap[key]
formatter.groupType === 'q' if (formatter) {
? valueFormatter(parseFloat(item.value as string), formatter.formatterCfg) const value =
: item.value formatter.groupType === 'q'
const name = isEmpty(formatter.chartShowName) ? valueFormatter(parseFloat(item.value as string), formatter.formatterCfg)
? formatter.name : item.value
: formatter.chartShowName const name = isEmpty(formatter.chartShowName)
result.push({ color: item.color, name, value }) ? formatter.name
} : formatter.chartShowName
result.push({ color: item.color, name, value })
}
}
})
}) })
return result return result
} }