@@ -28,6 +28,7 @@ import Point from './core/Point';
28
28
import { LIGHT_LABEL_COLOR , DARK_LABEL_COLOR } from './config' ;
29
29
import { parse , stringify } from './tool/color' ;
30
30
import env from './core/env' ;
31
+ import { REDARAW_BIT , STYLE_CHANGED_BIT } from './graphic/constants' ;
31
32
32
33
export interface ElementAnimateConfig {
33
34
duration ?: number
@@ -658,13 +659,14 @@ class Element<Props extends ElementProps = ElementProps> {
658
659
textEl . setDefaultTextStyle ( innerTextDefaultStyle ) ;
659
660
}
660
661
662
+ // Mark textEl to update transform.
663
+ // DON'T use markRedraw. It will cause Element itself to dirty again.
664
+ textEl . __dirty |= REDARAW_BIT ;
665
+
661
666
if ( textStyleChanged ) {
662
667
// Only mark style dirty if necessary. Update ZRText is costly.
663
- textEl . dirtyStyle ( ) ;
668
+ textEl . dirtyStyle ( true ) ;
664
669
}
665
-
666
- // Mark textEl to update transform.
667
- textEl . markRedraw ( ) ;
668
670
}
669
671
}
670
672
@@ -850,7 +852,7 @@ class Element<Props extends ElementProps = ElementProps> {
850
852
* @param keepCurrentState If keep current states.
851
853
* If not, it will inherit from the normal state.
852
854
*/
853
- useState ( stateName : string , keepCurrentStates ?: boolean , noAnimation ?: boolean ) {
855
+ useState ( stateName : string , keepCurrentStates ?: boolean , noAnimation ?: boolean , forceUseHoverLayer ?: boolean ) {
854
856
// Use preserved word __normal__
855
857
// TODO: Only restore changed properties when restore to normal???
856
858
const toNormalState = stateName === PRESERVED_NORMAL_STATE ;
@@ -889,7 +891,7 @@ class Element<Props extends ElementProps = ElementProps> {
889
891
this . saveCurrentToNormalState ( state ) ;
890
892
}
891
893
892
- const useHoverLayer = ! ! ( state && state . hoverLayer ) ;
894
+ const useHoverLayer = ! ! ( ( state && state . hoverLayer ) || forceUseHoverLayer ) ;
893
895
894
896
if ( useHoverLayer ) {
895
897
// Enter hover layer before states update.
@@ -906,11 +908,14 @@ class Element<Props extends ElementProps = ElementProps> {
906
908
) ;
907
909
908
910
// Also set text content.
909
- if ( this . _textContent ) {
910
- this . _textContent . useState ( stateName , keepCurrentStates ) ;
911
+ const textContent = this . _textContent ;
912
+ const textGuide = this . _textGuide ;
913
+ if ( textContent ) {
914
+ // Force textContent use hover layer if self is using it.
915
+ textContent . useState ( stateName , keepCurrentStates , noAnimation , useHoverLayer ) ;
911
916
}
912
- if ( this . _textGuide ) {
913
- this . _textGuide . useState ( stateName , keepCurrentStates ) ;
917
+ if ( textGuide ) {
918
+ textGuide . useState ( stateName , keepCurrentStates , noAnimation , useHoverLayer ) ;
914
919
}
915
920
916
921
if ( toNormalState ) {
@@ -938,7 +943,7 @@ class Element<Props extends ElementProps = ElementProps> {
938
943
this . _toggleHoverLayerFlag ( false ) ;
939
944
// NOTE: avoid unexpected refresh when moving out from hover layer!!
940
945
// Only clear from hover layer.
941
- this . __dirty &= ~ Element . REDARAW_BIT ;
946
+ this . __dirty &= ~ REDARAW_BIT ;
942
947
}
943
948
944
949
// Return used state.
@@ -949,7 +954,7 @@ class Element<Props extends ElementProps = ElementProps> {
949
954
* Apply multiple states.
950
955
* @param states States list.
951
956
*/
952
- useStates ( states : string [ ] , noAnimation ?: boolean ) {
957
+ useStates ( states : string [ ] , noAnimation ?: boolean , forceUseHoverLayer ?: boolean ) {
953
958
if ( ! states . length ) {
954
959
this . clearStates ( ) ;
955
960
}
@@ -984,7 +989,8 @@ class Element<Props extends ElementProps = ElementProps> {
984
989
}
985
990
}
986
991
987
- const useHoverLayer = ! ! ( stateObjects [ len - 1 ] && stateObjects [ len - 1 ] . hoverLayer ) ;
992
+ const lastStateObj = stateObjects [ len - 1 ] ;
993
+ const useHoverLayer = ! ! ( ( lastStateObj && lastStateObj . hoverLayer ) || forceUseHoverLayer ) ;
988
994
if ( useHoverLayer ) {
989
995
// Enter hover layer before states update.
990
996
this . _toggleHoverLayerFlag ( true ) ;
@@ -1004,11 +1010,13 @@ class Element<Props extends ElementProps = ElementProps> {
1004
1010
animationCfg
1005
1011
) ;
1006
1012
1007
- if ( this . _textContent ) {
1008
- this . _textContent . useStates ( states ) ;
1013
+ const textContent = this . _textContent ;
1014
+ const textGuide = this . _textGuide ;
1015
+ if ( textContent ) {
1016
+ textContent . useStates ( states , noAnimation , useHoverLayer ) ;
1009
1017
}
1010
- if ( this . _textGuide ) {
1011
- this . _textGuide . useStates ( states ) ;
1018
+ if ( textGuide ) {
1019
+ textGuide . useStates ( states , noAnimation , useHoverLayer ) ;
1012
1020
}
1013
1021
1014
1022
this . _updateAnimationTargets ( ) ;
@@ -1022,7 +1030,7 @@ class Element<Props extends ElementProps = ElementProps> {
1022
1030
this . _toggleHoverLayerFlag ( false ) ;
1023
1031
// NOTE: avoid unexpected refresh when moving out from hover layer!!
1024
1032
// Only clear from hover layer.
1025
- this . __dirty &= ~ Element . REDARAW_BIT ;
1033
+ this . __dirty &= ~ REDARAW_BIT ;
1026
1034
}
1027
1035
}
1028
1036
}
@@ -1352,7 +1360,7 @@ class Element<Props extends ElementProps = ElementProps> {
1352
1360
* Mark element needs to be repainted
1353
1361
*/
1354
1362
markRedraw ( ) {
1355
- this . __dirty |= Element . REDARAW_BIT ;
1363
+ this . __dirty |= REDARAW_BIT ;
1356
1364
const zr = this . __zr ;
1357
1365
if ( zr ) {
1358
1366
if ( this . __inHover ) {
@@ -1604,9 +1612,6 @@ class Element<Props extends ElementProps = ElementProps> {
1604
1612
out : TextPositionCalculationResult , style : ElementTextConfig , rect : RectLike
1605
1613
) => TextPositionCalculationResult
1606
1614
1607
-
1608
- static REDARAW_BIT = 1 ;
1609
-
1610
1615
protected static initDefaultProps = ( function ( ) {
1611
1616
const elProto = Element . prototype ;
1612
1617
elProto . type = 'element' ;
@@ -1618,7 +1623,7 @@ class Element<Props extends ElementProps = ElementProps> {
1618
1623
elProto . dragging = false ;
1619
1624
elProto . ignoreClip = false ;
1620
1625
elProto . __inHover = false ;
1621
- elProto . __dirty = Element . REDARAW_BIT ;
1626
+ elProto . __dirty = REDARAW_BIT ;
1622
1627
1623
1628
1624
1629
const logs : Dictionary < boolean > = { } ;
0 commit comments