[Bug] Rich text drops the \n between styled runs when width and overflow: 'break' are set
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- data-visualization, frontend
Línea de trabajo
Empieza por src/graphic/helper/parseText.ts, especialmente por pushTokens y wrapText alrededor de la lógica de manejo de líneas referenciada. Reproduce el ejemplo de texto enriquecido con width y overflow设置为 'break', y luego añade o actualiza pruebas que cubran los saltos de línea entre ejecuciones con estilo y varios saltos de línea. Hecho significa que esos casos conservan los mismos saltos de línea que el texto sin overflow y que la suite de pruebas existente pasa.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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!
- Lenguaje dominante
- TypeScript
- Estrellas
- 67.7k
- Forks
- 19.9k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/echarts
-
[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoen pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
-
[Bug] Inverse axis collapses the grid with outerBoundsContain when a tick is near the axis edgePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoen pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
[Bug] The zoom cursor in the toolbox area is incorrectPosiblemente ocupada @waterWang la tomó hace 98 días. Abiertobug en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de apache/echarts
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
pollen-robotics/reachy-mini-desktop-app#341 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
mike-north/AgentMonitors#648 ·
Los mantenedores suelen responder en 1 día
-
Position: a popup placed again from between two layout steps lands a fraction of a pixel offAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
vercel-labs/ui#700 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días