mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
fix karma tests where text.textwrap is undefined; added textPlacement parameters to some test cases
This commit is contained in:
@@ -23,6 +23,13 @@ var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 });
|
|||||||
//
|
//
|
||||||
//var sd = require('./sequenceRenderer');
|
//var sd = require('./sequenceRenderer');
|
||||||
|
|
||||||
|
function addConf(conf, key, value) {
|
||||||
|
if (value !== undefined) {
|
||||||
|
conf[key]=value;
|
||||||
|
}
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
var str;
|
var str;
|
||||||
describe('when parsing a sequenceDiagram',function() {
|
describe('when parsing a sequenceDiagram',function() {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -761,7 +768,9 @@ describe('when rendering a sequenceDiagram',function() {
|
|||||||
//console.log(document.querySelector('#tst').getBBox());
|
//console.log(document.querySelector('#tst').getBBox());
|
||||||
|
|
||||||
});
|
});
|
||||||
it('it should handle one actor', function () {
|
['tspan','fo','old',undefined].forEach(function(textPlacement) {
|
||||||
|
it('it should handle one actor, when textPlacement is '+textPlacement, function () {
|
||||||
|
sd.setConf(addConf(conf, 'textPlacement', textPlacement));
|
||||||
sd.bounds.init();
|
sd.bounds.init();
|
||||||
var str = 'sequenceDiagram\n' +
|
var str = 'sequenceDiagram\n' +
|
||||||
'participant Alice';
|
'participant Alice';
|
||||||
@@ -774,7 +783,7 @@ describe('when rendering a sequenceDiagram',function() {
|
|||||||
expect(bounds.starty).toBe(0);
|
expect(bounds.starty).toBe(0);
|
||||||
expect(bounds.stopx ).toBe( conf.width);
|
expect(bounds.stopx ).toBe( conf.width);
|
||||||
expect(bounds.stopy ).toBe(conf.height);
|
expect(bounds.stopy ).toBe(conf.height);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('it should handle one actor and a centered note', function () {
|
it('it should handle one actor and a centered note', function () {
|
||||||
sd.bounds.init();
|
sd.bounds.init();
|
||||||
@@ -987,7 +996,9 @@ describe('when rendering a sequenceDiagram with actor mirror activated',function
|
|||||||
};
|
};
|
||||||
sd.setConf(conf);
|
sd.setConf(conf);
|
||||||
});
|
});
|
||||||
it('it should handle one actor', function () {
|
['tspan','fo','old',undefined].forEach(function(textPlacement) {
|
||||||
|
it('it should handle one actor, when textPlacement is'+textPlacement, function () {
|
||||||
|
sd.setConf(addConf(conf, 'textPlacement', textPlacement));
|
||||||
sd.bounds.init();
|
sd.bounds.init();
|
||||||
var str = 'sequenceDiagram\n' +
|
var str = 'sequenceDiagram\n' +
|
||||||
'participant Alice';
|
'participant Alice';
|
||||||
@@ -1000,6 +1011,6 @@ describe('when rendering a sequenceDiagram with actor mirror activated',function
|
|||||||
expect(bounds.starty).toBe(0);
|
expect(bounds.starty).toBe(0);
|
||||||
expect(bounds.stopx ).toBe( conf.width);
|
expect(bounds.stopx ).toBe( conf.width);
|
||||||
expect(bounds.stopy ).toBe(2*conf.height+2*conf.boxMargin);
|
expect(bounds.stopy ).toBe(2*conf.height+2*conf.boxMargin);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -35,7 +35,7 @@ var conf = {
|
|||||||
activationWidth:10,
|
activationWidth:10,
|
||||||
|
|
||||||
//text placement as: tspan | fo | <else> only text as before
|
//text placement as: tspan | fo | <else> only text as before
|
||||||
textPlacement: 'tspan',
|
textPlacement: 'fo',
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.bounds = {
|
exports.bounds = {
|
||||||
|
@@ -281,25 +281,23 @@ var _drawTextCandidateFunc = (function() {
|
|||||||
.attr('x', x + width / 2).attr('y', y)
|
.attr('x', x + width / 2).attr('y', y)
|
||||||
.style('text-anchor', 'middle');
|
.style('text-anchor', 'middle');
|
||||||
var tspan = text.append('tspan')
|
var tspan = text.append('tspan')
|
||||||
.attr('x', x + width / 2).attr('dy', '0') //.attr('y', y + height / 2)
|
.attr('x', x + width / 2).attr('dy', '0')
|
||||||
.text(content);
|
.text(content);
|
||||||
|
|
||||||
text.textwrap({ //d3textwrap
|
if(typeof(text.textwrap) !== 'undefined'){
|
||||||
x: x + width / 2,
|
text.textwrap({ //d3textwrap
|
||||||
y: y,
|
x: x + width / 2, y: y, width: width, height: height
|
||||||
width: width,
|
}, 0);
|
||||||
height: height
|
//vertical aligment after d3textwrap expans tspan to multiple tspans
|
||||||
}, 0);
|
var tspans = text.selectAll('tspan');
|
||||||
|
if (tspans.length > 0 && tspans[0].length > 0) {
|
||||||
//vertical aligment after d3textwrap expans tspan to multiple tspans
|
tspans = tspans[0];
|
||||||
var tspans = text.selectAll('tspan');
|
//set y of <text> to the mid y of the first line
|
||||||
if (tspans.length > 0 && tspans[0].length > 0) {
|
text.attr('y', y + (height/2.- text[0][0].getBBox().height*(1 - 1.0/tspans.length)/2.))
|
||||||
tspans = tspans[0];
|
.attr("dominant-baseline", "central")
|
||||||
//set y of <text> to the mid y of the first line
|
.attr("alignment-baseline", "central")
|
||||||
text.attr('y', y + (height/2.- text[0][0].getBBox().height*(1 - 1.0/tspans.length)/2.))
|
}
|
||||||
.attr("dominant-baseline", "central")
|
}
|
||||||
.attr("alignment-baseline", "central")
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var key in textAttrs) {
|
for (var key in textAttrs) {
|
||||||
text.attr(key, textAttrs[key]);
|
text.attr(key, textAttrs[key]);
|
||||||
|
Reference in New Issue
Block a user