[Bug] Rich text drops the \n between styled runs when width and overflow: 'break' are set
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- data-visualization, frontend
Research direction
Start with src/graphic/helper/parseText.ts, especially pushTokens and wrapText around the referenced line-handling logic. Reproduce the rich-text example with width and overflow set to 'break', then add or update tests covering newlines between styled runs and multiple breaks. Done means those cases preserve the same line breaks as text without overflow, and the existing test suite passes.
Written by the indexing model from the issue text.
Description
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!
- Dominant language
- TypeScript
- Stars
- 67.7k
- Forks
- 19.9k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/echarts
-
[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`Possibly taken A pull request linked to this issue is open or already merged. Openen pending
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
[Bug] Inverse axis collapses the grid with outerBoundsContain when a tick is near the axis edgePossibly taken A pull request linked to this issue is open or already merged. Openen pending
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
en pending
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
[Bug] The zoom cursor in the toolbox area is incorrectPossibly taken @waterWang claimed this 98 days ago. Openbug en pending
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
en pending
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
lingdojo/kana-dojo#34223 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
bug status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
mastra-ai/mastra#30587 · 1 comment ·
Maintainers usually reply within 1 day
-
area:web p2 product:business triage:active type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cuadrao-ai/argus#2228 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
embedpdf/embed-pdf-viewer#1098 ·
Maintainers usually reply within 1 day
-
.Needs Triage .Team/Metabot Priority:P3 Type:Bug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
metabase/metabase#87252 · 1 comment ·
Maintainers usually reply within 1 day