@@ -535,14 +535,18 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
535535 this . isMarkInsideRect ( this . getRelatedGraphic ( label . attribute ) , bmpTool )
536536 ) ;
537537
538- const { clampForce = true , hideOnHit = true , overlapPadding, strategy } = option ;
539- if ( clampForce ) {
538+ const { clampForce = true , hideOnHit = true , hideOnOverflow = false , overlapPadding, strategy } = option ;
539+ if ( clampForce || hideOnOverflow ) {
540540 for ( let i = 0 ; i < result . length ; i ++ ) {
541541 const text = labels [ i ] ;
542542 const { dx = 0 , dy = 0 } = clampText ( text as IText , bmpTool . width , bmpTool . height , bmpTool . padding ) ;
543543 if ( dx !== 0 || dy !== 0 ) {
544- text . setAttributes ( { x : text . attribute . x + dx , y : text . attribute . y + dy } ) ;
545- text . _isClamped = true ;
544+ if ( hideOnOverflow ) {
545+ text . setAttributes ( { visible : false } ) ;
546+ } else {
547+ text . setAttributes ( { x : text . attribute . x + dx , y : text . attribute . y + dy } ) ;
548+ text . _isClamped = true ;
549+ }
546550 }
547551 }
548552 }
@@ -565,12 +569,16 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
565569 if ( canPlace ( bmpTool , bitmap , bounds , clampForce , overlapPadding ) ) {
566570 bitmap . setRange ( range ) ;
567571 } else {
568- if ( clampForce ) {
569- const placedAfterClampForce = this . _processClampForce ( text as IText , bmpTool , bitmap , overlapPadding ) ;
570- if ( placedAfterClampForce ) {
572+ if ( hideOnOverflow ) {
573+ if ( this . _processHideOnOverflow ( text as IText , bmpTool ) ) {
574+ continue ;
575+ }
576+ } else if ( clampForce ) {
577+ if ( this . _processClampForce ( text as IText , bmpTool , bitmap , overlapPadding ) ) {
571578 continue ;
572579 }
573580 }
581+
574582 if ( hideOnHit ) {
575583 text . setAttributes ( { visible : false } ) ;
576584 } else {
@@ -581,6 +589,17 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
581589 return result ;
582590 }
583591
592+ protected _processHideOnOverflow ( text : IText , bmpTool : BitmapTool ) {
593+ const { dy : dy = 0 , dx : dx = 0 } = clampText ( text , bmpTool . width , bmpTool . height , bmpTool . padding ) ;
594+ if ( 0 !== dx || 0 !== dy ) {
595+ text . setAttributes ( {
596+ visible : false
597+ } ) ;
598+ return false ;
599+ }
600+ return true ;
601+ }
602+
584603 protected _processClampForce ( text : IText , bmpTool : BitmapTool , bitmap : Bitmap , overlapPadding = 0 ) {
585604 const { dy = 0 , dx = 0 } = clampText ( text as IText , bmpTool . width , bmpTool . height , bmpTool . padding ) ;
586605 if ( dx === 0 && dy === 0 ) {
@@ -621,7 +640,8 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
621640 hideOnHit = true ,
622641 clampForce = true ,
623642 avoidMarks = [ ] ,
624- overlapPadding
643+ overlapPadding,
644+ hideOnOverflow = false
625645 } = option ;
626646 const result : ( IText | IRichText ) [ ] = [ ] ;
627647
@@ -694,17 +714,29 @@ export class LabelBase<T extends BaseLabelAttrs> extends AnimateComponent<T> {
694714 ) ;
695715 if ( hasPlace !== false ) {
696716 text . setAttributes ( { x : hasPlace . x , y : hasPlace . y } ) ;
697- result . push ( text ) ;
698- break ;
717+ // 需要判定是否超出边界
718+ if ( ! ( hideOnOverflow && ! this . _processHideOnOverflow ( text as IText , bmpTool ) ) ) {
719+ result . push ( text ) ;
720+ break ;
721+ }
699722 }
700723 }
701724
702725 // 尝试向内挤压
703- if ( ! hasPlace && clampForce ) {
704- const placedAfterClampForce = this . _processClampForce ( text as IText , bmpTool , bitmap , overlapPadding ) ;
705- if ( placedAfterClampForce ) {
706- result . push ( text ) ;
707- continue ;
726+ if ( ! hasPlace ) {
727+ // 是否隐藏
728+ if ( hideOnOverflow ) {
729+ // 直接隐藏
730+ if ( ! this . _processHideOnOverflow ( text as IText , bmpTool ) ) {
731+ continue ;
732+ }
733+ }
734+ if ( clampForce ) {
735+ // 向内挤压
736+ if ( this . _processClampForce ( text as IText , bmpTool , bitmap , overlapPadding ) ) {
737+ result . push ( text ) ;
738+ continue ;
739+ }
708740 }
709741 }
710742
0 commit comments