From f4f619bf499158c77048cb0e2fd3d4bb7ecbbf48 Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Thu, 21 May 2026 17:07:01 +0200 Subject: [PATCH 1/2] refactor: extract insertEdge private method in BpmnRenderer Mirror the existing insertVertex helper by extracting an insertEdge private method that encapsulates edge cell creation, waypoints insertion, and label-bounds geometry. The previous insertEdges loop inlined all three concerns, producing an asymmetry with the shape path where insertVertex already encapsulates the equivalent responsibilities. The waypoint-before-label-bounds ordering is preserved inside the new helper because computeEdgeCenter reads edge.geometry.points, which is set by insertWaypoints. Message flow icon insertion stays at the loop level since it is a separate child-cell concern rather than part of the edge cell geometry. No behavior change: build, unit tests (BpmnRenderer.test.ts, 38 tests) and integration tests (14 suites, 312 tests) all pass. --- src/component/mxgraph/BpmnRenderer.ts | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/component/mxgraph/BpmnRenderer.ts b/src/component/mxgraph/BpmnRenderer.ts index 796b39f933..4f840493f2 100644 --- a/src/component/mxgraph/BpmnRenderer.ts +++ b/src/component/mxgraph/BpmnRenderer.ts @@ -92,22 +92,8 @@ export class BpmnRenderer { 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(parent, bpmnElement.id, bpmnElement.name, source, target, internalEdge.waypoints, labelBounds, style); this.insertMessageFlowIconIfNeeded(internalEdge, edge); } } @@ -130,6 +116,24 @@ export class BpmnRenderer { return this.graph.getModel().getCell(id); } + private insertEdge(parent: mxCell, id: string | null, value: string, source: mxCell, target: mxCell, waypoints: Waypoint[], labelBounds: Bounds, style: string): mxCell { + const edge = this.graph.insertEdge(parent, id, value, source, target, style); + this.insertWaypoints(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); From 4e271dc6b8c3829939d84b5d0777fda1bf38194c Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Fri, 22 May 2026 15:42:59 +0200 Subject: [PATCH 2/2] refactor: simplify insertEdge signature to take Edge model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce insertEdge from 8 parameters to 1 by passing the Edge model directly instead of pre-derived primitives. SonarCloud flagged the previous signature as exceeding its 7-parameter threshold; the fix also aligns the helper with the existing insertShape pattern, which takes a Shape and derives parent/style/labelBounds internally. The default parent, source/target cells, label bounds and style are all derivable from the Edge model itself, so keeping them as parameters duplicated the caller logic. The new shape (insertEdges loop → insertEdge(internalEdge)) mirrors insertShapes → insertShape(shape) line for line. No behavior change: build, unit tests (38) and integration tests (14 suites, 312 tests) all pass. --- src/component/mxgraph/BpmnRenderer.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/component/mxgraph/BpmnRenderer.ts b/src/component/mxgraph/BpmnRenderer.ts index 4f840493f2..94738e307e 100644 --- a/src/component/mxgraph/BpmnRenderer.ts +++ b/src/component/mxgraph/BpmnRenderer.ts @@ -86,14 +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.insertEdge(parent, bpmnElement.id, bpmnElement.name, source, target, internalEdge.waypoints, labelBounds, style); + const edge = this.insertEdge(internalEdge); this.insertMessageFlowIconIfNeeded(internalEdge, edge); } } @@ -116,9 +109,15 @@ export class BpmnRenderer { return this.graph.getModel().getCell(id); } - private insertEdge(parent: mxCell, id: string | null, value: string, source: mxCell, target: mxCell, waypoints: Waypoint[], labelBounds: Bounds, style: string): mxCell { - const edge = this.graph.insertEdge(parent, id, value, source, target, style); - this.insertWaypoints(waypoints, edge); + 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;