Merge pull request #981 from knsv/feature/755_handling_br_in_sequence_diagram

Feature/755 handling br in sequence diagram
This commit is contained in:
edumicse
2019-10-08 14:19:36 +02:00
committed by GitHub

View File

@@ -230,60 +230,44 @@ const drawMessage = function(elem, startx, stopx, verticalPos, msg, sequenceInde
const g = elem.append('g'); const g = elem.append('g');
const txtCenter = startx + (stopx - startx) / 2; const txtCenter = startx + (stopx - startx) / 2;
const textElem = g let textElem
.append('text') // text label for the x axis let counterBreaklines = 0
.attr('x', txtCenter) let breaklineOffset = 17
.attr('y', verticalPos - 7) const breaklines = msg.message.split(/<br\/?>/ig)
.style('text-anchor', 'middle') for (const breakline of breaklines) {
.attr('class', 'messageText') textElem = g.append('text') // text label for the x axis
.text(msg.message); .attr('x', txtCenter)
.attr('y', verticalPos - 7 + counterBreaklines * breaklineOffset)
.style('text-anchor', 'middle')
.attr('class', 'messageText')
.text(breakline.trim())
counterBreaklines++
}
const offsetLineCounter = counterBreaklines - 1
const totalOffset = offsetLineCounter * breaklineOffset
let textWidth = (textElem._groups || textElem)[0][0].getBBox().width; let textWidth = (textElem._groups || textElem)[0][0].getBBox().width;
let line; let line;
if (startx === stopx) { if (startx === stopx) {
if (conf.rightAngles) { if (conf.rightAngles) {
line = g line = g.append('path').attr('d', `M ${startx},${verticalPos + totalOffset} H ${startx + (conf.width / 2)} V ${verticalPos + 25 + totalOffset} H ${startx}`)
.append('path')
.attr(
'd',
`M ${startx},${verticalPos} H ${startx + conf.width / 2} V ${verticalPos +
25} H ${startx}`
);
} else { } else {
line = g line = g.append('path')
.append('path') .attr('d', 'M ' + startx + ',' + (verticalPos + totalOffset) + ' C ' + (startx + 60) + ',' + (verticalPos - 10 + totalOffset) + ' ' + (startx + 60) + ',' +
.attr( (verticalPos + 30 + totalOffset) + ' ' + startx + ',' + (verticalPos + 20 + totalOffset))
'd',
'M ' +
startx +
',' +
verticalPos +
' C ' +
(startx + 60) +
',' +
(verticalPos - 10) +
' ' +
(startx + 60) +
',' +
(verticalPos + 30) +
' ' +
startx +
',' +
(verticalPos + 20)
);
} }
bounds.bumpVerticalPos(30); bounds.bumpVerticalPos(30 + totalOffset)
const dx = Math.max(textWidth / 2, 100); const dx = Math.max(textWidth / 2, 100)
bounds.insert(startx - dx, bounds.getVerticalPos() - 10, stopx + dx, bounds.getVerticalPos()); bounds.insert(startx - dx, bounds.getVerticalPos() - 10 + totalOffset, stopx + dx, bounds.getVerticalPos() + totalOffset)
} else { } else {
line = g.append('line'); line = g.append('line')
line.attr('x1', startx); line.attr('x1', startx)
line.attr('y1', verticalPos); line.attr('y1', verticalPos)
line.attr('x2', stopx); line.attr('x2', stopx)
line.attr('y2', verticalPos); line.attr('y2', verticalPos)
bounds.insert(startx, bounds.getVerticalPos() - 10, stopx, bounds.getVerticalPos()); bounds.insert(startx, bounds.getVerticalPos() - 10 + totalOffset, stopx, bounds.getVerticalPos() + totalOffset)
} }
// Make an SVG Container // Make an SVG Container
// Draw the line // Draw the line