mirror of
https://github.com/bpmn-io/bpmn-js.git
synced 2025-08-26 12:40:20 +08:00
@ -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,
|
||||
|
Reference in New Issue
Block a user