The main problem was with autoResize functionality. I’ve added a custom rule to disable all autoresize operations. You could also pass autoResize: [ 'value', null ],
in Modeler’s additional modules instead of creating custom rules.
But this was not enough since createShape
function ignored coordinates I was passing in attrs for some reason.
So I’ve created a wrapper createShape function, created a shape there, manually updated the coordinates, and then called Modeling’s updateElementProperties
passing an empty object like so:
public createShape(attrs: Partial<ShapeAttributes>, parent: Shape) {
const shape = this.modeling.createShape(attrs, {x: attrs.x, y: attrs.y}, parent);
shape.x = attrs.x;
shape.y = attrs.y;
if (attrs.width && attrs.height) {
shape.width = attrs.width;
shape.height = attrs.height;
}
this.updateElementProperties(shape, {});
return shape;
}
And this worked for shapes. Calling updateElementProperties
is crucial by the way.
For connections manually updating waypoints didn’t work. They looked broken on the diagram: sometimes start and tip of connections were not connected to sources and targets. I’ve devised this logic to fix it:
const connectionStart = getMid(flow.source);
const connectionEnd = getMid(flow.target);
const middle: Waypoint[] = waypoints.slice(1, waypoints.length - 1);
this.modeling.updateWaypoints(flow, [connectionStart, ...middle, connectionEnd]);
Basically what’s happening here is I take the first and last waypoint and smoothly connect to source and target respectively (due to that sometimes the original waypoints from the api ignored to make the connection smooth), the rest of the waypoints in between are left untouched.
This piece of code checks if there are only two waypoints, then I’m passing an empty object to layoutConnection
. Otherwise it automatically lays out connections the default way even if they were diagonal.
const layout = middle.length === 0 ? {} : {connectionStart, connectionEnd};
this.modeling.layoutConnection(flow, layout)