diff --git a/src/component/mxgraph/BpmnRenderer.ts b/src/component/mxgraph/BpmnRenderer.ts index 796b39f933..94738e307e 100644 --- a/src/component/mxgraph/BpmnRenderer.ts +++ b/src/component/mxgraph/BpmnRenderer.ts @@ -86,28 +86,7 @@ export class BpmnRenderer { private insertEdges(edges: Edge[]): void { for (const internalEdge of edges) { - const bpmnElement = internalEdge.bpmnElement; - const parent = this.graph.getDefaultParent(); - const source = this.getCell(bpmnElement.sourceReferenceId); - const target = this.getCell(bpmnElement.targetReferenceId); - const labelBounds = internalEdge.label?.bounds; - const style = this.styleComputer.computeStyle(internalEdge, labelBounds); - const edge = this.graph.insertEdge(parent, bpmnElement.id, bpmnElement.name, source, target, style); - this.insertWaypoints(internalEdge.waypoints, edge); - - if (labelBounds) { - edge.geometry.width = labelBounds.width; - edge.geometry.height = labelBounds.height; - - const edgeCenterCoordinate = this.coordinatesTranslator.computeEdgeCenter(edge); - edge.geometry.relative = false; - - const labelBoundsRelativeCoordinateFromParent = this.coordinatesTranslator.computeRelativeCoordinates(edge.parent, new mxPoint(labelBounds.x, labelBounds.y)); - const relativeLabelX = labelBoundsRelativeCoordinateFromParent.x + labelBounds.width / 2 - edgeCenterCoordinate.x; - const relativeLabelY = labelBoundsRelativeCoordinateFromParent.y - edgeCenterCoordinate.y; - edge.geometry.offset = new mxPoint(relativeLabelX, relativeLabelY); - } - + const edge = this.insertEdge(internalEdge); this.insertMessageFlowIconIfNeeded(internalEdge, edge); } } @@ -130,6 +109,30 @@ export class BpmnRenderer { return this.graph.getModel().getCell(id); } + private insertEdge(internalEdge: Edge): mxCell { + const bpmnElement = internalEdge.bpmnElement; + const parent = this.graph.getDefaultParent(); + const source = this.getCell(bpmnElement.sourceReferenceId); + const target = this.getCell(bpmnElement.targetReferenceId); + const labelBounds = internalEdge.label?.bounds; + const style = this.styleComputer.computeStyle(internalEdge, labelBounds); + const edge = this.graph.insertEdge(parent, bpmnElement.id, bpmnElement.name, source, target, style); + this.insertWaypoints(internalEdge.waypoints, edge); + + if (labelBounds) { + edge.geometry.width = labelBounds.width; + edge.geometry.height = labelBounds.height; + edge.geometry.relative = false; + + const edgeCenterCoordinate = this.coordinatesTranslator.computeEdgeCenter(edge); + const labelBoundsRelativeCoordinateFromParent = this.coordinatesTranslator.computeRelativeCoordinates(edge.parent, new mxPoint(labelBounds.x, labelBounds.y)); + const relativeLabelX = labelBoundsRelativeCoordinateFromParent.x + labelBounds.width / 2 - edgeCenterCoordinate.x; + const relativeLabelY = labelBoundsRelativeCoordinateFromParent.y - edgeCenterCoordinate.y; + edge.geometry.offset = new mxPoint(relativeLabelX, relativeLabelY); + } + return edge; + } + private insertVertex(parent: mxCell, id: string | null, value: string, bounds: Bounds, labelBounds: Bounds, style?: string): mxCell { const vertexCoordinates = this.coordinatesTranslator.computeRelativeCoordinates(parent, new mxPoint(bounds.x, bounds.y)); const cell = this.graph.insertVertex(parent, id, value, vertexCoordinates.x, vertexCoordinates.y, bounds.width, bounds.height, style);