style(图表-象限图): 优化象限图的tooltip样式

This commit is contained in:
jianneng-fit2cloud 2024-04-17 14:15:45 +08:00
parent a721be0dd2
commit 8f881e7d57

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,7 +335,9 @@ 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 (formatterMap[key]['originName'] === item.name) {
const formatter = formatterMap[key]
if (formatter) { if (formatter) {
const value = const value =
formatter.groupType === 'q' formatter.groupType === 'q'
@ -350,6 +348,8 @@ export class Quadrant extends G2PlotChartView<ScatterOptions, G2Scatter> {
: formatter.chartShowName : formatter.chartShowName
result.push({ color: item.color, name, value }) result.push({ color: item.color, name, value })
} }
}
})
}) })
return result return result
} }