mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Fix sequence diagram note text y position issue
This commit is contained in:
parent
2a061fba07
commit
7df9dea72a
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid",
|
"name": "mermaid",
|
||||||
"version": "8.0.0-alpha.4",
|
"version": "8.0.0-alpha.5",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid.core.js",
|
"main": "dist/mermaid.core.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -154,6 +154,23 @@ export const bounds = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _drawLongText = (text, x, y, g, width) => {
|
||||||
|
let textHeight = 0
|
||||||
|
const lines = text.split(/<br\/?>/ig)
|
||||||
|
for (const line of lines) {
|
||||||
|
const textObj = svgDraw.getTextObj()
|
||||||
|
textObj.x = x
|
||||||
|
textObj.y = y + textHeight
|
||||||
|
textObj.textMargin = conf.noteMargin
|
||||||
|
textObj.dy = '1em'
|
||||||
|
textObj.text = line
|
||||||
|
textObj.class = 'noteText'
|
||||||
|
const textElem = svgDraw.drawText(g, textObj, width)
|
||||||
|
textHeight += (textElem._groups || textElem)[0][0].getBBox().height
|
||||||
|
}
|
||||||
|
return textHeight
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws an actor in the diagram with the attaced line
|
* Draws an actor in the diagram with the attaced line
|
||||||
* @param center - The center of the the actor
|
* @param center - The center of the the actor
|
||||||
@ -170,29 +187,9 @@ const drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
|
|||||||
let g = elem.append('g')
|
let g = elem.append('g')
|
||||||
const rectElem = svgDraw.drawRect(g, rect)
|
const rectElem = svgDraw.drawRect(g, rect)
|
||||||
|
|
||||||
const textObj = svgDraw.getTextObj()
|
const textHeight = _drawLongText(msg.message, startx - 4, verticalPos + 24, g, rect.width - conf.noteMargin)
|
||||||
textObj.x = startx - 4
|
|
||||||
textObj.y = verticalPos + 24
|
|
||||||
textObj.textMargin = conf.noteMargin
|
|
||||||
textObj.dy = '1em'
|
|
||||||
textObj.text = msg.message
|
|
||||||
textObj.class = 'noteText'
|
|
||||||
|
|
||||||
let textElem = svgDraw.drawText(g, textObj, rect.width - conf.noteMargin)
|
|
||||||
|
|
||||||
let textHeight = (textElem._groups || textElem)[0][0].getBBox().height
|
|
||||||
if (!forceWidth && textHeight > conf.width) {
|
|
||||||
textElem.remove()
|
|
||||||
g = elem.append('g')
|
|
||||||
|
|
||||||
textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin)
|
|
||||||
textHeight = (textElem._groups || textElem)[0][0].getBBox().height
|
|
||||||
rectElem.attr('width', 2 * rect.width)
|
|
||||||
bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
|
||||||
} else {
|
|
||||||
bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
||||||
}
|
|
||||||
|
|
||||||
rectElem.attr('height', textHeight + 2 * conf.noteMargin)
|
rectElem.attr('height', textHeight + 2 * conf.noteMargin)
|
||||||
bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
|
bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user