#743 handle multiline section titles in gantt diagrams

This commit is contained in:
Marc Faber
2020-01-08 13:50:58 +01:00
parent 37ae863443
commit 1cfd93640c
4 changed files with 93 additions and 3 deletions

View File

@@ -357,9 +357,22 @@ export const draw = function(text, id) {
.selectAll('text')
.data(numOccurances)
.enter()
.append('text')
.text(function(d) {
return d[0];
.append(function(d) {
const rows = d[0].split(/<br\s*\/?>/gi);
const dy = -(rows.length - 1) / 2;
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
svgLabel.setAttribute('dy', dy + 'em');
for (let j = 0; j < rows.length; j++) {
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
tspan.setAttribute('alignment-baseline', 'central');
tspan.setAttribute('x', '10');
if (j > 0) tspan.setAttribute('dy', '1em');
tspan.textContent = rows[j];
svgLabel.appendChild(tspan);
}
return svgLabel;
})
.attr('x', 10)
.attr('y', function(d, i) {

View File

@@ -47,6 +47,16 @@ describe('when parsing a gantt diagram it', function() {
expect(parserFnConstructor(str)).not.toThrow();
});
it('should handle multiline section titles with different line breaks', function() {
const str =
'gantt\n' +
'dateFormat yyyy-mm-dd\n' +
'title Adding gantt diagram functionality to mermaid\n' +
'excludes weekdays 2019-02-01\n' +
'section Line1<br>Line2<br/>Line3</br />Line4<br\t/>Line5';
expect(parserFnConstructor(str)).not.toThrow();
});
/**
* Beslutsflöde inligt nedan. Obs bla bla bla
* ```