mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-09 09:09:38 +02:00
Fix for issue #178, auto-line wrap of notes in sequence diagrams
This commit is contained in:
@@ -19,23 +19,38 @@ exports.drawRect = function(elem , rectData){
|
||||
return rectElem;
|
||||
};
|
||||
|
||||
exports.drawText = function(elem , textData){
|
||||
exports.drawText = function(elem, textData, width) {
|
||||
// Remove and ignore br:s
|
||||
var nText = textData.text.replace(/<br\/?>/ig,' ');
|
||||
|
||||
var textElem = elem.append('text');
|
||||
textElem.attr('x', textData.x);
|
||||
textElem.attr('y', textData.y);
|
||||
textElem.style('text-anchor', textData.anchor);
|
||||
textElem.attr('fill', textData.fill);
|
||||
|
||||
textData.text.split(/<br\/?>/ig).forEach(function(rowText){
|
||||
var span = textElem.append('tspan');
|
||||
span.attr('x', textData.x +textData.textMargin);
|
||||
span.attr('dy', textData.dy);
|
||||
span.text(rowText);
|
||||
});
|
||||
|
||||
if(typeof textData.class !== 'undefined'){
|
||||
if (typeof textData.class !== 'undefined') {
|
||||
textElem.attr("class", textData.class);
|
||||
}
|
||||
/* textData.text.split(/<br\/?>/ig).forEach(function(rowText){
|
||||
var span = textElem.append('tspan');
|
||||
span.attr('x', textData.x +textData.textMargin);
|
||||
span.attr('dy', textData.dy);
|
||||
span.text(rowText);
|
||||
});*/
|
||||
|
||||
|
||||
var span = textElem.append('tspan');
|
||||
span.attr('x', textData.x);
|
||||
span.attr('dy', textData.dy);
|
||||
span.text(nText);
|
||||
if(typeof textElem.textwrap !== 'undefined'){
|
||||
textElem.textwrap({
|
||||
x: textData.x+4, // bounding box is 300 pixels from the left
|
||||
y: textData.y-2, // bounding box is 400 pixels from the top
|
||||
width: width, // bounding box is 500 pixels across
|
||||
height: 1800 // bounding box is 600 pixels tall
|
||||
}, textData.textMargin);
|
||||
}
|
||||
|
||||
return textElem;
|
||||
};
|
||||
|
Reference in New Issue
Block a user