refactor: Tidy up direction handling

This commit is contained in:
Sidharth Vinod
2023-09-03 10:46:26 +05:30
parent 784e235ff9
commit 20fd6d35f0

View File

@@ -1405,10 +1405,21 @@ const buildMessageModel = function (msg, actors, diagObj) {
} }
const [fromLeft, fromRight] = activationBounds(msg.from, actors); const [fromLeft, fromRight] = activationBounds(msg.from, actors);
const [toLeft, toRight] = activationBounds(msg.to, actors); const [toLeft, toRight] = activationBounds(msg.to, actors);
const arrowDirection = fromLeft <= toLeft ? 'right' : 'left'; const isArrowToRight = fromLeft <= toLeft;
const startx = arrowDirection === 'right' ? fromRight : fromLeft; const startx = isArrowToRight ? fromRight : fromLeft;
let stopx = arrowDirection === 'right' ? toLeft : toRight; let stopx = isArrowToRight ? toLeft : toRight;
const isToActivation = Math.abs(toLeft - toRight) > 2;
// As the line width is considered, the left and right values will be off by 2.
const isArrowToActivation = Math.abs(toLeft - toRight) > 2;
/**
* Adjust the value based on the arrow direction
* @param value - The value to adjust
* @returns The adjustment with correct sign to be added to the actual value.
*/
const adjustValue = (value: number) => {
return isArrowToRight ? -value : value;
};
/** /**
* This is an edge case for the first activation. * This is an edge case for the first activation.
@@ -1417,12 +1428,8 @@ const buildMessageModel = function (msg, actors, diagObj) {
* In cases where the message is to an activation that was properly detected, we don't want to move the arrow head * In cases where the message is to an activation that was properly detected, we don't want to move the arrow head
* The activation will not be detected on the first message, so we need to move the arrow head * The activation will not be detected on the first message, so we need to move the arrow head
*/ */
if (msg.activate && !isToActivation) { if (msg.activate && !isArrowToActivation) {
if (arrowDirection === 'right') { stopx += adjustValue(conf.activationWidth / 2 - 1);
stopx -= conf.activationWidth / 2 - 1;
} else {
stopx += conf.activationWidth / 2 - 1;
}
} }
/** /**
@@ -1430,11 +1437,7 @@ const buildMessageModel = function (msg, actors, diagObj) {
* This is not required for open arrows that don't have arrowheads * This is not required for open arrows that don't have arrowheads
*/ */
if (![diagObj.db.LINETYPE.SOLID_OPEN, diagObj.db.LINETYPE.DOTTED_OPEN].includes(msg.type)) { if (![diagObj.db.LINETYPE.SOLID_OPEN, diagObj.db.LINETYPE.DOTTED_OPEN].includes(msg.type)) {
if (arrowDirection === 'right') { stopx += adjustValue(3);
stopx -= 3;
} else {
stopx += 3;
}
} }
const allBounds = [fromLeft, fromRight, toLeft, toRight]; const allBounds = [fromLeft, fromRight, toLeft, toRight];