mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-03 04:14:15 +01:00
Fix for issues #249. Adding configuration option for when to use absolute references for arrow heads. Default is off.
Jasmine tests running in browser via karma.
This commit is contained in:
@@ -11,96 +11,96 @@ describe('class diagram, ', function () {
|
||||
});
|
||||
|
||||
it('should handle relation definitions', function () {
|
||||
var str = `classDiagram
|
||||
Class01 <|-- Class02
|
||||
Class03 *-- Class04
|
||||
Class05 o-- Class06
|
||||
Class07 .. Class08
|
||||
Class09 -- Class1`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 <|-- Class02\n'+
|
||||
'Class03 *-- Class04\n'+
|
||||
'Class05 o-- Class06\n'+
|
||||
'Class07 .. Class08\n'+
|
||||
'Class09 -- Class1';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
it('should handle relation definition of different types and directions', function () {
|
||||
var str = `classDiagram
|
||||
Class11 <|.. Class12
|
||||
Class13 --> Class14
|
||||
Class15 ..> Class16
|
||||
Class17 ..|> Class18
|
||||
Class19 <--* Class20`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class11 <|.. Class12\n'+
|
||||
'Class13 --> Class14\n'+
|
||||
'Class15 ..> Class16\n'+
|
||||
'Class17 ..|> Class18\n'+
|
||||
'Class19 <--* Class20';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
|
||||
it('should handle cardinality and labels', function () {
|
||||
var str = `classDiagram
|
||||
Class01 "1" *-- "many" Class02 : contains
|
||||
Class03 o-- Class04 : aggregation
|
||||
Class05 --> "1" Class06`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 "1" *-- "many" Class02 : contains\n'+
|
||||
'Class03 o-- Class04 : aggregation\n'+
|
||||
'Class05 --> "1" Class06';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
it('should handle class definitions', function () {
|
||||
var str = `classDiagram
|
||||
class Car
|
||||
Driver -- Car : drives >
|
||||
Car *-- Wheel : have 4 >
|
||||
Car -- Person : < owns`;
|
||||
var str = 'classDiagram\n'+
|
||||
'class Car\n'+
|
||||
'Driver -- Car : drives >\n'+
|
||||
'Car *-- Wheel : have 4 >\n'+
|
||||
'Car -- Person : < owns';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
|
||||
it('should handle method statements', function () {
|
||||
var str = `classDiagram
|
||||
Object <|-- ArrayList
|
||||
Object : equals()
|
||||
ArrayList : Object[] elementData
|
||||
ArrayList : size()`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Object <|-- ArrayList\n'+
|
||||
'Object : equals()\n'+
|
||||
'ArrayList : Object[] elementData\n'+
|
||||
'ArrayList : size()';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
it('should handle parsing of method statements grouped by brackets', function () {
|
||||
var str = `classDiagram
|
||||
class Dummy {
|
||||
String data
|
||||
void methods()
|
||||
}
|
||||
|
||||
class Flight {
|
||||
flightNumber : Integer
|
||||
departureTime : Date
|
||||
}`;
|
||||
var str = 'classDiagram\n'+
|
||||
'class Dummy {\n'+
|
||||
'String data\n'+
|
||||
' void methods()\n'+
|
||||
'}\n'+
|
||||
'\n'+
|
||||
'class Flight {\n'+
|
||||
' flightNumber : Integer\n'+
|
||||
' departureTime : Date\n'+
|
||||
'}';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
|
||||
it('should handle parsing of separators', function () {
|
||||
var str = `classDiagram
|
||||
class Foo1 {
|
||||
You can use
|
||||
several lines
|
||||
..
|
||||
as you want
|
||||
and group
|
||||
==
|
||||
things together.
|
||||
__
|
||||
You can have as many groups
|
||||
as you want
|
||||
--
|
||||
End of class
|
||||
}
|
||||
|
||||
class User {
|
||||
.. Simple Getter ..
|
||||
+ getName()
|
||||
+ getAddress()
|
||||
.. Some setter ..
|
||||
+ setName()
|
||||
__ private data __
|
||||
int age
|
||||
-- encrypted --
|
||||
String password
|
||||
}`;
|
||||
var str = 'classDiagram\n'+
|
||||
'class Foo1 {\n'+
|
||||
' You can use\n'+
|
||||
' several lines\n'+
|
||||
'..\n'+
|
||||
'as you want\n'+
|
||||
'and group\n'+
|
||||
'==\n'+
|
||||
'things together.\n'+
|
||||
'__\n'+
|
||||
'You can have as many groups\n'+
|
||||
'as you want\n'+
|
||||
'--\n'+
|
||||
'End of class\n'+
|
||||
'}\n'+
|
||||
'\n'+
|
||||
'class User {\n'+
|
||||
'.. Simple Getter ..\n'+
|
||||
'+ getName()\n'+
|
||||
'+ getAddress()\n'+
|
||||
'.. Some setter ..\n'+
|
||||
'+ setName()\n'+
|
||||
'__ private data __\n'+
|
||||
'int age\n'+
|
||||
'-- encrypted --\n'+
|
||||
'String password\n'+
|
||||
'}';
|
||||
|
||||
cd.parse(str);
|
||||
});
|
||||
@@ -116,8 +116,8 @@ class User {
|
||||
cd.yy.clear();
|
||||
});
|
||||
it('should handle relation definitions EXTENSION', function () {
|
||||
var str = `classDiagram
|
||||
Class01 <|-- Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 <|-- Class02';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
@@ -130,8 +130,8 @@ class User {
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
||||
});
|
||||
it('should handle relation definitions AGGREGATION and dotted line', function () {
|
||||
var str = `classDiagram
|
||||
Class01 o.. Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 o.. Class02';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
@@ -144,8 +144,8 @@ class User {
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE);
|
||||
});
|
||||
it('should handle relation definitions COMPOSITION on both sides', function () {
|
||||
var str = `classDiagram
|
||||
Class01 *--* Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 *--* Class02';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
@@ -158,8 +158,8 @@ class User {
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
||||
});
|
||||
it('should handle relation definitions no types', function () {
|
||||
var str = `classDiagram
|
||||
Class01 -- Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 -- Class02';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
@@ -172,8 +172,8 @@ class User {
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
||||
});
|
||||
it('should handle relation definitions with type only on right side', function () {
|
||||
var str = `classDiagram
|
||||
Class01 --|> Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 --|> Class02';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
@@ -187,12 +187,12 @@ class User {
|
||||
});
|
||||
|
||||
it('should handle multiple classes and relation definitions', function () {
|
||||
var str = `classDiagram
|
||||
Class01 <|-- Class02
|
||||
Class03 *-- Class04
|
||||
Class05 o-- Class06
|
||||
Class07 .. Class08
|
||||
Class09 -- Class10`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 <|-- Class02\n'+
|
||||
'Class03 *-- Class04\n'+
|
||||
'Class05 o-- Class06\n'+
|
||||
'Class07 .. Class08\n'+
|
||||
'Class09 -- Class10';
|
||||
|
||||
cd.parse(str);
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ var getGraphId = function (label) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
window.tunk = getGraphId;
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
*/
|
||||
@@ -160,10 +159,12 @@ var drawEdge = function (elem, path, relation) {
|
||||
.attr('d', lineFunction(lineData))
|
||||
.attr('id', 'edge' + edgeCount)
|
||||
.attr('class', 'relation');
|
||||
|
||||
var url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
|
||||
url = url.replace(/\(/g, '\\(');
|
||||
url = url.replace(/\)/g, '\\)');
|
||||
var url = '';
|
||||
if(conf.arrowMarkerAbsolute){
|
||||
url = window.location.protocol+'//'+window.location.host+window.location.pathname +window.location.search;
|
||||
url = url.replace(/\(/g,'\\(');
|
||||
url = url.replace(/\)/g,'\\)');
|
||||
}
|
||||
|
||||
//console.log(relation.relation.type1);
|
||||
if (relation.relation.type1 !== 'none') {
|
||||
@@ -265,10 +266,15 @@ var drawClass = function (elem, classDef) {
|
||||
.attr('class', 'classText');
|
||||
|
||||
var isFirst = true;
|
||||
for (var member of classDef.members) {
|
||||
addTspan(members, member, isFirst);
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
classDef.members.forEach(function(member){
|
||||
addTspan(members, member, isFirst);
|
||||
isFirst = false;
|
||||
});
|
||||
//for (var member of classDef.members) {
|
||||
// addTspan(members, member, isFirst);
|
||||
// isFirst = false;
|
||||
//}
|
||||
|
||||
console.warn(JSON.stringify(classDef));
|
||||
|
||||
@@ -287,10 +293,15 @@ var drawClass = function (elem, classDef) {
|
||||
.attr('class', 'classText');
|
||||
|
||||
isFirst = true;
|
||||
for (var method of classDef.methods) {
|
||||
addTspan(methods, method, isFirst);
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
classDef.methods.forEach(function(method){
|
||||
addTspan(methods, method, isFirst);
|
||||
isFirst = false;
|
||||
});
|
||||
//for (var method of classDef.methods) {
|
||||
// addTspan(methods, method, isFirst);
|
||||
// isFirst = false;
|
||||
//}
|
||||
|
||||
var classBox = g.node().getBBox();
|
||||
g.insert('rect', ':first-child')
|
||||
@@ -373,11 +384,16 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
var relations = cDDb.getRelations();
|
||||
var i = 0;
|
||||
for (var relation of relations) {
|
||||
i = i + 1;
|
||||
log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
|
||||
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation});
|
||||
}
|
||||
relations.forEach(function(relation){
|
||||
i = i + 1;
|
||||
log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
|
||||
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation});
|
||||
});
|
||||
//for (var relation of relations) {
|
||||
// i = i + 1;
|
||||
// log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
|
||||
// g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation});
|
||||
//}
|
||||
dagre.layout(g);
|
||||
g.nodes().forEach(function (v) {
|
||||
if(typeof v !== 'undefined'){
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//};
|
||||
|
||||
//var classRenderer = proxyquire('./classRenderer', { '../../d3': d3 });
|
||||
var testDom = require('testdom')('<html><body><div id="tst"></div></body></html>');
|
||||
//var testDom = require('testdom')('<html><body><div id="tst"></div></body></html>');
|
||||
|
||||
var classRenderer = require('./classRenderer');
|
||||
var parser = require('./parser/classDiagram').parser;
|
||||
@@ -101,8 +101,8 @@ describe('class diagram, ', function () {
|
||||
});
|
||||
});
|
||||
it('it should handle one actor', function () {
|
||||
var str = `classDiagram
|
||||
Class01 --|> Class02`;
|
||||
var str = 'classDiagram\n'+
|
||||
'Class01 --|> Class02';
|
||||
|
||||
//classRenderer.draw(str,'tst');
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
var proxyquire = require('proxyquire');
|
||||
/**
|
||||
* Created by knut on 14-11-18.
|
||||
*/
|
||||
var proxyquire = require('proxyquire');
|
||||
//var proxyquire = require('proxyquire');
|
||||
//var log = require('../../logger').create();
|
||||
|
||||
var sq = require('./parser/sequenceDiagram').parser;
|
||||
@@ -18,6 +19,10 @@ var d3 = {
|
||||
//var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
|
||||
var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 });
|
||||
|
||||
//
|
||||
//
|
||||
//var sd = require('./sequenceRenderer');
|
||||
|
||||
var str;
|
||||
describe('when parsing a sequenceDiagram',function() {
|
||||
beforeEach(function () {
|
||||
@@ -574,14 +579,14 @@ describe('when rendering a sequenceDiagram',function() {
|
||||
sq.yy = require('./sequenceDb');
|
||||
sq.yy.clear();
|
||||
|
||||
var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
||||
var mock = new MockBrowser();
|
||||
//var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
||||
//var mock = new MockBrowser();
|
||||
|
||||
delete global.mermaid_config;
|
||||
|
||||
// and in the run-code inside some object
|
||||
global.document = mock.getDocument();
|
||||
global.window = mock.getWindow();
|
||||
//global.document = mock.getDocument();
|
||||
//global.window = mock.getWindow();
|
||||
|
||||
//parseError = function(err, hash) {
|
||||
// log.debug('Syntax error:' + err);
|
||||
@@ -632,6 +637,12 @@ describe('when rendering a sequenceDiagram',function() {
|
||||
noteMargin:25
|
||||
};
|
||||
sd.setConf(conf);
|
||||
//document.body.innerHTML = '<div id="tst"></div>';
|
||||
//document.body.innerHTML = '<svg height="30" width="200"><text id="tst" x="0" y="15" fill="red">I love SVG!</text></svg>';
|
||||
//document.body.innerHTML = '<svg height="30" width="200"><text x="0" y="15" fill="red"><tspan x="46" id="tst">Alice thinks</tspan></text></svg>';
|
||||
//console.log('document.body');
|
||||
//console.log(document.querySelector('#tst').getBBox());
|
||||
|
||||
});
|
||||
it('it should handle one actor', function () {
|
||||
sd.bounds.init();
|
||||
|
||||
@@ -225,9 +225,12 @@ var drawMessage = function(elem, startx, stopx, verticalPos, msg){
|
||||
line.attr('class', 'messageLine0');
|
||||
}
|
||||
|
||||
var url = window.location.protocol+'//'+window.location.host+window.location.pathname +window.location.search;
|
||||
url = url.replace(/\(/g,'\\(');
|
||||
url = url.replace(/\)/g,'\\)');
|
||||
var url = '';
|
||||
if(conf.arrowMarkerAbsolute){
|
||||
url = window.location.protocol+'//'+window.location.host+window.location.pathname +window.location.search;
|
||||
url = url.replace(/\(/g,'\\(');
|
||||
url = url.replace(/\)/g,'\\)');
|
||||
}
|
||||
|
||||
line.attr('stroke-width', 2);
|
||||
line.attr('stroke', 'black');
|
||||
|
||||
@@ -46,6 +46,7 @@ exports.drawText = function(elem, textData, width) {
|
||||
//span.attr('dy', textData.dy);
|
||||
span.text(nText);
|
||||
if(typeof textElem.textwrap !== 'undefined'){
|
||||
|
||||
textElem.textwrap({
|
||||
x: textData.x, // bounding box is 300 pixels from the left
|
||||
y: textData.y, // bounding box is 400 pixels from the top
|
||||
|
||||
Reference in New Issue
Block a user