Skip to content
Merged
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
47 changes: 25 additions & 22 deletions src/component/mxgraph/BpmnRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down
Loading