2014-12-20 08:40:48 +01:00
|
|
|
/**
|
|
|
|
* Created by knut on 14-12-20.
|
|
|
|
*/
|
2015-06-30 14:23:32 +02:00
|
|
|
var log = require('../../logger').create();
|
2014-12-20 08:40:48 +01:00
|
|
|
exports.drawRect = function(elem , rectData){
|
2014-12-20 09:18:12 +01:00
|
|
|
var rectElem = elem.append("rect");
|
2014-12-20 08:40:48 +01:00
|
|
|
rectElem.attr("x", rectData.x);
|
2014-12-20 09:18:12 +01:00
|
|
|
rectElem.attr("y", rectData.y);
|
2014-12-20 08:40:48 +01:00
|
|
|
rectElem.attr("fill", rectData.fill);
|
|
|
|
rectElem.attr("stroke", rectData.stroke);
|
|
|
|
rectElem.attr("width", rectData.width);
|
|
|
|
rectElem.attr("height", rectData.height);
|
|
|
|
rectElem.attr("rx", rectData.rx);
|
|
|
|
rectElem.attr("ry", rectData.ry);
|
|
|
|
|
2014-12-21 20:59:11 +01:00
|
|
|
if(typeof rectData.class !== 'undefined'){
|
|
|
|
rectElem.attr("class", rectData.class);
|
|
|
|
}
|
|
|
|
|
2014-12-20 08:40:48 +01:00
|
|
|
return rectElem;
|
|
|
|
};
|
|
|
|
|
2015-06-20 20:58:58 +02:00
|
|
|
exports.drawText = function(elem, textData, width) {
|
|
|
|
// Remove and ignore br:s
|
|
|
|
var nText = textData.text.replace(/<br\/?>/ig,' ');
|
|
|
|
|
2014-12-20 09:18:12 +01:00
|
|
|
var textElem = elem.append('text');
|
|
|
|
textElem.attr('x', textData.x);
|
|
|
|
textElem.attr('y', textData.y);
|
2014-12-20 18:41:20 +01:00
|
|
|
textElem.style('text-anchor', textData.anchor);
|
2014-12-21 20:59:11 +01:00
|
|
|
textElem.attr('fill', textData.fill);
|
2015-06-20 20:58:58 +02:00
|
|
|
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);
|
|
|
|
});*/
|
2014-12-20 09:18:12 +01:00
|
|
|
|
|
|
|
|
2015-06-20 20:58:58 +02:00
|
|
|
var span = textElem.append('tspan');
|
2015-09-26 12:09:47 +02:00
|
|
|
//span.attr('x', textData.x);
|
|
|
|
span.attr('x', textData.x+textData.textMargin*2);
|
|
|
|
//span.attr('dy', textData.dy);
|
2015-06-20 20:58:58 +02:00
|
|
|
span.text(nText);
|
|
|
|
if(typeof textElem.textwrap !== 'undefined'){
|
|
|
|
textElem.textwrap({
|
2015-09-26 12:09:47 +02:00
|
|
|
x: textData.x, // bounding box is 300 pixels from the left
|
|
|
|
y: textData.y, // bounding box is 400 pixels from the top
|
2015-06-20 20:58:58 +02:00
|
|
|
width: width, // bounding box is 500 pixels across
|
|
|
|
height: 1800 // bounding box is 600 pixels tall
|
|
|
|
}, textData.textMargin);
|
2014-12-21 20:59:11 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 09:18:12 +01:00
|
|
|
return textElem;
|
|
|
|
};
|
|
|
|
|
2014-12-20 18:41:20 +01:00
|
|
|
exports.drawLabel = function(elem , txtObject){
|
|
|
|
var rectData = exports.getNoteRect();
|
|
|
|
rectData.x = txtObject.x;
|
|
|
|
rectData.y = txtObject.y;
|
|
|
|
rectData.width = 50;
|
|
|
|
rectData.height = 20;
|
2014-12-21 20:59:11 +01:00
|
|
|
rectData.fill = '#526e52';
|
2014-12-20 18:41:20 +01:00
|
|
|
rectData.stroke = 'none';
|
2014-12-21 20:59:11 +01:00
|
|
|
rectData.class = 'labelBox';
|
2014-12-20 18:41:20 +01:00
|
|
|
//rectData.color = 'white';
|
|
|
|
|
2015-01-05 14:12:49 +01:00
|
|
|
exports.drawRect(elem, rectData);
|
2014-12-20 18:41:20 +01:00
|
|
|
|
|
|
|
txtObject.y = txtObject.y + txtObject.labelMargin;
|
|
|
|
txtObject.x = txtObject.x + 0.5*txtObject.labelMargin;
|
|
|
|
txtObject.fill = 'white';
|
|
|
|
exports.drawText(elem, txtObject);
|
|
|
|
|
|
|
|
//return textElem;
|
|
|
|
};
|
2015-07-04 10:00:14 +02:00
|
|
|
var actorCnt = -1;
|
2015-01-05 13:41:32 +01:00
|
|
|
/**
|
|
|
|
* Draws an actor in the diagram with the attaced line
|
|
|
|
* @param center - The center of the the actor
|
|
|
|
* @param pos The position if the actor in the liost of actors
|
|
|
|
* @param description The text in the box
|
|
|
|
*/
|
2015-01-25 14:24:58 +01:00
|
|
|
exports.drawActor = function(elem, left, verticalPos, description,conf){
|
2015-01-05 13:41:32 +01:00
|
|
|
var center = left + (conf.width/2);
|
|
|
|
var g = elem.append("g");
|
2015-01-25 14:24:58 +01:00
|
|
|
if(verticalPos === 0) {
|
2015-07-04 10:00:14 +02:00
|
|
|
actorCnt++;
|
2015-01-25 14:24:58 +01:00
|
|
|
g.append("line")
|
2015-07-04 10:00:14 +02:00
|
|
|
.attr("id", 'actor'+actorCnt)
|
2015-01-25 14:24:58 +01:00
|
|
|
.attr("x1", center)
|
|
|
|
.attr("y1", 5)
|
|
|
|
.attr("x2", center)
|
|
|
|
.attr("y2", 2000)
|
|
|
|
.attr("class", 'actor-line')
|
|
|
|
.attr("stroke-width", '0.5px')
|
|
|
|
.attr("stroke", '#999');
|
|
|
|
}
|
2015-01-05 13:41:32 +01:00
|
|
|
|
2015-01-05 14:12:49 +01:00
|
|
|
var rect = exports.getNoteRect();
|
|
|
|
rect.x = left;
|
2015-01-25 14:24:58 +01:00
|
|
|
rect.y = verticalPos;
|
2015-01-05 14:12:49 +01:00
|
|
|
rect.fill = '#eaeaea';
|
|
|
|
rect.width = conf.width;
|
|
|
|
rect.height = conf.height;
|
|
|
|
rect.class = 'actor';
|
|
|
|
rect.rx = 3;
|
|
|
|
rect.ry = 3;
|
|
|
|
exports.drawRect(g, rect);
|
|
|
|
|
2015-01-05 13:41:32 +01:00
|
|
|
g.append("text") // text label for the x axis
|
|
|
|
.attr("x", center)
|
2015-01-25 14:24:58 +01:00
|
|
|
.attr("y", verticalPos + (conf.height/2)+5)
|
2015-01-05 13:41:32 +01:00
|
|
|
.attr('class','actor')
|
|
|
|
.style("text-anchor", "middle")
|
|
|
|
.text(description)
|
|
|
|
;
|
|
|
|
};
|
2015-01-05 14:41:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws an actor in the diagram with the attaced line
|
|
|
|
* @param center - The center of the the actor
|
|
|
|
* @param pos The position if the actor in the list of actors
|
|
|
|
* @param description The text in the box
|
|
|
|
*/
|
|
|
|
exports.drawLoop = function(elem,bounds,labelText, conf){
|
|
|
|
var g = elem.append("g");
|
|
|
|
var drawLoopLine = function(startx,starty,stopx,stopy){
|
|
|
|
g.append("line")
|
|
|
|
.attr("x1", startx)
|
|
|
|
.attr("y1", starty)
|
|
|
|
.attr("x2", stopx )
|
|
|
|
.attr("y2", stopy )
|
|
|
|
.attr("stroke-width", 2)
|
|
|
|
.attr("stroke", "#526e52")
|
|
|
|
.attr('class','loopLine');
|
|
|
|
};
|
|
|
|
drawLoopLine(bounds.startx, bounds.starty, bounds.stopx , bounds.starty);
|
|
|
|
drawLoopLine(bounds.stopx , bounds.starty, bounds.stopx , bounds.stopy );
|
|
|
|
drawLoopLine(bounds.startx, bounds.stopy , bounds.stopx , bounds.stopy );
|
|
|
|
drawLoopLine(bounds.startx, bounds.starty, bounds.startx, bounds.stopy );
|
|
|
|
if(typeof bounds.elsey !== 'undefined'){
|
|
|
|
drawLoopLine(bounds.startx, bounds.elsey, bounds.stopx, bounds.elsey );
|
|
|
|
}
|
|
|
|
|
|
|
|
var txt = exports.getTextObj();
|
|
|
|
txt.text = labelText;
|
|
|
|
txt.x = bounds.startx;
|
|
|
|
txt.y = bounds.starty;
|
|
|
|
txt.labelMargin = 1.5 * conf.boxMargin;
|
|
|
|
txt.class = 'labelText';
|
|
|
|
txt.fill = 'white';
|
|
|
|
|
|
|
|
exports.drawLabel(g,txt);
|
|
|
|
|
|
|
|
txt = exports.getTextObj();
|
|
|
|
txt.text = '[ ' + bounds.title + ' ]';
|
|
|
|
txt.x = bounds.startx + (bounds.stopx - bounds.startx)/2;
|
|
|
|
txt.y = bounds.starty + 1.5 * conf.boxMargin;
|
|
|
|
txt.anchor = 'middle';
|
|
|
|
txt.class = 'loopText';
|
|
|
|
|
|
|
|
exports.drawText(g,txt);
|
|
|
|
|
|
|
|
if(typeof bounds.elseText !== 'undefined') {
|
|
|
|
txt.text = '[ ' + bounds.elseText + ' ]';
|
|
|
|
txt.y = bounds.elsey + 1.5 * conf.boxMargin;
|
|
|
|
exports.drawText(g, txt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-05 13:41:32 +01:00
|
|
|
/**
|
|
|
|
* Setup arrow head and define the marker. The result is appended to the svg.
|
|
|
|
*/
|
|
|
|
exports.insertArrowHead = function(elem){
|
|
|
|
elem.append("defs").append("marker")
|
|
|
|
.attr("id", "arrowhead")
|
2015-01-05 14:12:49 +01:00
|
|
|
.attr("refX", 5)
|
2015-01-05 13:41:32 +01:00
|
|
|
.attr("refY", 2)
|
|
|
|
.attr("markerWidth", 6)
|
|
|
|
.attr("markerHeight", 4)
|
|
|
|
.attr("orient", "auto")
|
|
|
|
.append("path")
|
|
|
|
.attr("d", "M 0,0 V 4 L6,2 Z"); //this is actual shape for arrowhead
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Setup arrow head and define the marker. The result is appended to the svg.
|
|
|
|
*/
|
|
|
|
exports.insertArrowCrossHead = function(elem){
|
2015-01-09 08:21:48 +01:00
|
|
|
var defs = elem.append("defs");
|
|
|
|
var marker = defs.append("marker")
|
2015-01-05 13:41:32 +01:00
|
|
|
.attr("id", "crosshead")
|
2015-01-09 08:21:48 +01:00
|
|
|
.attr("markerWidth", 15)
|
2015-01-05 13:41:32 +01:00
|
|
|
.attr("markerHeight", 8)
|
|
|
|
.attr("orient", "auto")
|
2015-01-09 08:21:48 +01:00
|
|
|
.attr("refX", 16)
|
|
|
|
.attr("refY", 4);
|
|
|
|
|
|
|
|
// The arrow
|
|
|
|
marker.append("path")
|
|
|
|
.attr("fill",'black')
|
|
|
|
.attr("stroke",'#000000')
|
|
|
|
.style("stroke-dasharray", ("0, 0"))
|
|
|
|
.attr("stroke-width",'1px')
|
|
|
|
.attr("d", "M 9,2 V 6 L16,4 Z");
|
|
|
|
|
|
|
|
// The cross
|
|
|
|
marker.append("path")
|
|
|
|
.attr("fill",'none')
|
|
|
|
.attr("stroke",'#000000')
|
|
|
|
.style("stroke-dasharray", ("0, 0"))
|
|
|
|
.attr("stroke-width",'1px')
|
|
|
|
.attr("d", "M 0,1 L 6,7 M 6,1 L 0,7")
|
|
|
|
; //this is actual shape for arrowhead
|
|
|
|
|
2015-01-05 13:41:32 +01:00
|
|
|
};
|
2014-12-20 18:41:20 +01:00
|
|
|
|
2014-12-20 09:18:12 +01:00
|
|
|
exports.getTextObj = function(){
|
2014-12-21 20:59:11 +01:00
|
|
|
var txt = {
|
2014-12-20 09:18:12 +01:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
2014-12-20 18:41:20 +01:00
|
|
|
'fill':'black',
|
2014-12-20 09:18:12 +01:00
|
|
|
'text-anchor': 'start',
|
|
|
|
style: '#666',
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
2014-12-20 18:41:20 +01:00
|
|
|
textMargin:0,
|
2014-12-20 09:18:12 +01:00
|
|
|
rx: 0,
|
|
|
|
ry: 0
|
|
|
|
};
|
2014-12-21 20:59:11 +01:00
|
|
|
return txt;
|
2014-12-20 09:18:12 +01:00
|
|
|
};
|
|
|
|
|
2014-12-20 08:40:48 +01:00
|
|
|
exports.getNoteRect = function(){
|
|
|
|
var rect = {
|
2015-04-20 21:21:17 +02:00
|
|
|
x : 0,
|
|
|
|
y : 0,
|
|
|
|
fill : '#EDF2AE',
|
|
|
|
stroke : '#666',
|
|
|
|
width : 100,
|
|
|
|
anchor : 'start',
|
|
|
|
height : 100,
|
|
|
|
rx : 0,
|
|
|
|
ry : 0
|
2014-12-20 08:40:48 +01:00
|
|
|
};
|
|
|
|
return rect;
|
|
|
|
};
|