feat(label): improve positioning of sequence flow labels

closes #512
This commit is contained in:
Jan Stümmel
2016-04-19 16:50:42 +02:00
parent 1923a6bdda
commit 7811a47fae
3 changed files with 121 additions and 1 deletions

View File

@ -25,6 +25,39 @@ module.exports.hasExternalLabel = function(semantic) {
is(semantic, 'bpmn:MessageFlow');
};
/**
* Get the position for sequence flow labels
*
* @param {Array<Point>} waypoints
* @return {Point} the label position
*/
function getFlowLabelPosition(waypoints) {
// get the waypoints mid
var mid = waypoints.length / 2 - 1;
var first = waypoints[Math.floor(mid)];
var second = waypoints[Math.ceil(mid + 0.01)];
// get position
var position = getWaypointsMid(waypoints);
// calculate angle
var angle = Math.atan( (second.y - first.y) / (second.x - first.x) );
var x = position.x,
y = position.y;
if ( Math.abs(angle) < Math.PI / 2 ) {
y += DEFAULT_LABEL_SIZE.height / 2;
} else {
x += DEFAULT_LABEL_SIZE.width / 2;
}
return { x: x, y: y };
}
module.exports.getFlowLabelPosition = getFlowLabelPosition;
/**
* Get the middle of a number of waypoints
@ -51,7 +84,7 @@ module.exports.getWaypointsMid = getWaypointsMid;
function getExternalLabelMid(element) {
if (element.waypoints) {
return getWaypointsMid(element.waypoints);
return getFlowLabelPosition(element.waypoints);
} else {
return {
x: element.x + element.width / 2,