pbasiak commented on issue #17319:
URL: https://github.com/apache/echarts/issues/17319#issuecomment-2242530271
Still not fixed.
I got a workaround for this using a formatter.
**Function which takes string and maxWidth as parameters and imitate
maxWidth by using real dom element and calculate when to break string using
`\n`.**
```js
function wrapTextToPixelWidth(
text: string,
maxWidth: number,
font = '12px Arial',
) {
const span = document.createElement('span');
span.style.visibility = 'hidden';
span.style.whiteSpace = 'nowrap';
span.style.position = 'absolute';
span.style.font = font;
document.body.appendChild(span);
const words = text.split(' ');
let currentLine = '';
let result = '';
words.forEach(word => {
const testLine = `${currentLine + word} `;
span.textContent = testLine;
const testLineWidth = span.offsetWidth;
if (testLineWidth > maxWidth) {
result += `${currentLine.trim()}\n`;
currentLine = `${word} `;
} else {
currentLine = testLine;
}
});
result += currentLine.trim();
document.body.removeChild(span);
return result;
}
```
Then in the formatter function:
```js
axisName: {
formatter: (value: string) => wrapTextToPixelWidth(value, 140),
},
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]