2014-12-20 08:40:48 +01:00
|
|
|
/**
|
|
|
|
* Created by knut on 14-12-20.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-12-20 09:18:12 +01:00
|
|
|
exports.drawText = function(elem , textData){
|
|
|
|
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);
|
2014-12-20 09:18:12 +01:00
|
|
|
|
2014-12-31 02:02:39 -05:00
|
|
|
textData.text.split(/<br\/?>/ig).forEach(function(rowText){
|
2014-12-20 09:18:12 +01:00
|
|
|
var span = textElem.append('tspan');
|
|
|
|
span.attr('x', textData.x +textData.textMargin);
|
|
|
|
span.attr('dy', textData.dy);
|
|
|
|
span.text(rowText);
|
|
|
|
});
|
|
|
|
|
2014-12-21 20:59:11 +01:00
|
|
|
if(typeof textData.class !== 'undefined'){
|
|
|
|
textElem.attr("class", textData.class);
|
|
|
|
}
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
var label = exports.drawRect(elem, rectData);
|
|
|
|
|
|
|
|
txtObject.y = txtObject.y + txtObject.labelMargin;
|
|
|
|
txtObject.x = txtObject.x + 0.5*txtObject.labelMargin;
|
|
|
|
txtObject.fill = 'white';
|
|
|
|
exports.drawText(elem, txtObject);
|
|
|
|
|
|
|
|
//return textElem;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
exports.drawActor = function(elem, left,description,conf){
|
|
|
|
var center = left + (conf.width/2);
|
|
|
|
var g = elem.append("g");
|
|
|
|
g.append("line")
|
|
|
|
.attr("x1", center)
|
|
|
|
.attr("y1", 5)
|
|
|
|
.attr("x2", center)
|
|
|
|
.attr("y2", 2000)
|
|
|
|
.attr("class", 'actor-line')
|
|
|
|
.attr("stroke-width", '0.5px')
|
|
|
|
.attr("stroke", '#999');
|
|
|
|
|
|
|
|
g.append("rect")
|
|
|
|
.attr("x", left)
|
|
|
|
.attr("y", 0)
|
|
|
|
.attr("fill", '#eaeaea')
|
|
|
|
.attr("stroke", '#666')
|
|
|
|
.attr("width", conf.width)
|
|
|
|
.attr("height", conf.height)
|
|
|
|
.attr("class", 'actor')
|
|
|
|
.attr("rx", 3)
|
|
|
|
.attr("ry", 3);
|
|
|
|
g.append("text") // text label for the x axis
|
|
|
|
.attr("x", center)
|
|
|
|
.attr("y", (conf.height/2)+5)
|
|
|
|
.attr('class','actor')
|
|
|
|
.style("text-anchor", "middle")
|
|
|
|
.text(description)
|
|
|
|
;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* 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")
|
|
|
|
.attr("refX", 5) /*must be smarter way to calculate shift*/
|
|
|
|
.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){
|
|
|
|
elem.append("defs").append("marker")
|
|
|
|
.attr("id", "crosshead")
|
|
|
|
.attr("refX", 15) /*must be smarter way to calculate shift*/
|
|
|
|
.attr("refY", 4)
|
|
|
|
.attr("markerWidth", 8)
|
|
|
|
.attr("markerHeight", 8)
|
|
|
|
.attr("orient", "auto")
|
|
|
|
.append("path")
|
|
|
|
.attr("fill",'none')
|
|
|
|
.attr("stroke",'#000000')
|
|
|
|
.style("stroke-dasharray", ("0, 0"))
|
|
|
|
.attr("stroke-width",'1px')
|
|
|
|
.attr("d", "M 1,1 L 7,7 M 7,1 L 1,7"); //this is actual shape for arrowhead
|
|
|
|
};
|
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 = {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
fill: '#EDF2AE',
|
|
|
|
stroke: '#666',
|
|
|
|
width: 100,
|
2014-12-20 18:41:20 +01:00
|
|
|
anchor:'start',
|
2014-12-20 08:40:48 +01:00
|
|
|
height: 100,
|
|
|
|
rx: 0,
|
|
|
|
ry: 0
|
|
|
|
};
|
|
|
|
return rect;
|
|
|
|
};
|