This is an automated email from the ASF dual-hosted git repository. wangzx pushed a commit to branch fix/rich-inherit-plain-label in repository https://gitbox.apache.org/repos/asf/echarts.git
commit a1c4c3ffba7d8a834478860338ff6d0e7fb8964b Author: plainheart <[email protected]> AuthorDate: Fri May 16 17:26:25 2025 +0800 fix(label): fix label rich style does not inherit the plain label style & add new option `richInheritPlainLabel` to control this behavior. --- src/label/labelStyle.ts | 7 +- test/rich-inherit-plain-label.html | 118 +++++++++++++++++++++ test/richText.html | 2 +- test/runTest/actions/__meta__.json | 1 + test/runTest/actions/rich-inherit-plain-label.json | 1 + 5 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/label/labelStyle.ts b/src/label/labelStyle.ts index fd44f45e9..7bd88d293 100644 --- a/src/label/labelStyle.ts +++ b/src/label/labelStyle.ts @@ -395,15 +395,18 @@ function setTextStyleCommon( let richResult: TextStyleProps['rich']; if (richItemNames) { richResult = {}; + const richInheritPlainLabel = textStyleModel.get('richInheritPlainLabel') !== false; for (const name in richItemNames) { if (richItemNames.hasOwnProperty(name)) { // Cascade is supported in rich. - const richTextStyle = textStyleModel.getModel(['rich', name]); + const richTextStyle = textStyleModel.getModel(['rich', name], richInheritPlainLabel && textStyleModel); // In rich, never `disableBox`. - // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`, + // consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`, // the default color `'blue'` will not be adopted if no color declared in `rich`. // That might confuses users. So probably we should put `textStyleModel` as the // root ancestor of the `richTextStyle`. But that would be a break change. + // Since v6, the rich style inherits plain label by default + // but this behavior can be disabled by setting `richInheritPlainLabel` to `false`. setTokenTextStyle( richResult[name] = {}, richTextStyle, globalTextStyle, opt, isNotNormal, isAttached, false, true ); diff --git a/test/rich-inherit-plain-label.html b/test/rich-inherit-plain-label.html new file mode 100644 index 000000000..d7195b9d8 --- /dev/null +++ b/test/rich-inherit-plain-label.html @@ -0,0 +1,118 @@ +<!DOCTYPE html> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + + +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <script src="lib/simpleRequire.js"></script> + <script src="lib/config.js"></script> + <script src="lib/jquery.min.js"></script> + <script src="lib/facePrint.js"></script> + <script src="lib/testHelper.js"></script> + <!-- <script src="ut/lib/canteen.js"></script> --> + <link rel="stylesheet" href="lib/reset.css" /> + </head> + <body> + <div id="main0"></div> + + <script> + require(['echarts'], function (echarts) { + var richInheritPlainLabel = void 0; + var option = { + title: { + text: `richInheritPlainLabel: ${richInheritPlainLabel}` + }, + tooltip: {}, + xAxis: { + type: 'time', + axisLabel: { + fontFamily: 'monospace', + fontSize: 20 + } + }, + yAxis: { + axisLabel: { + fontFamily: 'monospace', + fontSize: 20, + formatter: '{a|{value}}', + rich: { + a: { + fontWeight: 'bold' + } + } + } + }, + series: [ + { + type: 'line', + areaStyle: {}, + data: [ + ['2019-10-10', 200], + ['2019-11-11', 560], + ['2019-12-12', 750], + ['2020-01-13', 580], + ['2020-02-14', 250], + ['2020-03-15', 300], + ['2020-04-16', 450], + ['2020-05-17', 300], + ['2020-06-18', 100] + ] + } + ] + }; + + var chart = testHelper.create(echarts, 'main0', { + title: [ + 'When **`richInheritPlainLabel`** is **true**:', + '1. Both x-axis label font of **2020** and y-axis label font should be **`monospace`**', + '2. Both x-axis label font size of **2020** and y-axis label should be **20**', + ], + option: option, + buttons: [{ + text: 'Toggle RichInheritPlainLabel', + onclick: toggleRichInheritPlainLabel + }] + }); + + function toggleRichInheritPlainLabel() { + richInheritPlainLabel = !richInheritPlainLabel; + chart.setOption({ + title: { + text: `richInheritPlainLabel: ${richInheritPlainLabel}` + }, + xAxis: { + axisLabel: { + richInheritPlainLabel: richInheritPlainLabel + } + }, + yAxis: { + axisLabel: { + richInheritPlainLabel: richInheritPlainLabel + } + } + }); + } + }); + </script> + </body> +</html> + diff --git a/test/richText.html b/test/richText.html index 751630503..a829a014f 100644 --- a/test/richText.html +++ b/test/richText.html @@ -53,4 +53,4 @@ under the License. </script> </body> -</html> \ No newline at end of file +</html> diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json index 41c40c69f..c9357abed 100644 --- a/test/runTest/actions/__meta__.json +++ b/test/runTest/actions/__meta__.json @@ -169,6 +169,7 @@ "radar3": 2, "radar4": 1, "resize-animation": 1, + "rich-inherit-plain-label": 1, "roseType-labeline": 1, "sankey-depth": 1, "sankey-emphasis-lineStyle": 1, diff --git a/test/runTest/actions/rich-inherit-plain-label.json b/test/runTest/actions/rich-inherit-plain-label.json new file mode 100644 index 000000000..7695c6f91 --- /dev/null +++ b/test/runTest/actions/rich-inherit-plain-label.json @@ -0,0 +1 @@ +[{"name":"Action 1","ops":[{"type":"mousedown","time":408,"x":67,"y":114},{"type":"mouseup","time":558,"x":67,"y":114},{"time":559,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1640,"x":67,"y":114},{"type":"mouseup","time":1822,"x":67,"y":114},{"time":1823,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":3022,"x":67,"y":114},{"type":"mouseup","time":3157,"x":67,"y":114},{"time":3158,"delay":400,"type":"screenshot-auto"}],"scrollY":0,"scrollX":0,"timesta [...] \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
