Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow TextAnnotation for SequenceFlows #1652

Merged
merged 4 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/features/auto-place/BpmnAutoPlaceUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export function getTextAnnotationPosition(source, element) {
y: sourceTrbl.top - 50 - element.height / 2
};

if (isConnection(source)) {
position = getMid(source);
position.x += 100;
position.y -= 50;
}

var nextPositionDirection = {
y: {
margin: -30,
Expand Down Expand Up @@ -135,4 +141,8 @@ export function getDataElementPosition(source, element) {
};

return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
}

function isConnection(element) {
return !!element.waypoints;
}
9 changes: 9 additions & 0 deletions lib/features/context-pad/ContextPadProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
});
}

if (is(businessObject, 'bpmn:SequenceFlow')) {
assign(actions, {
'append.text-annotation': appendAction(
'bpmn:TextAnnotation',
'bpmn-icon-text-annotation'
)
});
}

if (
isAny(businessObject, [
'bpmn:FlowNode',
Expand Down
117 changes: 117 additions & 0 deletions lib/features/modeling/behavior/LayoutConnectionBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {
assign
} from 'min-dash';

import inherits from 'inherits';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

import { getConnectionAdjustment as getConnectionAnchorPoint } from './util/ConnectionLayoutUtil';

/**
* A component that makes sure that Associations connected to Connections
* are updated together with the Connection.
*
* @param {EventBus} eventBus
* @param {Modeling} modeling
*/
export default function LayoutConnectionBehavior(
marstamm marked this conversation as resolved.
Show resolved Hide resolved
eventBus, modeling) {

CommandInterceptor.call(this, eventBus);

function getnewAnchorPoint(event, point) {

var context = event.context,
connection = context.connection,
hints = assign({}, context.hints),
newWaypoints = context.newWaypoints || connection.waypoints,
oldWaypoints = context.oldWaypoints;


if (typeof hints.startChanged === 'undefined') {
hints.startChanged = !!hints.connectionStart;
}

if (typeof hints.endChanged === 'undefined') {
hints.endChanged = !!hints.connectionEnd;
}

return getConnectionAnchorPoint(point, newWaypoints, oldWaypoints, hints);
}

this.postExecute([
'connection.layout',
'connection.updateWaypoints'
], function(event) {
var context = event.context;

var connection = context.connection,
outgoing = connection.outgoing,
incoming = connection.incoming;

incoming.forEach(function(connection) {
var endPoint = connection.waypoints[connection.waypoints.length - 1];
var newEndpoint = getnewAnchorPoint(event, endPoint);

var newWaypoints = [].concat(connection.waypoints.slice(0, -1), [ newEndpoint ]);

modeling.updateWaypoints(connection, newWaypoints);
});

outgoing.forEach(function(connection) {
var startpoint = connection.waypoints[0];
var newStartpoint = getnewAnchorPoint(event, startpoint);

var newWaypoints = [].concat([ newStartpoint ], connection.waypoints.slice(1));

modeling.updateWaypoints(connection, newWaypoints);
});

});


this.postExecute([
'connection.move'
], function(event) {
var context = event.context;

var connection = context.connection,
outgoing = connection.outgoing,
incoming = connection.incoming,
delta = context.delta;

incoming.forEach(function(connection) {
var endPoint = connection.waypoints[connection.waypoints.length - 1];
var newEndpoint = {
x: endPoint.x + delta.x,
y: endPoint.y + delta.y
};

var newWaypoints = [].concat(connection.waypoints.slice(0, -1), [ newEndpoint ]);

modeling.updateWaypoints(connection, newWaypoints);
});

outgoing.forEach(function(connection) {
var startpoint = connection.waypoints[0];
var newStartpoint = {
x: startpoint.x + delta.x,
y: startpoint.y + delta.y
};

var newWaypoints = [].concat([ newStartpoint ], connection.waypoints.slice(1));

modeling.updateWaypoints(connection, newWaypoints);
});

});

}

inherits(LayoutConnectionBehavior, CommandInterceptor);

LayoutConnectionBehavior.$inject = [
'eventBus',
'modeling'
];
3 changes: 3 additions & 0 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import GroupBehavior from './GroupBehavior';
import ImportDockingFix from './ImportDockingFix';
import IsHorizontalFix from './IsHorizontalFix';
import LabelBehavior from './LabelBehavior';
import LayoutConnectionBehavior from './LayoutConnectionBehavior';
import MessageFlowBehavior from './MessageFlowBehavior';
import ModelingFeedback from './ModelingFeedback';
import RemoveEmbeddedLabelBoundsBehavior from './RemoveEmbeddedLabelBoundsBehavior';
Expand Down Expand Up @@ -57,6 +58,7 @@ export default {
'importDockingFix',
'isHorizontalFix',
'labelBehavior',
'layoutConnectionBehavior',
'messageFlowBehavior',
'modelingFeedback',
'removeElementBehavior',
Expand Down Expand Up @@ -95,6 +97,7 @@ export default {
importDockingFix: [ 'type', ImportDockingFix ],
isHorizontalFix: [ 'type', IsHorizontalFix ],
labelBehavior: [ 'type', LabelBehavior ],
layoutConnectionBehavior: [ 'type', LayoutConnectionBehavior ],
messageFlowBehavior: [ 'type', MessageFlowBehavior ],
modelingFeedback: [ 'type', ModelingFeedback ],
removeElementBehavior: [ 'type', RemoveElementBehavior ],
Expand Down
16 changes: 16 additions & 0 deletions lib/features/modeling/behavior/util/ConnectionLayoutUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getAnchorPointAdjustment } from './LayoutUtil';

/**
* Calculate the new point after the connection waypoints got updated.
*
* @param {djs.model.Label} label
* @param {Array<Point>} newWaypoints
* @param {Array<Point>} oldWaypoints
* @param {Object} hints
*
* @return {Point} point
*/
export function getConnectionAdjustment(position, newWaypoints, oldWaypoints, hints) {
return getAnchorPointAdjustment(position, newWaypoints, oldWaypoints, hints).point;
}

Loading