Skip to content

Commit 9003873

Browse files
authored
Merge pull request #21016 from apache/fix/rich-inherit-plain-label-2
fix(rich-text-inherit-plain)
2 parents b60f105 + ad7c5c8 commit 9003873

File tree

4 files changed

+202
-25
lines changed

4 files changed

+202
-25
lines changed

src/label/labelStyle.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import {
3030
ColorString,
3131
ZRStyleProps,
3232
AnimationOptionMixin,
33-
InterpolatableValue
33+
InterpolatableValue,
34+
NullUndefined
3435
} from '../util/types';
3536
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';
3738
import { SPECIAL_STATES, DISPLAY_STATES } from '../util/states';
3839
import { deprecateReplaceLog } from '../util/log';
3940
import { makeInner, interpolateRawValues } from '../util/model';
@@ -398,15 +399,12 @@ function setTextStyleCommon(
398399
const richInheritPlainLabelOptionName = 'richInheritPlainLabel' as const;
399400
const richInheritPlainLabel = retrieve2(
400401
textStyleModel.get(richInheritPlainLabelOptionName),
401-
ecModel && ecModel.get(richInheritPlainLabelOptionName)
402+
ecModel ? ecModel.get(richInheritPlainLabelOptionName) : undefined
402403
);
403404
for (const name in richItemNames) {
404405
if (richItemNames.hasOwnProperty(name)) {
405406
// 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]);
410408
// In rich, never `disableBox`.
411409
// consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
412410
// the default color `'blue'` will not be adopted if no color declared in `rich`.
@@ -415,7 +413,8 @@ function setTextStyleCommon(
415413
// Since v6, the rich style inherits plain label by default
416414
// but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
417415
setTokenTextStyle(
418-
richResult[name] = {}, richTextStyle, globalTextStyle, opt, isNotNormal, isAttached, false, true
416+
richResult[name] = {}, richTextStyle, globalTextStyle, textStyleModel, richInheritPlainLabel,
417+
opt, isNotNormal, isAttached, false, true
419418
);
420419
}
421420
}
@@ -431,7 +430,9 @@ function setTextStyleCommon(
431430
if (margin != null) {
432431
textStyle.margin = margin;
433432
}
434-
setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isNotNormal, isAttached, true, false);
433+
setTokenTextStyle(
434+
textStyle, textStyleModel, globalTextStyle, null, null, opt, isNotNormal, isAttached, true, false
435+
);
435436
}
436437
// Consider case:
437438
// {
@@ -482,6 +483,8 @@ function setTokenTextStyle(
482483
textStyle: TextStyleProps['rich'][string],
483484
textStyleModel: Model<LabelOption>,
484485
globalTextStyle: LabelOption,
486+
plainTextModel: Model<LabelOption> | NullUndefined,
487+
richInheritPlainLabel: boolean,
485488
opt?: Pick<TextCommonParams, 'inheritColor' | 'defaultOpacity' | 'disableBox'>,
486489
isNotNormal?: boolean,
487490
isAttached?: boolean,
@@ -566,7 +569,17 @@ function setTokenTextStyle(
566569
// others should remain their original value got from normal style.
567570
for (let i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
568571
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]);
570583
if (val != null) {
571584
(textStyle as any)[key] = val;
572585
}

test/rich-inherit-plain-label.html

Lines changed: 177 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/runTest/actions/__meta__.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/runTest/actions/rich-inherit-plain-label.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)