mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-15 02:04:08 +01:00
only split if string is over length.
This commit is contained in:
@@ -119,23 +119,27 @@ function createFormattedText(width, g, structuredText, addBackground = false) {
|
|||||||
let tempStr = '';
|
let tempStr = '';
|
||||||
let linesUnderWidth = [];
|
let linesUnderWidth = [];
|
||||||
let prevIndex = 0;
|
let prevIndex = 0;
|
||||||
for (let i = 0; i <= fullStr.length; i++) {
|
if (computeWidthOfText(labelGroup, lineHeight, fullStr) <= width) {
|
||||||
tempStr = fullStr.slice(prevIndex, i);
|
linesUnderWidth.push(fullStr);
|
||||||
log.info(tempStr, prevIndex, i);
|
} else {
|
||||||
if (computeWidthOfText(labelGroup, lineHeight, tempStr) > width) {
|
for (let i = 0; i <= fullStr.length; i++) {
|
||||||
const subStr = fullStr.slice(prevIndex, i);
|
tempStr = fullStr.slice(prevIndex, i);
|
||||||
// Break at space if any
|
log.info(tempStr, prevIndex, i);
|
||||||
const lastSpaceIndex = subStr.lastIndexOf(' ');
|
if (computeWidthOfText(labelGroup, lineHeight, tempStr) > width) {
|
||||||
if (lastSpaceIndex > -1) {
|
const subStr = fullStr.slice(prevIndex, i);
|
||||||
i = prevIndex + lastSpaceIndex + 1;
|
// Break at space if any
|
||||||
|
const lastSpaceIndex = subStr.lastIndexOf(' ');
|
||||||
|
if (lastSpaceIndex > -1) {
|
||||||
|
i = prevIndex + lastSpaceIndex + 1;
|
||||||
|
}
|
||||||
|
linesUnderWidth.push(fullStr.slice(prevIndex, i).trim());
|
||||||
|
prevIndex = i;
|
||||||
|
tempStr = null;
|
||||||
}
|
}
|
||||||
linesUnderWidth.push(fullStr.slice(prevIndex, i).trim());
|
|
||||||
prevIndex = i;
|
|
||||||
tempStr = null;
|
|
||||||
}
|
}
|
||||||
}
|
if (tempStr != null) {
|
||||||
if (tempStr != null) {
|
linesUnderWidth.push(tempStr);
|
||||||
linesUnderWidth.push(tempStr);
|
}
|
||||||
}
|
}
|
||||||
/** Add each prepared line as a tspan to the parent node */
|
/** Add each prepared line as a tspan to the parent node */
|
||||||
const preparedLines = linesUnderWidth.map((w) => ({ content: w, type: line.type }));
|
const preparedLines = linesUnderWidth.map((w) => ({ content: w, type: line.type }));
|
||||||
|
|||||||
Reference in New Issue
Block a user