@@ -30,10 +30,11 @@ import {
30
30
ColorString ,
31
31
ZRStyleProps ,
32
32
AnimationOptionMixin ,
33
- InterpolatableValue
33
+ InterpolatableValue ,
34
+ NullUndefined
34
35
} from '../util/types' ;
35
36
import GlobalModel from '../model/Global' ;
36
- import { isFunction , retrieve2 , extend , keys , trim } from 'zrender/src/core/util' ;
37
+ import { isFunction , retrieve2 , extend , keys , trim , retrieve3 } from 'zrender/src/core/util' ;
37
38
import { SPECIAL_STATES , DISPLAY_STATES } from '../util/states' ;
38
39
import { deprecateReplaceLog } from '../util/log' ;
39
40
import { makeInner , interpolateRawValues } from '../util/model' ;
@@ -398,15 +399,12 @@ function setTextStyleCommon(
398
399
const richInheritPlainLabelOptionName = 'richInheritPlainLabel' as const ;
399
400
const richInheritPlainLabel = retrieve2 (
400
401
textStyleModel . get ( richInheritPlainLabelOptionName ) ,
401
- ecModel && ecModel . get ( richInheritPlainLabelOptionName )
402
+ ecModel ? ecModel . get ( richInheritPlainLabelOptionName ) : undefined
402
403
) ;
403
404
for ( const name in richItemNames ) {
404
405
if ( richItemNames . hasOwnProperty ( name ) ) {
405
406
// Cascade is supported in rich.
406
- const richTextStyle = textStyleModel . getModel (
407
- [ 'rich' , name ] ,
408
- richInheritPlainLabel !== false ? textStyleModel : void 0
409
- ) ;
407
+ const richTextStyle = textStyleModel . getModel ( [ 'rich' , name ] ) ;
410
408
// In rich, never `disableBox`.
411
409
// consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
412
410
// the default color `'blue'` will not be adopted if no color declared in `rich`.
@@ -415,7 +413,8 @@ function setTextStyleCommon(
415
413
// Since v6, the rich style inherits plain label by default
416
414
// but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
417
415
setTokenTextStyle (
418
- richResult [ name ] = { } , richTextStyle , globalTextStyle , opt , isNotNormal , isAttached , false , true
416
+ richResult [ name ] = { } , richTextStyle , globalTextStyle , textStyleModel , richInheritPlainLabel ,
417
+ opt , isNotNormal , isAttached , false , true
419
418
) ;
420
419
}
421
420
}
@@ -431,7 +430,9 @@ function setTextStyleCommon(
431
430
if ( margin != null ) {
432
431
textStyle . margin = margin ;
433
432
}
434
- setTokenTextStyle ( textStyle , textStyleModel , globalTextStyle , opt , isNotNormal , isAttached , true , false ) ;
433
+ setTokenTextStyle (
434
+ textStyle , textStyleModel , globalTextStyle , null , null , opt , isNotNormal , isAttached , true , false
435
+ ) ;
435
436
}
436
437
// Consider case:
437
438
// {
@@ -482,6 +483,8 @@ function setTokenTextStyle(
482
483
textStyle : TextStyleProps [ 'rich' ] [ string ] ,
483
484
textStyleModel : Model < LabelOption > ,
484
485
globalTextStyle : LabelOption ,
486
+ plainTextModel : Model < LabelOption > | NullUndefined ,
487
+ richInheritPlainLabel : boolean ,
485
488
opt ?: Pick < TextCommonParams , 'inheritColor' | 'defaultOpacity' | 'disableBox' > ,
486
489
isNotNormal ?: boolean ,
487
490
isAttached ?: boolean ,
@@ -566,7 +569,17 @@ function setTokenTextStyle(
566
569
// others should remain their original value got from normal style.
567
570
for ( let i = 0 ; i < TEXT_PROPS_WITH_GLOBAL . length ; i ++ ) {
568
571
const key = TEXT_PROPS_WITH_GLOBAL [ i ] ;
569
- const val = retrieve2 ( textStyleModel . getShallow ( key ) , globalTextStyle [ key ] ) ;
572
+ // props width, height, padding, margin, tag, backgroundColor, borderColor,
573
+ // borderWidth, borderRadius, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY
574
+ // may inappropriate to inherit from plainTextStyle.
575
+ // And if some props is specified in default options, users may have to reset them one by one.
576
+ // Therefore, we only allow these props to inherit from plainTextStyle.
577
+ // `richInheritPlainLabel` is switch for backward compatibility
578
+ const val = ( richInheritPlainLabel !== false && plainTextModel )
579
+ ? retrieve3 (
580
+ textStyleModel . getShallow ( key ) , plainTextModel . getShallow ( key ) , globalTextStyle [ key ]
581
+ )
582
+ : retrieve2 ( textStyleModel . getShallow ( key ) , globalTextStyle [ key ] ) ;
570
583
if ( val != null ) {
571
584
( textStyle as any ) [ key ] = val ;
572
585
}
0 commit comments