bpmn-io / diagram-js

A toolbox for displaying and modifying diagrams on the web.
MIT License
1.68k stars 420 forks source link

connection.reconnect event doesn't define a connectionStart waypoint when calling modeling.reconnectStart #788

Closed vbo75 closed 1 year ago

vbo75 commented 1 year ago

Context

I develop an ArchiMate modeling engine builds on diagram-js library. In Archimate, it’s allowed to connect a connection to a shape with a specific connection type. (see also : https://forum.bpmn.io/t/update-waypoints-between-two-connections/8789)

In this case, when there is a connection (called A connection) between a shape and another connection (called B connection), if B connection move voluntarily or not, we need to reconnect A connection to B connection. Reconnect depends on A connection type : incoming or outgoing connection of B connection.

As connecting connections to connections isn’t standard behavior, I developed a hook to capture essential information (old waypoints or docking points) and after, call Modeling.reconnectStart or Modeling.reconnectEnd with the new calculated waypoint.

this.postExecuted(['connection.updateWaypoints','connection.move','connection.layout'], function(context) {
var connection = context.connection,
    hints = context.hints || {};

var incoming = connection.incoming.slice(),
    outgoing = connection.outgoing.slice();

var indexB = Math.ceil(connection.waypoints.length / 2),
  indexA = indexB - 1;

var waypointA = connection.waypoints[indexA],
  waypointB = connection.waypoints[indexB];

var xm = (waypointA.x + waypointB.x) /2,
  ym = (waypointA.y + waypointB.y) / 2;

var newWaypoint = {x: xm, y: ym};

forEach(incoming, function(incomingConnection) {
  modeling.reconnectEnd(
    incomingConnection, connection,
    newWaypoint
  );
});

forEach(outgoing, function(outgoingConnection) {
  modeling.reconnectStart(
    outgoingConnection, connection,
    newWaypoint
  );
});

}, true);

When A connection is an incoming connection, modeling.reconnectEnd is ok and A connection is well reconnected to B connection.

Bug

When A connection is an outgoing connexion, modeling.reconnectStart does not work. connectionEnd and connectionStart point to the same waypoint. hints passed in context to connection.reconnect event define a new connectionEnd waypoint instead of connectionStart : { hints: { connectionEnd: {x: 402.5, y: 315}, connectionStart: false, docking: "source" }

Expected Behavior

Good context hints param for connection.reconnect event : { hints: { connectionEnd: false, connectionStart: {x: 402.5, y: 315}, docking: "source" }

Environment

nikku commented 1 year ago

@vbo75 Could you share an example (visually) of what you'd like to accomplish?

As you can see in the following screen capture diagram-js (I tested v12) supports connecting connections to connections:

capture H0hm2C_optimized

nikku commented 1 year ago

Alternatively you can share a codesandbox or a demo of your archimate modeler that we can look into to inspect.

vbo75 commented 1 year ago

Ok, let me test on diagram v12 to see if I still have this bug.

vbo75 commented 1 year ago

Hi, I still have the same bug on diagram v12. I looked at bpmn-js source code to understand how your sample works. It's using modeling.updateWaypoints, not modeling.reconnectStart or modeling.reconnectEnd as I do. I'll prepare a codesandbox in case you want to look into.

nikku commented 1 year ago

@vbo75 A code sandbox would be apprechiated. You can also share a running example of archimate-js that suffers from this issue. Anything really that we can debug and use to reproduce.

philippfromme commented 1 year ago

@vbo75 Any progress?

nikku commented 1 year ago

Closing this issue due to inactivity.