refactor(图表): 最值标签不显示

This commit is contained in:
wisonic 2024-07-30 17:48:53 +08:00
parent 44c89d1147
commit a95e34aad0
2 changed files with 9 additions and 2 deletions

View File

@ -104,8 +104,10 @@ const noChildrenFieldChart = chart => {
export const extremumEvt = (newChart, chart, _options, container) => { export const extremumEvt = (newChart, chart, _options, container) => {
chart.container = container chart.container = container
newChart.on('afterrender', ev => { newChart.on('beforerender', ev => {
createExtremumPoint(chart, ev) newChart.chart.geometries[0].on('beforerenderlabel', () => {
createExtremumPoint(chart, ev)
})
}) })
} }
@ -158,6 +160,8 @@ export const createExtremumPoint = (chart, ev) => {
if (pointObjList && pointObjList.length > 0) { if (pointObjList && pointObjList.length > 0) {
const pointObj = pointObjList[0] const pointObj = pointObjList[0]
const { minItem, maxItem } = findMinMax(pointObjList.reverse()) const { minItem, maxItem } = findMinMax(pointObjList.reverse())
minItem._origin.EXTREME = true
maxItem._origin.EXTREME = true
let attr let attr
let showExtremum = false let showExtremum = false
if (noChildrenFieldChart(chart) || yAxis.length > 1) { if (noChildrenFieldChart(chart) || yAxis.length > 1) {

View File

@ -132,6 +132,9 @@ export class Bar extends G2PlotChartView<ColumnOptions, Column> {
fields: [], fields: [],
...tmpOptions.label, ...tmpOptions.label,
formatter: (data: Datum, _point) => { formatter: (data: Datum, _point) => {
if (data.EXTREME) {
return ''
}
if (!labelAttr.seriesLabelFormatter?.length) { if (!labelAttr.seriesLabelFormatter?.length) {
return data.value return data.value
} }