[Bug] Rich text drops the \n between styled runs when width and overflow: 'break' are set
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
从 src/graphic/helper/parseText.ts 开始,尤其关注所引用的行处理逻辑附近的 pushTokens 和 wrapText。将 width 和 overflow 设置为 'break' 来复现富文本示例,然后添加或更新测试,以涵盖格式化 run 之间的换行和多个换行。完成意味着这些情况保留与没有 overflow 的文本相同的换行,并且现有测试套件通过。
由索引模型根据 Issue 内容生成。
描述
Version
6.1.0 (the latest release). 5.6.0 behaves the same, and zrender master has the same code.
Link to Minimal Reproduction
Official Editor, ECharts 6.1.0. The same page as a standalone HTML file, with the screenshot below: https://gist.github.com/floke75/3b924d190ceee31063b4a02dc2ca7064
Steps to Reproduce
Open the link. Both titles have the same text, '{name|First line}\n{note|Second line}'. The right-hand one adds width: 280, overflow: 'break' to its textStyle.
const rich = { name: { fontSize: 18, fontWeight: 'bold' }, note: { fontSize: 12, color: '#666' } };
const text = '{name|First line}\n{note|Second line}';
option = {
title: [
// No width: two lines, as expected.
{ text: text, left: 10, top: 10, textStyle: { rich: rich } },
// Same text with width + overflow 'break': the \n is dropped and both runs share one line.
{ text: text, left: '50%', top: 10, textStyle: { rich: rich, width: 280, overflow: 'break' } }
]
};
Current Behavior
In the right-hand title, "First line" and "Second line" are drawn on one line. The left-hand one, without overflow, has two lines.

With width and overflow: 'break' or 'breakAll', the same happens with:
- a
\nat the end of a run:'{name|First line\n}{note|Second line}'; - two breaks, which become one:
'{name|First line}\n\n{note|Second line}'; - plain text before a run:
'First line\n{note|Second line}'; - axis labels, for example
axisLabel: { width: 80, overflow: 'break', formatter: '{n|{value}}\n{u|SEK bn}' }, and pie labels with awidth.
A \n at the start of a run ('{name|First line}{note|\nSecond line}') is kept, and overflow: 'truncate' keeps all of them.
Expected Behavior
The same line breaks as without overflow: 'break': "Second line" on its own line.
Environment
- OS: macOS 26.6.1, Apple M3
- Browser: Chromium 148.0.7778.96 (Playwright), and the official editor in the same browser. Also in server-side rendering (Node, SVG renderer).
- Framework: none
Any additional comments?
This looks like Problem 1 in #17573, which was closed as stale in 2024. I'm opening a new issue, as the template asks.
Where it comes from, as far as I can tell: with overflow: 'break', pushTokens splits each text segment with wrapText instead of str.split('\n') (parseText.ts). When a segment ends with \n (the \n between two runs is a segment of its own), wrapText doesn't push the empty line after it (if (line)). '\n'.split('\n') gives ['', ''], but wrapText gives [''], so the next run continues on the same line.
This change fixed all the cases above for me. I checked it only against them, not against your test suite:
--- a/src/graphic/helper/parseText.ts
+++ b/src/graphic/helper/parseText.ts
@@ -822,7 +822,7 @@
if (currentWord) {
line += currentWord;
}
- if (line) {
+ if (line || text.charAt(text.length - 1) === '\n') {
lines.push(line);
linesWidths.push(accumWidth);
}
It also gives plain text that ends in \n an empty last line under overflow: 'break', which is what that text already gets without overflow.
Thank you for ECharts!
- 主要语言
- TypeScript
- 星标
- 67.7k
- 派生
- 19.9k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/echarts 的其他 Issue
-
[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭en pending
难度 2/5 1-3 小时 新手友好度 80/100
-
[Bug] Inverse axis collapses the grid with outerBoundsContain when a tick is near the axis edge可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭en pending
难度 2/5 1-3 小时 新手友好度 82/100
-
en pending
难度 2/5 1-3 小时 新手友好度 78/100
-
[Bug] The zoom cursor in the toolbox area is incorrect可能已有人在做 @waterWang 于 98 天前认领。 未关闭bug en pending
难度 2/5 1-3 小时 新手友好度 70/100
-
en pending
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
Stop retrying permanent GitHub API failures in retry.sh可能已有人在做 @muspi-merol-review 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
promplate/code-review#113 · 1 条评论 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
サムネイルの Storage のバケット(`thumbnails`)に、大きさの上限(1 MiB)と許可する種類(JPEG、PNG、WebP)を設定する可能已有人在做 @ykzts 今天认领。 未关闭tech: supabase
难度 2/5 1-3 小时 新手友好度 78/100
inabagumi/shinju-date#7147 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
elecnix/your-attention#129 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
umami-software/umami#4780 ·
维护者通常 3 天内回复