@@ -29,7 +29,8 @@ import {
2929 isNil ,
3030 isArray ,
3131 isObject ,
32- pointInRect
32+ pointInRect ,
33+ isBoolean
3334} from '@visactor/vutils' ;
3435import type { PointLocationCfg } from '../core/type' ;
3536import { labelSmartInvert , contrastAccessibilityChecker , smartInvertStrategy } from '../util/label-smartInvert' ;
@@ -212,17 +213,30 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
212213 labels = this . _layout ( labels ) ;
213214 }
214215
216+ const filteredLabels : ( IText | IRichText ) [ ] = [ ] ;
217+ const overlapLabels : ( IText | IRichText ) [ ] = labels ;
218+ if ( ! isBoolean ( overlap ) && isFunction ( overlap . filterBeforeOverlap ) ) {
219+ const getRelatedGraphic = this . getRelatedGraphic . bind ( this ) ;
220+ labels . forEach ( label => {
221+ if ( overlap . filterBeforeOverlap ( label , getRelatedGraphic , this ) ) {
222+ overlapLabels . push ( label ) ;
223+ } else {
224+ filteredLabels . push ( label ) ;
225+ }
226+ } ) ;
227+ }
228+
215229 if ( isFunction ( customOverlapFunc ) ) {
216230 labels = customOverlapFunc (
217- labels as Text [ ] ,
231+ overlapLabels as Text [ ] ,
218232 this . getRelatedGraphic . bind ( this ) ,
219233 this . _isCollectionBase ? ( d : LabelItem ) => this . _idToPoint . get ( d . id ) : null ,
220234 this
221- ) ;
235+ ) . concat ( filteredLabels ) ;
222236 } else {
223237 // 防重叠逻辑
224238 if ( overlap !== false ) {
225- labels = this . _overlapping ( labels ) ;
239+ labels = this . _overlapping ( overlapLabels ) . concat ( filteredLabels ) ;
226240 }
227241 }
228242
0 commit comments