chore(modeling/BpmnLayouter): refactor boundary event layout

This commit is contained in:
Maciej Barelkowski 2019-04-24 09:53:23 +02:00 committed by merge-me[bot]
parent 0f7b8f483c
commit 5438f1a0c2
1 changed files with 64 additions and 61 deletions

View File

@ -271,82 +271,85 @@ function getBoundaryEventPreferredLayouts(source, target) {
targetMid = getMid(target),
attachOrientation = getAttachOrientation(source),
sourceLayout,
targetlayout;
targetLayout;
var isLoop = isSame(source.host, target);
var attachedToSide = isAnyOrientation(attachOrientation, [ 'top', 'right', 'bottom', 'left' ]);
var isHorizontalAttachOrientation = isHorizontalOrientation(attachOrientation);
var targetOrientation = getOrientation(targetMid, sourceMid, {
x: source.width / 2 + target.width / 2,
y: source.height / 2 + target.height / 2
});
// source layout
// attached to either top, right, bottom or left side
if (attachedToSide) {
sourceLayout = orientationDirectionMapping[
isHorizontalAttachOrientation ?
getHorizontalOrientation(attachOrientation) :
getVerticalOrientation(attachOrientation)
];
} else
// attached to either top-right, top-left, bottom-right or bottom-left corner
{
// loop, same vertical or opposite horizontal orientation
if (isLoop ||
isSame(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) ||
isOppositeOrientation(getHorizontalOrientation(attachOrientation), getHorizontalOrientation(targetOrientation))
) {
sourceLayout = orientationDirectionMapping[getVerticalOrientation(attachOrientation)];
} else {
sourceLayout = orientationDirectionMapping[getHorizontalOrientation(attachOrientation)];
}
}
sourceLayout = getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide, isLoop);
// target layout
targetLayout = getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide, isLoop);
return [ sourceLayout + ':' + targetLayout ];
}
function getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide, isLoop) {
// attached to either top, right, bottom or left side
if (attachedToSide) {
// loop or opposite horizontal/vertical orientation
if (
isLoop ||
(isHorizontalAttachOrientation ?
isOppositeHorizontalOrientation(attachOrientation, targetOrientation) :
isOppositeVerticalOrientation(attachOrientation, targetOrientation))
) {
targetlayout = isHorizontalAttachOrientation ? 'h' : 'v';
} else {
targetlayout = isHorizontalAttachOrientation ? 'v' : 'h';
}
} else
// attached to either top-right, top-left, bottom-right or bottom-left corner
{
// orientation is 'right', 'left'
// or same vertical orientation but also 'right' or 'left'
if (
isHorizontalOrientation(targetOrientation) ||
(isSame(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) &&
getHorizontalOrientation(targetOrientation))
) {
targetlayout = 'h';
} else {
targetlayout = 'v';
}
return orientationDirectionMapping[attachOrientation];
}
return [ sourceLayout + ':' + targetlayout ];
}
// attached to either top-right, top-left, bottom-right or bottom-left corner
// loop, same vertical or opposite horizontal orientation
if (isLoop ||
isSame(
getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)
) ||
isOppositeOrientation(
getHorizontalOrientation(attachOrientation), getHorizontalOrientation(targetOrientation)
)) {
return orientationDirectionMapping[getVerticalOrientation(attachOrientation)];
}
// fallback
return orientationDirectionMapping[getHorizontalOrientation(attachOrientation)];
}
function getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide, isLoop) {
// attached to either top, right, bottom or left side
if (attachedToSide) {
if (isHorizontalOrientation(attachOrientation)) {
// orientation is 'right' or 'left'
// loop or opposite horizontal orientation
if (isLoop || isOppositeHorizontalOrientation(attachOrientation, targetOrientation)) {
return 'h';
}
// fallback
return 'v';
} else {
// orientation is 'top' or 'bottom'
// loop or opposite vertical orientation
if (isLoop || isOppositeVerticalOrientation(attachOrientation, targetOrientation)) {
return 'v';
}
// fallback
return 'h';
}
}
// attached to either top-right, top-left, bottom-right or bottom-left corner
// orientation is 'right', 'left'
// or same vertical orientation but also 'right' or 'left'
if (isHorizontalOrientation(targetOrientation) ||
(isSame(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) &&
getHorizontalOrientation(targetOrientation))) {
return 'h';
} else {
return 'v';
}
}